System assertEquals Salesforce – System methods

System assertEquals Salesforce

System assertEquals Salesforce

System assertEquals Salesforce, Here I am posting about assert methods in System class. This helps everyone to find the differences between assert methods in salesforce.




Below are the three assert methods in system class.
1. System.assert(condition, msg)
2. System.assertEquals(expected, actual, msg)
3. System.assertNotEquals(expected, actual, msg)

What is System.assert(condition, msg)?

This method asserts that the specified condition is true. If it is not true, a fatal error is returned that causes code execution to halt.



Signature of this method:
Public static void assert(Boolean condition, Object msg)

This method is having two parameters, one is condition which is Boolean type, the other one is msg which is optional and object type.

 What is system.assertEquals(expected, actual, msg)?

This asserts that the first two arguments are the same. if they are not same, a fatal error is returned that causes code execution halt.

Signature of this method:
Public static void assertEquals(Object expected, Objecet actual, object msg)

This method is having three parameters, one is expected which is a type of object, second one is actual which is also type of object and the other one msg which is optional and type of object.

What is system.assertNotEquals(expected, actual, msg)?

This asserts that the first two arguments are not same. if they are the same, a fatal error is returned that causes code execution halt.



Signature of this method:
Public static void assertNotEquals(Object expected, Objecet actual, object msg)

This method is having three parameters, one is expected which is a type of object, second one is actual which is also type of object and the other one msg which is optional and type of object.

Note: We cannot catch an assertion failure using a try/catch block even though it is logged as an exception in case all above three methods.

To know more about this refer below Salesforce documentation URL about salesforce system class.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_system.htm#apex_System_System_methods




Leave a Reply