Posts

Showing posts with the label salesforce_winter24_release_notes

Salesforce Custom Metadata Types Explained: Benefits, Setup, and Examples

Image
Salesforce's powerful Custom Metadata Types functionality lets developers and administrators make deployable, adjustable configurations and settings. The application cache contains all of the custom metadata, allowing access without requiring repeated database queries. How to create Custom Metadata Type 1. Search  Custom Metadata Type  in Setup Quick Find. 2. Click New Custom Metadata Type 3. Fill all required fields and click save Accessing Custom Metadata Type in Apex 1. Using getAll() - returns map of developer name to metadata type record list.   Datatype returned by the method - Map<String, Games__mdt> List<Games__mdt> mcs = Games__mdt.getAll().values(); boolean textField = null; if (mcs[0].GameType__c == 'PC') { textField = true; } system.assertEquals(textField, true); 2. Using getInstance(recordId) Returns a single custom metadata type record sObject for a specified record ID. Games__mdt mc = Games__mdt.getInstance('m00000000000001'); Using g...

Salesforce GraphQL: Developer Insights

Image
What is GraphQL?   GraphQL is a standard query language for APIs and a runtime for fulfilling those queries with your data. It provides users with a single endpoint to request all necessary data from in a single request. Applications that utilise GraphQL APIs are frequently far more efficient than those that stick with REST APIs. This is due to their capacity to retrieve all required data in a single invocation, which reduces the number of round trips to the server, allowing you to customise it to meet your needs. Why GraphQL is better than REST API? REST API is the gold standard for APIs, yet traditional REST APIs present significant issues when developing modern, highly performant, and scalable online and mobile applications. REST endpoints do not allow client changes to the API endpoint's response.   For example, when fetching a user's phone number from a REST API, receiving extraneous data beyond the number adds unnecessary costs for both the server and the requester. ...

Leveraging Object and Field References in LWC Wire Adapters

Image
When utilizing a wire adapter, it is strongly advised to import references to fields and objects in a lightning/ui*Api module. Salesforce verifies the validity of the fields and objects, prevents their removal, and propagates any rename modifications into your component's source code. It also ensures that dependent objects and fields are included in change sets and packages. If references to objects and fields are imported, your code will still work even if their names change in salesforce.  Lightning Web Components supports the import of references to standard objects, as well as the import of references to custom objects (__c) only. To import a reference to an object, use this syntax . import objectName from "@salesforce/schema/object"; import objectName from "@salesforce/schema/namespace__object"; import FIELD_NAME from "@salesforce/schema/object.field"; Example: import ACCOUNT_OBJECT from "@salesforce/schema/Account"; import ACCOUNT_NAME_...

(Salesforce Apex 2024 Release) Monitor Async Apex Job Limit Usage

Image
Monitor your org’s async Apex usage on the Apex Jobs Setup page to mitigate potential limit problems before they happen. You see the percentage of async Apex used and how many Apex operations have been used out of the allowed 24-hour org limit Step1 : From Setup, in the Quick Find box, enter Apex Jobs Step2 : Select Apex Jobs

(Salesforce Apex 2024 Release) InvalidHeaderException in Apex REST API

Image
  The reason you are encountering the error InvalidHeaderException is due to a recently implemented restriction that states that REST response headers defined in Apex via the RestResponse must match API versions. RFC 7230 is used to validate the header names in the addHeader(name, value) method. Following the upgrade, many more restrictions have been implemented; you can verify them by visiting the RFC 7230 validation page. Invalid characters, including /(slash), are no longer accepted. Below is a summary of the information found on the validation page of RFC 7230: Header Field Syntax: Each header field consists of a case-insensitive field name followed by a colon (":"), optional leading whitespace, the field value, and optional trailing whitespace. Field Extensibility: Header fields are fully extensible, allowing the introduction of new field names, each defining new semantics. Unrecognized header fields should be forwarded, except when exp...

(Salesforce Apex 2024 Release) getSalesforceBaseUrl method is deprecated

Image
  The getSalesforceBaseUrl() method is no longer available and deprecated in API versions 59.0 and beyond. Alternatively, use getCurrentRequestUrl() to obtain the URL of a complete request on a Salesforce instance, or getOrgDomainUrl() to obtain your organization's URL. A compilation error occurs when the deprecated method in API version 59.0 and later is attempted to be used. System.debug(URL.getOrgDomainUrl());

(Salesforce Apex 2024 Release) For loops now directly support Iterable

Image
As per the Winter `24 release notes It will work directly on Iterable classes, so you don't need to call .iterator() explicitly yourself in the for loop. The code that we currently need to write in order to iterate over an iterable is shown below. and we are relying on the more verbose while loop currently imposed on us. Current Implementation Iterator<Integer> iter = someClass.iterator(); while(iter.hasNext()) { Integer value = iter.next(); // Do something with value } New Implementation as per winter `24 release notes for(Integer value: someClass.iterator()) { // Do something with value } We could use this in almost every class we develop, including triggers, the majority of Visualforce pages, and pretty much any other place we have to write loops. It facilitates reading the code, particularly when we want to iterate over several levels of data. With Lists, Sets, and queries.

(Salesforce Apex 2024 Release) A Deep Dive into List Element Comparison

Image
  You can now construct different sort orders in your code by using List.sort() with a Comparator parameter, as the List class now implements the new Comparator interface. For sorting and locale-sensitive comparisons, use the new Collator class's getInstance function. due to the fact that locale-sensitive sorting's outcomes can change depending on who runs the code. utilizing it in code that anticipates a specific sort order or in triggers, let's see with an example To sort the employees by name in this example, let's construct a class called Employee with two properties: a name and an id. Since the name property is private, we will use the getName function to retrieve the employee's name. public class Employee { private Long id; private String name; //Constructor public Employee(Long i, String n){ id=i; name=n; } public String getName() { return name;} } Now, to add the sorting logic, we will create a class named N...