Posts

Showing posts from March, 2015

Best practices for writing test classes in Salesforce

Writing effective test classes is crucial in Salesforce development to ensure the quality and stability of your code. Cover as many lines of code as possible. Testing Best Practices Code Coverage Best Practices Here are some best practices for writing test classes in Salesforce: Test Coverage: Aim for high code coverage, typically aiming for at least 75% coverage for your Apex classes, and 100% if possible. Ensure that your test methods exercise all code paths, including positive and negative scenarios. Isolation : Write tests that are isolated from each other and from the data in the organization. Use the @testSetup annotation to create test data once and reuse it across test methods, minimizing the need to insert duplicate data in each test method. Data Creation : Create the necessary test data within your test class using Apex code rather than relying on existing data in the organization. This ensures that your tests are self-contained and portable, independent of changes in th...

Asynchronous Apex in Salesforce

Image
Asynchronous Apex in Salesforce refers to executing code asynchronously, meaning that the code is executed in the background without blocking the user interface. Asynchronous Apex is typically used for long-running or resource-intensive processes that would otherwise exceed the transaction execution time limits. Queueable Apex Take control of your asynchronous Apex processes by using the Queueable interface. This interface enables you to add jobs to the queue and monitor them. Using the interface is an enhanced way of running your asynchronous Apex code compared to using future methods. Apex Scheduler Batch Apex Future Methods This table lists the asynchronous Apex features and when to use each. Here'r multiple ways for running your Apex code asynchronously. @future Annotation : Methods annotated with @future are queued for execution in a separate transaction. This allows you to perform tasks asynchronously. @future methods can accept parameters and return void, making them suitab...