Posts

Visualforce PDF Rendering Considerations and Limitations

It is essential to consider these limitations when designing Visualforce pages that will be rendered to PDF. Always verify the formatting and appearance of the PDF version of your page before putting it into production. The following are some limitations of the Visualforce PDF rendering service Limitations of the Visualforce PDF rendering service include the following. PDF is the only supported rendering service. The PDF rendering service renders PDF version 1.4 and CSS versions up to 2.1. Rendering a Visualforce page as a PDF file is intended for pages designed and optimized for print. A Visualforce page rendered as a PDF file displays either in the browser or is downloaded, depending on the browser’s settings. Specific behavior depends on the browser, version, and user settings, and is outside the control of Visualforce. The PDF rendering service renders the markup and data on your page, but it might not render formatting contained within the contents of rich text area fields added t...

"One Trigger Per Object" Pattern

The " One Trigger per Object " pattern is a best practice in Salesforce development that involves consolidating multiple trigger logic into a single, well-structured trigger handler class per object. This pattern helps to maintain clean and organized code, reduces the risk of trigger order issues, and facilitates better code reuse and maintainability. Trigger Handler Class public class AccountTriggerHandler {          public static void onBeforeInsert(List<Account> newList) {         // Your before insert logic here     }          public static void onBeforeUpdate(List<Account> newList, Map<Id, Account> oldMap) {         // Your before update logic here     }          public static void onBeforeDelete(List<Account> oldList) {         // Your before delete logic here     }        ...

System.CalloutException: Callout from triggers are currently not supported

The error message "System.CalloutException: Callout from triggers is currently not supported" indicates that a trigger in your Salesforce org is attempting to make a callout to an external system, which is not allowed. Salesforce does not allow callouts to be made directly from triggers. This restriction ensures the integrity and consistency of data in the Salesforce database. If handled improperly, callouts can result in long-running transactions, leading to performance issues or data inconsistencies. For example, when a new Account record is inserted and this trigger fires, you encounter the "System.CalloutException: Callout from triggers are currently not supported" error. trigger AccountTrigger on Account (after insert) {     for (Account acc : Trigger.new) {         // Make a callout to an external API         HttpRequest req = new HttpRequest();         req.setEndpoint('https://api.example.com');    ...

Lightning Design System (SLDS) in Visualforce pages

Salesforce Lightning Design System provides a set of CSS classes and design guidelines that allow you to create user interfaces that are consistent with the Salesforce Lightning Experience.  You can use the Lightning Design System (SLDS) to build Visualforce pages that match the look and feel of the Salesforce mobile app. To use SLDS, it takes some tweaks in your code and a few things to remember. Visualforce Page with SLDS <apex:page applyHtmlTag="false" applyBodyTag="false">     <html lang="en">     <head>         <title>SLDS Example in Visualforce</title>         <apex:slds />     </head>     <body>         <div class="slds-scope">             <div class="slds-grid slds-grid_vertical">                 <div class="slds-col slds-size_1-of-2">  ...

Exposing Apex Methods as SOAP Web Services

By exposing them as SOAP web services, apex methods are available to external applications. To make Apex methods available as SOAP web services, we must declare them within a global Apex class and use the "webservice" keyword. Salesforce will then automatically create a WSDL document for that class, which can be utilized by external applications to access the exposed web services. Example global class MyWebService {     webservice static Id makeContact(String contactLastName, Account a) {         Contact c = new Contact(lastName = contactLastName, AccountId = a.Id);         insert c;         return c.id;     } } To generate the WSDL file for a Salesforce instance, we can simply append "?wsdl" to the instance URL, followed by the path to the Apex class.  For example, the URL should look like https://yourinstance.salesforce.com/services/wsdl/class/MyWebService. Once you have the WSDL file, you can generat...

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...