Example for System.assertEquals()

Sample Code:

public class SampleClass {
    public void insertAcct(String name, String extId) {
        Account acc = new Account(Name = name,External_ID__c = extId);
        insert acc;
        System.assertEquals('Test',acc.Name);
    }
}

In the above example, the expected name of the Account is 'Test'. If we give the name other than 'Test', it will throw error.

Opposite to System.assertEquals() is System.assertNotEquals().

Cheers!!!

2 comments:

  1. For picklist field comparison in System.assertEquals statement is returning false. Any idea how to resolve this problem?

    ReplyDelete
    Replies
    1. Check whether any workflow or process builder or trigger is changing the field value.

      Delete