New Features For Platform Developers
Salesforce during the Winter 22 release came up with many exciting features. As always all the new features are super cool and good to know. But I will be discussing two of them which I believe are very useful features for a Platform Developer.
You no longer need to write a Salesforce Object Query Language (SOQL) to access custom metadata records in Apex. There are new methods similar to accessing Custom Settings. This removes any SOQL limits, making the code cleaner and faster.
Example: This sample returns a single record sObject for the custom metadata type named Sample_mdt with developerName specified as FirstRecord.
Sample_mdt cm = Sample_mdt.getInstance('FirstRecord');
If you note it is now similar to the way we retrieve Custom Settings.
2. SOQL FIELDS() Function
We all know how to write a SOQL, but sometime if you don’t know what fields an object has, you must first get a description of the object. Typically, you use a call to first get a description of the object, then parse the description to identify the fields. Then you construct a SOQL query that specifies the fields, and then make another call to submit the query.
To simplify this process, the FIELDS() function lets you select fields easily, without knowing their names in advance. The FIELDS() function eliminates the need for a round trip to the server to prepare a SOQL statement, eliminates the need for research and a lot of typing, simplifies query statements, and makes it much easier to explore the shape of your objects. It also helps avoid exceeding the character limits on SOQL queries and the URI length limit for REST calls.
You can now include any of these in the field list:
In each case, FIELDS() respects field-level security so it only shows the fields that you have permission to access. This function is available in API version 51.0 and later.
Recommended by LinkedIn
Example:
You can also mix FIELDS() with other field names in the field list. For example:
FIELDS() is supported in these platform features:
The FIELDS() function is a brilliant addition but we if you already know which fields you want to retrieve, you’ll get better performance by specifying them explicitly rather than using FIELDS() and retrieving more fields than you need.
“Concentrate all your thoughts upon the work in hand. The sun's rays do not burn until brought to a focus. “
Alexander Graham Bell