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
dn6184dn6184 

Exceptions during record updates no longer halt the update. What changed?

We have an apex integration set up in SalesForce with our system and through this service we update our records when we update them in SalesForce. We have set up a way to halt a SalesForce record update if our system responds with an issue updating the record on our end. It throws an exception that SalesForce in turn showed on the page. However, sometime in the last 2 months we have noticed an issue where an exception thrown from the main apex classes no longer shows on the page, and the record gets updated anyway. No apex code has changed on our end and even our old sandboxes (some of which haven't been update since February) are displaying the same odd behavior. The only conclusion we can come up with is that something was changed in the way salesforce handles those exceptions. 
 
Desired Behavior:
When a record is edited (inline included) it sends a request to our system to check if the edit is valid. Our system responds saying that the edit is invalid. The apex class checks the response and if the response is valid it updates the record, if the response is not valid, it does not update the record and throws an exception which is displayed on the screen.
 
Current Behavior: Same as above except that when the respons is not valid, it updates the record anyway, and the exception (which is still thrown according to the logs) does not show anywhere on the page.
Any assistance would be appreciated.
Here's a sample of the log:

14:27:44.437 (437424000)|SYSTEM_METHOD_EXIT|[60]|LIST<AdminServiceAbstract.OperationResult>.add(Object)
14:27:44.437 (437433000)|SYSTEM_METHOD_ENTRY|[58]|system.ListIterator.hasNext()
14:27:44.437 (437444000)|SYSTEM_METHOD_EXIT|[58]|system.ListIterator.hasNext()
14:27:44.437 (437455000)|METHOD_EXIT|[146]|01p60000000Gzxf|AdminServiceAbstract.upsertContacts(LIST<Contact>)
14:27:44.437 (437503000)|METHOD_ENTRY|[163]|01p60000000Gzxd|AdminIntegrationImpl.CreateIntegrationLogEntry(String, String, String, String, Boolean)
14:27:44.437 (437547000)|METHOD_ENTRY|[366]|01p60000000H90N|IntegrationLogManager.stageLogEntry(String, String, String, String)
14:27:44.437 (437690000)|SYSTEM_METHOD_ENTRY|[21]|LIST<IntegrationError__c>.add(Object)
14:27:44.437 (437704000)|SYSTEM_METHOD_EXIT|[21]|LIST<IntegrationError__c>.add(Object)
14:27:44.437 (437713000)|METHOD_EXIT|[366]|01p60000000H90N|IntegrationLogManager.stageLogEntry(String, String, String, String)
14:27:44.437 (437728000)|METHOD_ENTRY|[372]|01p60000000H90N|IntegrationLogManager.persistStagedLogEntries()
14:27:44.437 (437760000)|SYSTEM_METHOD_ENTRY|[25]|LIST<IntegrationError__c>.size()
14:27:44.437 (437784000)|SYSTEM_METHOD_EXIT|[25]|LIST<IntegrationError__c>.size()
14:27:44.437 (437843000)|SYSTEM_METHOD_ENTRY|[28]|Database.insert(LIST<SObject>, Boolean)
14:27:44.437 (437879000)|DML_BEGIN|[28]|Op:Insert|Type:IntegrationError__c|Rows:2
14:27:44.492 (492650000)|DML_END|[28]
14:27:44.492 (492842000)|SYSTEM_METHOD_EXIT|[28]|Database.insert(LIST<SObject>, Boolean)
14:27:44.492 (492925000)|SYSTEM_METHOD_ENTRY|[31]|LIST<Database.SaveResult>.iterator()
14:27:44.493 (493099000)|SYSTEM_METHOD_EXIT|[31]|LIST<Database.SaveResult>.iterator()
14:27:44.493 (493124000)|SYSTEM_METHOD_ENTRY|[31]|system.ListIterator.hasNext()
14:27:44.493 (493140000)|SYSTEM_METHOD_EXIT|[31]|system.ListIterator.hasNext()
14:27:44.493 (493196000)|SYSTEM_METHOD_ENTRY|[31]|system.ListIterator.hasNext()
14:27:44.493 (493206000)|SYSTEM_METHOD_EXIT|[31]|system.ListIterator.hasNext()
14:27:44.493 (493226000)|SYSTEM_METHOD_ENTRY|[31]|system.ListIterator.hasNext()
14:27:44.493 (493235000)|SYSTEM_METHOD_EXIT|[31]|system.ListIterator.hasNext()
14:27:44.493 (493251000)|SYSTEM_METHOD_ENTRY|[41]|LIST<IntegrationError__c>.clear()
14:27:44.493 (493281000)|SYSTEM_METHOD_EXIT|[41]|LIST<IntegrationError__c>.clear()
14:27:44.493 (493293000)|METHOD_EXIT|[372]|01p60000000H90N|IntegrationLogManager.persistStagedLogEntries()
14:27:44.493 (493302000)|METHOD_EXIT|[163]|01p60000000Gzxd|AdminIntegrationImpl.CreateIntegrationLogEntry(String, String, String, String, Boolean)
14:27:44.493 (493319000)|SYSTEM_METHOD_ENTRY|[164]|System.debug(ANY)
14:27:44.493 (493342000)|USER_DEBUG|[164]|DEBUG|Everything failed
14:27:44.493 (493349000)|SYSTEM_METHOD_EXIT|[164]|System.debug(ANY)
14:27:44.496 (496944000)|METHOD_ENTRY|[5]|01p60000000Gzxk|ApplicationException.ApplicationException()
14:27:44.496 (496959000)|METHOD_EXIT|[5]|ApplicationException
14:27:44.497 (497017000)|CONSTRUCTOR_ENTRY|[165]|01p60000000Gzxk|<init>(String)
14:27:44.497 (497158000)|CONSTRUCTOR_EXIT|[165]|01p60000000Gzxk|<init>(String)
14:27:44.497 (497206000)|EXCEPTION_THROWN|[165]|ApplicationException: UpsertContacts: Error updating Contact:
Email: A contact with this email already exists.

14:27:44.497 (497231000)|EXCEPTION_THROWN|[168]|ApplicationException: UpsertContacts: Error updating Contact:
Email: A contact with this email already exists. Exception Thrown

14:27:44.497 (497242000)|METHOD_EXIT|[117]|01p60000000Gzxd|AdminIntegrationImpl.upsertContact(Id)
14:27:44.497 (497416000)|SYSTEM_METHOD_ENTRY|[134]|ApexPages.addMessage(ApexPages.Message)
14:27:44.497 (497451000)|VF_PAGE_MESSAGE|Error while synching data. Please make any necessary corrections and re-try. UpsertContacts: Error updating Contact:
Email: A contact with this email already exists. Supposed to have outputted to the page, but doesn't anymore

14:27:44.497 (497461000)|SYSTEM_METHOD_EXIT|[134]|ApexPages.addMessage(ApexPages.Message)
14:27:44.497 (497471000)|METHOD_EXIT|[27]|01p60000000Gzxv|PostEditController.doIntegration(String)
14:27:44.497 (497478000)|SYSTEM_MODE_EXIT|false
14:27:44.500 (500549000)|CODE_UNIT_FINISHED|IntegratedObjectController invoke(actionSave)
14:27:44.500 (500587000)|VF_APEX_CALL|j_id2|{!actionSave}|PageReference: none
14:27:44.515 (515999000)|CODE_UNIT_STARTED|[EXTERNAL]|01p60000000Gzxt|IntegratedObjectController get(ErrorMessage)
14:27:44.516 (516016000)|SYSTEM_MODE_ENTER|true
14:27:44.516 (516029000)|CODE_UNIT_STARTED|[EXTERNAL]|01p60000000Gzxt|ErrorMessage
14:27:44.516 (516044000)|CODE_UNIT_FINISHED|ErrorMessage
14:27:44.516 (516050000)|CODE_UNIT_FINISHED|IntegratedObjectController get(ErrorMessage)
14:27:44.516 (516405000)|VF_SERIALIZE_VIEWSTATE_BEGIN|06660000000TSh9
14:27:44.518 (518187000)|VF_SERIALIZE_VIEWSTATE_END
14:27:44.769 (522279000)|CUMULATIVE_LIMIT_USAGE
14:27:44.769|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 3 out of 100
Number of query rows: 3 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 1 out of 150
Number of DML rows: 2 out of 10000
Number of script statements: 190 out of 200000
Maximum heap size: 0 out of 6000000
Number of callouts: 1 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 0 out of 10

14:27:44.769|CUMULATIVE_LIMIT_USAGE_END

14:27:44.522 (522313000)|CODE_UNIT_FINISHED|VF: /apex/ContactPage
14:27:44.522 (522321000)|EXECUTION_FINISHED

Damien_Damien_

Does your page use the page message component on it and also rerender it?

 

<apex:pageMessages />

dn6184dn6184

Yes, the PostEdit page (the page that the addmessage is being sent to) has <apex:pageMessages /> on it.

 

Everything did work up until a couple weeks ago. We started seeing discrepancies between our data and salesforce and I finally had a chance to really find the root of the cause this week (rather than just fixing and syncing the data like we've been doing the past weeks). No code pertaining to any of those apex classes has changed since before this issue started so I'm rather stumped.

Damien_Damien_

Hmmmm, can't really think of another reason it wouldn't work. Sorry.