Posts

Tip of the week # 217 : Apex Trigger Best Practices

Image
Salesforce : Apex Trigger Best Practices Description : Apex Triggers in Salesforce are a powerful way to extend platform functionality. They enable developers to perform custom actions before or after record changes such as insert, update, or delete operations. To maintain high code quality and performance, it is essential to write efficient and optimized trigger logic. While triggers provide a high degree of flexibility and control, following best practices is crucial to ensure that the code remains scalable, maintainable, and efficient. Apex Trigger Best Practices : One trigger per object We should always write one trigger per object, as having multiple triggers on the same object can cause unexpected behavior due to the lack of a guaranteed execution order. To avoid this, consolidate all trigger logic for an object into a single trigger and delegate the detailed processing to helper classes. This approach improves clarity, maintainability, and control ov...

Tip of the week # 216 : Salesforce Composite and Composite Tree API

Image
Salesforce Composite and Composite Tree API with Examples Description : Executes a series of REST API requests in a single POST request, or retrieves a list of other composite resources with a GET request. Salesforce REST Composite API's : Salesforce REST Composite : To perform multiple REST API calls in a single request.Batch multiple API sub-requests together, execute sequentially (or in parallel), and optionally reference results between them. Method:- Post (For Insert) URL:-/services/data/v64.0/composite Request Body :- { "compositeRequest": [ { "method": "POST", "url": "/services/data/v64.0/sobjects/Account", "referenceId": "newAccount", "body": { "Name": "Test Account" } }, { "method": "POST", "url": ...

Tip of the week # 215 : Salesforce REST API

Image
Salesforce REST API's with Examples Description : Salesforce REST API allows external applications to interact with Salesforce using HTTP methods like GET, POST, PATCH, and DELETE. It streamlines CRUD operations, making integrations simpler and more efficient. Types of Salesforce REST API's : Standard REST API : For basic record operations. (Below example for create account via REST API) Method:- Post URL:- /services/data/v36.0/sobjects/Account/ Request Body :- { "Name" : "Account from Rest API", "phone" : "1111111111", "website" : "www.salesforce1.com", "numberOfEmployees" : "100", "industry" : "Banking" } Response Body :- { "id" : "00190000001pPvHAAU", "errors" : [ ], "success" : true, ...

Tip of the week # 214 : Lightning Datatable with Mask and Unmasked

Image
Lightning Datatable with Mask and Unmasked Description : lightning-datatable displays tabular data where each cell with field values and value should be masked and unmasked. ADVANCED OPTIONS FOR lightning-datatable IN LWC : Component HTML Component JS import { LightningElement, track, api } from 'lwc'; import getContacts from '@salesforce/apex/ContactController.getContacts'; export default class MaskComp extends LightningElement { @track accounts; @api recordId; columns = [ { label: 'First Name', fieldName: 'FirstName', type: 'text' }, { label: 'Last Name', fieldName: 'LastName', type: 'text' }, { label: 'Email', fieldName: 'maskedEmail', type: 'button', ...

Tip of the week # 213 : Set up reCAPTCHA for Experience Cloud Site

Image
Set up reCAPTCHA for Experience Cloud Site Description : Set up reCAPTCHA in the Experience Cloud sites to ensure that the provider applications are filled in by humans, not bots.. Steps are following : Generate a Google reCAPTCHA site key, and copy the site key. For more information, From Setup, in the Quick Find box, enter Digital Experiences, and select All Sites. Click Builder next to the Experience Cloud site for your providers. Configure the security settings In the Settings section, select Security and Privacy. Click Edit Head Markup, and then paste this code: Make sure Lightning Locker is turned on. To add Google as a trusted site, click Add Trusted Site. For Name, enter Google. For URL, enter https://www.google.com. Make sure Active is selected, and then click Add Site. To add gstatic as a trusted site, click Add Trusted Site. For Name, enter gstatic. For URL, enter https://www.gstatic.com. Make su...

Tip of the week # 212 : Lightning Datatable hidden gems

Image
Lightning Datatable hidden gems Description : lightning-datatable displays tabular data where each column renders the content based on the data type. ADVANCED OPTIONS FOR lightning-datatable IN LWC : Displaying and formatting of columns with appropriate data types const columns = [ { label: 'Opportunity name', fieldName: 'OpportunityName', type: 'text' }, { label: 'Probability', fieldName: 'Probability', type: 'percent', cellAttributes: { iconName: { fieldName: 'TrendIcon' }, iconPosition: 'right', }, }, { label: 'Amount', fieldName: 'Amount', type: 'currency', typeAttributes: { currencyCode: 'EUR', step: '0.001' }, }, { label: 'Contact Email', fieldName: 'Contact', type: '...

Tip of the week # 210 : Lightning Input Address with Autocomplete

Image
Lightning Input Address with Autocomplete Description : In Lightning Web Components (LWC), A lightning-input-address component with Autocomplete.(Powered By Google) Code snapshot is following : HTML File JavaScript: import { LightningElement,api } from 'lwc'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; export default class AddressLwc extends LightningElement { @api recordId; @api objectAPIName='Contact'; strStreet; strCity; strState; strCountry; strPostalCode; handleSuccess( event ) { this.dispatchEvent( new ShowToastEvent({ title: 'Successful Record Update', message: 'Record Updated Surccessfully!!!', variant: 'success' })); } handleSubmit(event){ let fields = ev...