[SalesForce] System.AssertException: Assertion Failed: Same value

This is related to Lightning Specialist Superbadge step 6 – Automate fulfillment cancellation actions.

The task is when fulfillment is Cancelled, the related OpportunityLineItem unitprice (i.e., salesprice) should be same as the Fulfillment's Deposit. Simple. I manually checked this (after setting up process builder) and is working fine, but when the trailhead app checks, it fails with the error : System.AssertException: Assertion Failed: Same value.

ISSUE: Now, if I see the debug logs (captured when Salesforce trailhead checks this). In below snippet (from debug logs) see the last 2 lines.

There is assertEquals which checks deposit and unitprice – Match.
But assertNotEqual is also checking deposit and unitPrice. It fails here. Both the values will be same, the assertNotEqual is failing because both the values are same!

Execute Anonymous: OpportunityLineItem oli1 = new OpportunityLineItem(OpportunityId=opp.Id, UnitPrice=2, quantity=1,pricebookentryid=pbe.Id, servicedate = date.newInstance(2050, 1, 1), explorer__c = sam.id);
Execute Anonymous: OpportunityLineItem oli2 = new OpportunityLineItem(OpportunityId=opp.Id, UnitPrice=2, quantity=1,pricebookentryid=pbe.Id, servicedate = date.newInstance(2010, 1, 1), explorer__c = sam.id);

Execute Anonymous: // make sure the deposit matches the unit price
Execute Anonymous: System.assertEquals(f1.deposit__c, oli1.unitprice); // one way in the future
Execute Anonymous: System.assertNotEquals(f2.deposit__c, oli2.unitprice); // one way in the past

How to fix this? Is this a bug?

Best Answer

Not a bug per-se, this is exactly the point of assertNotEquals... if the parameters ARE NOT EQUAL it returns true. Else, it returns false.

You answered yourself in your question:

"Both the values will be same, the assertNotEqual is failing because both the values are same!"

Exactly right, as it should.

See the docs for more information: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_system.htm

But if you are asking "is this a bug w/ the trailhead validator", then perhaps it may be. You don't control their assertions, the assertions they have hardcoded into their validation engine when you click and check your answer after finishing a trailhead module.

Related Topic