Am I able to see the system.assert logs anywhere? I checked the logs after I run the test in my UAT org but i dont see the system.assert anywhere???

public class testSFSETrigger {
public static void myTest() {
    Account a1 = new Account();
    a1.Name = 'Test Bill To';
    insert a1;

    Opportunity o1 = new Opportunity();
    o1.Name = 'test';
    o1.Account = a1.Id;
    insert o1;

    Contact c1 = new Contact();
    c1.FirstName = 'Steve';
    c1.LastName = 'Rogers';
    c1.AccountId = a1.Id;
    insert c1;

    //Insert 1 quote to satisfy first fork criteria
    //where myObject.Contact__c != null;
    SBQQ__Quote__c quote = new SBQQ__Quote__c();
    quote.Contact__c = c1.Id;
    insert quote;

    system.assert(quote.Contact__c != null, 'Contact not created');

    //Insert another quote to satisfy second fork criteria
    // where myObject.Contact__c == NULL
    // and  myObject.Opportunity2__c != null 
    SBQQ__Quote__c quote2 = new SBQQ__Quote__c();
    quote2.Opportunity2__c = o1.Id;
    insert quote2;

 system.assert(quote2.Opportunity2__c != null 'Opportunity not related');

  • 1
    This code wouldn't even compile. Do your tests run? Do they pass?
    – Adrian Larson
    Commented May 31, 2018 at 19:28

2 Answers 2


System.debug() is for logging things that we need to see on debug logs (e.g. any message, object dump, etc.).

System.assert() is for proving our code behaves as expected.

It's better to use 2nd/3rd parameters to log any outputs too, so we have more information on possible issue if assert fails. For example,

system.assert(quote.Contact__c != null, 'Contact not created, quote.Contact__c: '+quote.Contact__c);

We must include sufficient System.assert() methods to prove that code behaves properly, and also follow Testing best practices .

I personally prefer having System.debug() before assert.

  • 2
    That's what the assertion message (2nd/3rd param) is for; you don't typically need to debug before assert. Debug statements can get lost in the logs, but the assertion method is guaranteed to be seen.
    – sfdcfox
    Commented May 31, 2018 at 21:04
  • 1
    Thanks @sfdcfox Yes, I agree with you. Probably it's my personal preference to have the values logged to specifically see in debug log regardless asserts failure. Updated answer accordingly. Commented May 31, 2018 at 22:06
  • 1
    Note also that if you are using a Logging framework (rather than system debug), you can make the third argument of system.assert: ... + MyLoggingFramework.getLog()) and then the assert includes the relevant details leading up to the assertion failure
    – cropredy
    Commented May 31, 2018 at 23:24
  • @cropredy Excellent point. I don't suppose you have a favorite you'd like to share?
    – sfdcfox
    Commented May 31, 2018 at 23:30
  • @sfdcfox - I'm using a modified version of the Andrew Fawcett EventLogger with Platform Events. I have to admit, I've been dilatory about contributing my enhancements to the lib so YMMV
    – cropredy
    Commented Jun 1, 2018 at 1:07

system.assert statements are different from system.debug statements.

System.debug will let you see the output from apex.

System.assert is used in test classes to make sure expected results match with actual outputs. When both match, the test class is said to be passed else failed. You can use it in regular apex to compare components of same type(integer vs integer, string vs string etc.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .