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
Mauricio OliveiraMauricio Oliveira 

Can't reproduce Syncing Quote correct behavior in test

Hi everyone.

I have a Quote trigger that should update a custom field when the Quote is unsynced, but I'm having troubles in representing this correctly in a test. This is from my trigger:

// Only case that it shouldn't be marked is when editing an unsynced Quote
if (!old_map.get(quote.Id).IsSyncing && !quote.IsSyncing) {
    continue;
}

sales_order.Quote_was_modified__c = true;
update sales_order;

As you can see, the field should always be updated, unless the Quote was unsynced and remains unsynced. Doing this in Salesforce interface (pressing Stop Sync button) works fine, but this test fails and I can't figure out why:

quote = [SELECT Id, IsSyncing FROM Quote WHERE Id =: quote.Id];
system.assert(quote.IsSyncing);

// Unsync that quote
opportunity.SyncedQuoteId = null;
update opportunity;

// Check if it was unsynced
quote = [SELECT Id, IsSyncing FROM Quote WHERE Id =: quote.Id];
system.assert(!quote.IsSyncing);

sales_order = [SELECT Id, Quote_was_modified__c FROM Sales_Order__c WHERE Id =: sales_order.Id];
system.assert(sales_order.Quote_was_modified__c);


This last assert fails. I have added some system.debug calls in this code and found out that it is getting into that if statement that checks if the Quote was and remains unsynced. When accessing the oldMap version of the Quote right after the update opportunity call, IsSyncing is already set to false. So, why is that happening? Am I missing something?

Thank you

Eric PepinEric Pepin
The continue keyword only skips to the next iteration of a looping structure. If this code is not contained within a loop, then the continue keyword will simply do nothing and the update will happen in all cases. You haven't provided enough code to know if this is the issue or not.