Friday, 22 May 2015

More Salesforce Spring 15 Release

Set Up Test Data for an Entire Test Class 
Use test setup methods (methods that are annotated with @testSetup) to create test records once and then access them in every test method in the test class. Test setup methods can be time-saving when you need to create reference or prerequisite data for all test methods, or a common set of records that all test methods operate on.

@testSetup static void setup() {
// Create common test accounts
List<Account> testAccts = new List<Account>();

for(Integer i=0;i<2;i++) {
testAccts.add(new Account(Name = 'TestAcct'+i));

insert testAccts;

//The Accounts created in setup() are automatically available in testMethod1() and testMethod2() which makes our test methods easier to make and the tests will run faster and more efficient

static void testMethod1() {

static void testMethod2() {

Chain More Jobs with Queueable Apex 
Queueable Apex was introduced in Winter ’15 and enables you to easily start and manage asynchronous processes. Previously, you could chain a queueable job to another job only once. You can now chain a job to another job an unlimited number of times. For Developer Edition and Trial organizations, your chain can have up to five queueable jobs.

public class AsyncExecutionExample implements Queueable {

public void execute(QueueableContext context) {
// Your processing logic here
// Chain this job to next job by submitting the next job

System.enqueueJob(new SecondJob());  //2nd job queued


No comments:

Post a Comment

Note: only a member of this blog may post a comment.