Activity Forums Salesforce® Discussions What is the difference between assert() and assertEquals() with example in Salesforce? Reply To: What is the difference between assert() and assertEquals() with example in Salesforce?

  • PRANAV

    Member
    March 28, 2018 at 9:05 am

    Hi Ankit,

    System.Assert accepts two parameters, one (mandatory) which is the condition to test for and the other a message (optional) to display should that condition be false.

    System.AssertEquals and System.AssertNotEquals both accepts three parameters; the first two (mandatory) are the variables that will be tested for in/equality and the third (optional) is the message to display if the assert results in false.

    System.assert(var1 == var2, "The value of var1 is: " +var1 + " and the value of... oh I mean it's just a variable");

    System.assertEquals(var1, var2);

    If the second assertion fails the console will output the values of var1 and var2 with the labels “expected” and “actual”.

    Hope this helps you more.