Posts

Maximum trigger depth exceeded

"Maximum trigger depth exceeded" is an error message in Salesforce that occurs when there's a recursive trigger execution that exceeds the platform's governor limit. Let's consider a scenario with a Contact object with a custom field called Total_Contacts__c. This field represents the total number of contacts associated with an account. We aim to ensure that this field is always up-to-date whenever a new contact is created, updated, or deleted.  To achieve this, we implement triggers on the Contact object that update the Total_Contacts__c field on the related Account object. Unfortunately, due to a mistake in the trigger logic, the triggers recursively update contacts and accounts, causing an error. Here's an example trigger UpdateTotalContacts on Contact (after insert, after update, after delete) {     if (Trigger.isAfter) {         if (Trigger.isInsert || Trigger.isUpdate) {             List<Account> accountsToUpda...

Salesforce Platform Cache

Salesforce Platform Cache is a feature that allows you to store and access data in memory, providing faster access to frequently used or computationally expensive data. It's particularly useful for improving the performance of Salesforce applications by reducing response times and decreasing the load on backend systems. The Platform Cache API lets you store and retrieve data that’s tied to Salesforce sessions or shared across your org. Put, retrieve, or remove cache values by using the Session, Org, SessionPartition, and OrgPartition classes in the Cache namespace. Use the Platform Cache Partition tool in Setup to create or remove org partitions and allocate their cache capacities to balance performance across apps. There are two types of cache: Session cache —Stores data for individual user sessions. For example, in an app that finds customers within specified territories, the calculations that run while users browse different locations on a map are reused. Session cache lives al...

Get Picklist Values Using Dynamic Apex

Image
  The picklist field name and object are the two parameters that the code snippet below requires. We can read either the Picklist label or the value based on these two inputs. String objectName = 'Account'; String fieldName ='Industry'; Schema.SObjectType s = Schema.getGlobalDescribe().get(objectName) ; Schema.DescribeSObjectResult r = s.getDescribe() ; Map<String,Schema.SObjectField> fields = r.fields.getMap() ; Schema.DescribeFieldResult fieldResult = fields.get(fieldName).getDescribe(); List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues(); for( Schema.PicklistEntry pickListVal : ple){ System.debug(pickListVal.getLabel() +' ---- '+pickListVal.getValue()); }  

Use Of addFields in ApexPages.StandardController

The add fields method helps developers specify fields for the standard controller to query in Visualforce pages. public AccountController(ApexPages.StandardController stdController){             this.controller = stdController;             List<String> fieldNamesList = new List<String>{Type,Industry};             stdController.addFields( fieldNamesList );             // stdController.addFields(new List<String>{'Name', 'TaxExemption__c', ' Industry '}); } Reference: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_ApexPages_StandardController_addFields.htm

Lock Records Using Apex in Salesforce

Locking Statements In Apex, you can use FOR UPDATE to lock sObject records while they’re being updated to prevent race conditions and other thread safety problems. Account [] accts = [SELECT Id FROM Account LIMIT 2 FOR UPDATE]; Locking Consideration When records are locked by a client, that client can modify the record's field values in the database within the same transaction. Other clients must wait until the transaction is completed and the records are no longer locked before they can update the same records. However, other clients can still query the locked records. If a record is already locked by another client, a process will wait for a maximum of 10 seconds for the lock to be released before acquiring a new lock. If the wait exceeds 10 seconds, a QueryException is thrown. Similarly, if a record is locked by another client and the lock is not released within 10 seconds, a DmlException is thrown. If a client tries to modify a locked record, the update can succeed if the lock ...

Web-to-Case In Salesforce

Image
Creating a Web-to-Case form in Salesforce enables you to automatically convert customer inquiries submitted through your website into cases within your Salesforce. Turn On and Customize Web-to-Case Generate and Test Your Web-to-Case Form To test the Web-to-Case form, add the line <input type="hidden" name="debug" value="1"> to the code. This line redirects you to a debugging page when you submit the form. Don’t forget to remove it before publishing the Web-to-Case page on your website. Web-to-Case Limits 5,000 cases in a 24-hour period. When you reach the 24-hour limit, additional requests are stored in a pending request queue that contains both Web-to-Case and Web-to-Lead requests Unsupported Content Types Web-to-Case forms don’t support the following content types: Attachments Rich text area (RTA) fields—If you use these fields on your forms, any information entered in them is saved as plain text when the case is created. Multipart/form-data—Cases ...

Web-to-Lead In Salesforce

Image
Creating a Web-to-Lead form in Salesforce allows you to capture lead information directly from your website and automatically create leads within your Salesforce instance Generate a new HTML by going to Setup > App Setup > Customization > Leads > Web-to-Lead. Generate Leads from Your Website for Your Sales Teams We can have multiple web-to-lead forms for various websites or landing pages and can be used to send leads to Salesforce. Please note that using the Web-to-Lead form you can automatically generate up to 500 new leads a day. Some of the Lead Sources available in Salesforce Web Phone Inquiry Partner Referral Purchased List Other Employee Referral Twitter External Referral Partner Public Relations Trade Show Word of mouth Here are the steps to follow  Click on "Create Web-to-Lead Form" Once you fill in the details, Click on "Generate" Here's a simple example of what the HTML code for the Web-to-Lead form might look like: <form action="ht...