Winter '21 Release Highlights - Programmatic Code

 

Learn What’s New in Winter ‘21

Learning Objectives


After completing this unit, you’ll be able to:

  • Improve Apex testing with new SObject error methods.
  • Develop flow screen components that work for multiple objects.
  • Create custom property editors for Lightning web components.
  • Enforce profile-based access for @AuraEnabled Apex classes.
  • Make more powerful composite requests.

Improve Apex Testing with New SObject Error Methods

Track errors with the new SObject.hasErrors() and SObject.getErrors() methods without performing a DML operation to check the result for errors. Dynamically add errors to specific fields with new SObject.addError() overload methods. Use the hasErrors() method to know if an SObject instance contains errors. Use the getErrors() method to retrieve the list of errors for a specific SObject instance.

If the SObject.addError() method has been called on an SObject instance, the SObject.hasErrors() method returns true. The SObject.getErrors() method returns a list of Database.Error objects that contain the errors encountered.

This example code shows usage of the new SObject error methods.

//Baseline code sample for using addError, getErrors, together Account a = new Account(); String msg = 'New error method in SObject'; //The new overload that accepts the field dynamically at runtime a.addError('Name', msg); List errors = a.getErrors(); System.assertEquals(1, errors.size()); Database.Error error = errors.get(0); System.assertEquals(msg, error.getMessage()); System.assertEquals(StatusCode.FIELD_CUSTOM_VALIDATION_EXCEPTION, error.getStatusCode()); String[] fields = error.getFields(); System.assertNotEquals(null, fields); System.assertEquals(1, fields.size());


Develop Flow Screen Components That Work for Multiple Objects

Now you can create reusable flow screen components that use the generic sObject and sObject[] data types. Build one component that works for multiple objects, rather than one for each individual object. For example, you can build a data table component that works with any collection of records, from accounts and contacts to custom objects.

Here’s how it works. Create a custom flow screen Lightning web component, or edit an existing one. In its configuration file, a flow screen component has the target lightning__FlowScreen.

  1. Define a type that extends the generic sObject data type by defining a <propertyType>.

  2. For each property that maps to the same object, set the property’s type attribute to {propertyTypeName}. If the attribute expects a collection of that object, set the type attribute to {propertyTypeName[]}. For example, if propertyTypeName is T, use {T} or {T[]}.

You can reference the same property type for single and collection properties. To set the type attribute for single or collection variable properties, see the comments in the code example.

<!-- myComponent.js-meta.xml -->
<targetConfigs> <targetConfig targets="lightning__FlowScreen"> <!-- Declare a property type that extends SObject for single and collection
variable properties.--> <propertyType name="T" extends="SObject" label="Object"
description="Select an object." /> <!--To use a collection of the SObject data type, use
the braces in this syntax, type="{T[]}".--> <property name="tableData" label="Records to Display" type="{T[]}"
role="inputOnly" required="true" description="REQUIRED: Record Collection variable
containing the records to display in the data table. Make sure to
select a variable that matches the selected object."/> <property name="preSelectedRows" label="Preselected Rows"
type="{T[]}" role="inputOnly" description="Which records should be selected by
default when the table renders? Select a Record Collection variable
that contains those records."/> <property name="outputSelectedRows" label="User-Selected Rows"
type="{T[]}" role="outputOnly" description="Which records were selected by the user a
t runtime? This value should be stored in a record collection variable."/> </targetConfig> </targetConfigs>


Previously, the example component was tied to one object, such as Account, Contact, or myCustomObject__c. But now developers create one component, and the Flow Builder admin chooses the object each time they use that component.

Create Custom Property Editors for Lightning Web Components

Create a custom property editor that lets an admin configure a flow screen component in Flow Builder. 

Previously, when you configured a custom flow screen component, the UI was composed of combo boxes. The developer who built the component had no control over the property editor UI.

The custom property editor is simply a Lightning web component. Now, developers can create a custom Lightning web component that provides a clean, simple experience for you when you configure a flow screen component.

Enforcement for Profile-Based Access for @AuraEnabled Apex Classes

We’re enforcing the two release updates for Apex classes containing @AuraEnabled methods. There’s also a new Enable Secure Static Resources for Lightning Components release update. This update enforces user profile and permission set restrictions for Apex classes used by Aura and Lightning web components.

Restrict Access to @AuraEnabled Apex Methods for Guest and Portal Users Based on User Profile

This update gives you more control over which guest, portal, or community users can access Apex classes containing @AuraEnabled methods. Add guest user profile access to any @AuraEnabled Apex class used by a community or portal. When this update is activated, a guest, portal, or community user can access an @AuraEnabled Apex method only when the user’s profile allows access to the Apex class.

Restrict Access to @AuraEnabled Apex Methods for Authenticated Users Based on User Profile

This update gives you more control over which authenticated users can access Apex classes containing @AuraEnabled methods. When this update is enforced, an authenticated user can access an @AuraEnabled Apex method only when the user’s profile allows access to the Apex class.

In the next unit, we learn how to use the Composite Graph resource to insert a hierarchy of records in a single API call. Dig into the resources below to find more about the updates in this unit and other exciting changes. 

Resources

Comments

Popular posts from this blog

Adding a red asterisk to required fields using label in LWC

The Developer Console didn't set the DEVELOPER_LOG trace flag on your user. Having an active trace flag triggers debug logging. You have 1,978 MB of the maximum 1,000 MB of debug logs. Before you can edit trace flags, delete some debug logs.

Salesforce: Serial and Parallel Approval