As the name suggests, this post intends to provide highlights of the upcoming Summer ’19 release. For simplicity, the post is classified in various sections each one of which will be highlighting few of the key updates of Summer ’19 release.
Please note, this post highlights only few of the items from the Summer ’19 release and not all of them. It would still be recommended to go through the official Salesforce Release Notes here to learn about all the updates in detail.
Apex
1. Enforce Field-Level Security in Apex (Pilot)
Now with the help of Security.stripInaccessible method and SObjectAccessDecision class, the current user’s context will strip the fields from the query results which the user do not have access to. This can also be used to remove the fields from sObjects before performing a DML operation.
So, you now need not to worry about the exceptions if the current user doesn’t have access to a specific field while querying records or performing DML operations.
Example: If the user doesn’t have the permission to create the Probability field of an Opportunity object, this example removes the Probability field before creating the records. The DML operation is completed without throwing an exception.
List opportunities = new List{
new Opportunity(Name='Opportunity1'),
new Opportunity(Name='Opportunity2', Probability=95)
};
// Strip fields that are not creatable
SObjectAccessDecision decision = Security.stripInaccessible(
AccessType.CREATABLE,
opportunities);
// Print stripped records
for (SObject strippedOpportunity : decision.getRecords()) {
System.debug(strippedOpportunity);
}
// print modified indexes
System.debug(decision.getModifiedIndexes());
// Print removed fields
System.debug(decision.getRemovedFields());
//System.debug Output
// DEBUG|Opportunity:{Name=Opportunity1}
// DEBUG|Opportunity:{Name=Opportunity2}
// DEBUG|{1}
// DEBUG|{Opportunity={Probability}}
2. Fire Platform Events from Batch Apex Classes (Generally Available)
Batch Apex classes can fire platform events when an error or exception is encountered. A batch Apex class declaration must be using API version 44.0 or later to implement the Database.RaisesPlatformEvents interface and fire a platform event. A platform event record now includes the phase of the batch job (start, execute, or finish) when the error was encountered. The start and finish methods of the Database.Batchable interface now fire platform events on error (which they didn’t do in the beta release).
Where: This change applies to Lightning Experience and Salesforce Classic in Enterprise, Performance, Unlimited, and Developer editions.
How: To fire a platform event, a batch Apex class declaration must implement the Database.RaisesPlatformEvents interface.
public with sharing class YourSampleBatchJob implements Database.Batchable<SObject>,
Database.RaisesPlatformEvents{
// class implementation
}