function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PremKumar MohandassPremKumar Mohandass 

Assertions

Hi,

Can anyone tell me the actual difference between system.assert() and system.assertequals()?

Thanks in Advance,
Prem.
Best Answer chosen by PremKumar Mohandass
Shalom RubdiShalom Rubdi
Hey Prem - essentially with system.assert() you pass in a condition which you expect evaluates to true and an optional error message to return if the condition fails (evaluates to false).

With system.assertEquals() you pass in the actual & expected values as your first two arguments and an optional error message.  The method evaluates if the actual & expected values are equal, and returns true if so; if not, it returns false with the custom message passed in.

Reference links:

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

https://th3silverlining.com/2010/09/07/salesforce-system-assert-vs-system-assertequals/

All Answers

Shalom RubdiShalom Rubdi
Hey Prem - essentially with system.assert() you pass in a condition which you expect evaluates to true and an optional error message to return if the condition fails (evaluates to false).

With system.assertEquals() you pass in the actual & expected values as your first two arguments and an optional error message.  The method evaluates if the actual & expected values are equal, and returns true if so; if not, it returns false with the custom message passed in.

Reference links:

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

https://th3silverlining.com/2010/09/07/salesforce-system-assert-vs-system-assertequals/
This was selected as the best answer
PremKumar MohandassPremKumar Mohandass
Hi Shalom,

Thanks for the reply and links :)

Regards,
Prem.