Hi,
Here we are going to learn
How to do two composite graph requests each create an Account and then create related records:
Endpoint Url:
- <instance.salesforce.com(baseurl)>/services/data/vXX.X/composite/graph
Hi,
Here we are going to learn
How to do two composite graph requests each create an Account and then create related records:
Endpoint Url:
Hi,
Here we are going to learn what is Composite Graph API and how it works.
What is Composite Graph API:
Hi,
Let's see the following code how it handles when user doesn’t have permission to insert the Account__c field, which is a lookup from MyCustomObject__c to Account.
// Account__c is a lookup from MyCustomObject__c to Account
@isTest
public class TestCustomObjectLookupStripped {
@isTest static void caseCustomObjectStripped() {
Account a = new Account(Name='foo');
insert a;
List<MyCustomObject__c> records = new List<MyCustomObject__c>{
new MyCustomObject__c(Name='Custom0', Account__c=a.id)
};
insert records;
records = [SELECT Id, Account__c FROM MyCustomObject__c];
SObjectAccessDecision securityDecision = Security.stripInaccessible
(AccessType.READABLE, records);
// Verify stripped records
System.assertEquals(1, securityDecision.getRecords().size());
for (SObject strippedRecord : securityDecision.getRecords()) {
System.debug('Id should be set as Id fields are ignored: ' +
strippedRecord.isSet('Id')); // prints true
System.debug('Lookup field FLS is not READABLE to running user,
should not be set: ' +
strippedRecord.isSet('Account__c')); // prints false
}
}
}
Reference:
Hi ,
Let's assume we recieved a json string with "Name" and "Annual Revenue" to update on Account.
But user doesn't have permisson to update Annual Revenue on Account object.
Then we can avoid updating Annual Revenue on Account object as shown below.
String jsonInput =
'[' +
'{' +
'"Name": "InGen",' +
'"AnnualRevenue": "100"' +
'},' +
'{' +
'"Name": "Octan"' +
'}' +
']';
List<Account> accounts = (List<Account>)JSON.deserializeStrict(jsonInput, List<Account>.class);
SObjectAccessDecision securityDecision = Security.stripInaccessible(
AccessType.UPDATABLE, accounts);
// Secure update
update securityDecision.getRecords(); // Doesn’t update AnnualRevenue field
System.debug(String.join(securityDecision.getRemovedFields().get('Account'), ', ')); // Prints "AnnualRevenue"
System.debug(String.join(securityDecision.getModifiedIndexes(), ', ')); // Prints "0”
Hi,
Let's take a scenario that
The user who doesn’t have permission to create Rating for an Account can still create an Account.
Her the method "Security.stripInaccessible" ensures that no Rating is set and doesn’t throw an exception.
Eg:
List<Account> newAccounts = new List<Account>();
Account a = new Account(Name='Acme Corporation');
Account b = new Account(Name='Blaze Comics', Rating=’Warm’);
newAccounts.add(a);
newAccounts.add(b);
SObjectAccessDecision securityDecision = Security.stripInaccessible(
AccessType.CREATABLE, newAccounts);
// No exceptions are thrown and no rating is set
insert securityDecision.getRecords();
System.debug(securityDecision.getRemovedFields().get('Account')); // Prints "Rating"
System.debug(securityDecision.getModifiedIndexes()); // Prints "1"
Hi,
Here we are going to learn how to remove inaccessible fields from the subquery:
Scenario:
Remove the "Phone" field on Contact Object that the user doesn’t have read permission.
Code Snippet:
List<Account> accountsWithContacts =
[SELECT Id, Name, Phone,
(SELECT Id, LastName, Phone FROM Account.Contacts)
FROM Account];
// Strip fields that are not readable
SObjectAccessDecision decision = Security.stripInaccessible(
AccessType.READABLE,
accountsWithContacts);
// Print stripped records
for (Integer i = 0; i < accountsWithContacts.size(); i++)
{
System.debug('Insecure record access: '+accountsWithContacts[i]);
System.debug('Secure record access: '+decision.getRecords()[i]);
}
// Print modified indexes
System.debug('Records modified by stripInaccessible: '+decision.getModifiedIndexes());
// Print removed fields
System.debug('Fields removed by stripInaccessible: '+decision.getRemovedFields());
Hi,
Here we are going to learn how to remove inaccessible fields from the query:
Let's take a scenario
A display table for campaign data must always show the BudgetedCost. The ActualCost must be shown only to users who have permission to read that field.
Code Snippet:
SObjectAccessDecision securityDecision =
Security.stripInaccessible(AccessType.READABLE,
[SELECT Name, BudgetedCost, ActualCost FROM Campaign];
);
// Construct the output table
if (securityDecision.getRemovedFields().get('Campaign').contains('ActualCost')) {
for (Campaign c : securityDecision.getRecords()) {
//System.debug Output: Name, BudgetedCost
}
} else {
for (Campaign c : securityDecision.getRecords()) {
//System.debug Output: Name, BudgetedCost, ActualCost
}
}
Reference:
Hi ,
Here we are going to learn about Security.StripInaccessible method.
How does it work?
Hi,
Here we learn how can we use Safe Navigation Operator:
We Use the safe navigation operator (?.) to replace explicit, sequential checks for null references.
This operator short-circuits expressions that attempt to operate on a null value and returns null instead of throwing a NullPointerException.
If the left-hand-side of the chain expression evaluates to null, the right-hand-side is not evaluated. Use the safe navigation operator (?.) in method, variable, and property chaining. The part of the expression that is not evaluated can include variable references, method references, or array expressions.
This example first evaluates a, and returns null if a is null. Otherwise, the return value is a.b.
a?.b // Evaluates to: a == null ? null : a.b
This example indicates that the type of the expression is the same whether the safe navigation operator is used in the expression or not.
Integer x = anObject?.anIntegerField; // The expression is of type Integer because the field is of type Integer
This example shows a single statement replacing a block of code that checks for nulls.
// Previous code checking for nulls
String profileUrl = null;
if (user.getProfileUrl() != null) {
profileUrl = user.getProfileUrl().toExternalForm();
}
This example shows a single-row SOQL query using the safe navigation operator.
// Previous code checking for nulls
results = [SELECT Name FROM Account WHERE Id = :accId];
if (results.size() == 0) { // Account was deleted
return null;
}
return results[0].Name;
// New code using the safe navigation operator
return [SELECT Name FROM Account WHERE Id = :accId]?.Name;
References:
Hi,
Here we are going to learn how can we include Lightning Experience theme and Branding set in package.xml for retrieving and deploying the same.
Reference:
https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_brandingset.htm
Hi ,
Here we are going learn how we can Convert Source format to Metadata Format and Deploy with the help of SFDX commands.
We can do this via command prompt or vs code terminal after opening the project.
Let's look into following simple steps:
Hi,
When we develop Lightning web components we can customize a component’s behavior based on whether the current user has specific permission.
To check whether a user has a permission, import Salesforce permissions from the @salesforce/userPermission and @salesforce/customPermission scoped modules and evaluate whether it’s true or undefined. Then if the user has the permission, the component can take a specific action.
Custom permissions can include a namespace. Orgs use namespaces as unique identifiers for their own customization and packages. If the custom permission was installed from a managed package, prepend the namespace followed by __ to the permission name.
Standard Permission Example:
import hasPermission from '@salesforce/userPermission/StandardPermissionName';
Custom Permission Examples:
import hasPermission from '@salesforce/customPermission/CustomPermissionName';
import hasPermission from '@salesforce/customPermission/namespace__CustomPermissionName';
The name of the static reference is your choice. These examples chose the format hasPermission to indicate that the reference contains a Boolean.
Reference:
https://trailhead.salesforce.com/content/learn/modules/platform-developer-i-certification-maintenance-winter-21/learn-whats-new-in-lightning-web-components-and-visualforce
How Does Einstein Article Recommendations Work? Einstein Article Recommendations helps support agents resolve customer cases efficiently by ...