Category: Apex
-
How is Aggregate Code Coverage Calculated in Salesforce?
Question How does Salesforce calculate aggregate code coverage when multiple Apex classes are involved? Is it based on the average coverage per class or the ratio of covered lines to total testable lines? Answer Salesforce determines aggregate code coverage using the ratio of all covered lines to the total testable lines in the org, not…
-
How to Retrieve Tabs, Apps, and Apex Classes in Salesforce?
Question I am using sf project retrieve to pull metadata from my Salesforce Dev Hub into my local project. My package.xml retrieves Apex triggers but does not fetch custom applications (Lightning apps), custom tabs, Apex classes, or custom fields. How can I modify package.xml to retrieve them? Answer In Salesforce, retrieving metadata using sf project…
-
How Do I Write an Apex Unit Test?
Question Writing unit tests in Apex is an essential practice for ensuring code quality, maintaining stability, and meeting Salesforce’s deployment requirements. A well-written unit test follows structured principles to verify that your code behaves as expected. Answer Understanding Apex Unit Tests Apex unit tests follow three essential steps: Create test data: Before executing your code,…
-
Why Does EncryptSymmetric() in AMPScript Produce Different AES Results?
Question We are trying to encrypt and encode URL parameters in Salesforce Marketing Cloud using the EncryptSymmetric() function with the AES algorithm. Following the documentation, we used the following AMPScript: The function returned: However, decrypting this value using an online AES tool resulted in an error. Encrypting the same string with an online AES-128 tool…
-
How Can I Integrate Salesforce with JIRA?
Question I have been looking for an easy way to integrate Salesforce with JIRA and have gone through JIRA’s documentation. I also tried a few AppExchange packages, but they only support standard objects. However, my use case requires integrating a custom object in Salesforce with JIRA issues. What are some easy ways to achieve this…
-
What is the Trigger Execution Order During Lead Conversion?
Question I’m working on a project where I need to customize the standard lead conversion process. Triggers during lead conversion have always been tricky in past projects, so I want to ensure I fully understand the exact order of execution before designing my solution. However, after searching extensively, I haven’t found a clear and detailed…
-
Why Is My Apex Sharing Rule Not Granting Record Access?
Question I am trying to share Project__c records with the Project Management Team public group when Priority__c is set to “High” using an Apex sharing rule. To achieve this, I created an Apex Sharing Reason called Project_Sharing_Rule and implemented the following trigger and helper class: Trigger Code Apex Class Code Answer The error occurs because…
-
How to Retrieve Named Principal Values in Apex?
Question I have a scenario where I need to generate an additional token before making a callout. This token requires API_KEY and API_SECRET, which I have stored in Named Principals. The usual approach, as mentioned in Salesforce documentation and forums, is to use the following formula: However, this does not work because the formula is…
-
How to Check Record Type in a Loop?
Question However, I can’t access the record type ID of LinkedEntityId directly in the loop. I tried: But I get the error:“Method does not exist or incorrect signature: void getRecordTypeId() from the type Id.” How can I correctly retrieve and compare the record type ID in this scenario? Answer Since the system does not allow…