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

How to detect if a future call fails after it is sent to SF

I have a situation that I have  been unable to recreate because it happens less than 10 times a year that I am aware of.  There is a future call that executes after the Opportunity Product Related List is updated and the custom field on is Checked.  That causes a fture call that grabs all product names where the checkbox is checked and strings there values in a custom field on the Opportunity page called Products_Sold__c.  There are times when the Products_Sold__c field never gets populated.

Is there a way that in the future call method I can have SF notify me if that calls fails for whatever reason such as record locking issue or whatever?

As I wrote the question I realized that I should put the DML in a TRY CATCH and send an email to Admins if a failure is detected.  Is that possible?  I will start down that avenue as I wait for an answer from someone.  

For realtime monitoring you could use the exception handling option you mentioned above.

However, you could also fire an SOQL query to get the details of the future calls in the past 24 hours.

You can try this:
SELECT ApexClassId,CompletedDate,CreatedById,CreatedDate,ExtendedStatus,Id,JobItemsProcessed,JobType,LastProcessed,LastProcessedOffset,MethodName,NumberOfErrors,ParentJobId,Status,TotalJobItems FROM AsyncApexJob WHERE JobType='Future'

Hope this helps.

Satish Kumar

I believe the query produces the same results that are seen at Apex Job screen; however, I still ran the query and there are no jobs that failed!  In fact, after the update of the opportunity I send an email on success and in the catch side and I only get the email from the TRY side so I have to assume that the update occurs.  The content in the update is not being saved to the opportunity level!  Or is it!  That statement brings me to a rather scenario question that I was hoping the user community can help me with. This is what I am doing and this is what I believe is happening.  Please tell me if this is possible as I am only assuming! :(

After the user saves the product a trigger is fired which calls a method using the @future.  In that method an update is executed.  Typically after the user checks of what they sold in the product related list, they change the opportunity stage to 'Sold'.  I believe that at the time they put the opportunity in edit mode the hidden field is blank.  While in edit mode the @future call executes and updates the hidden field with the products that the user checked off in the product related list as sold.

Now, the user saves the opportunity which pushes the blank value back up to the server (remember it was blank when they went into edit mode).

I feel this is what is happending because after I made the field read only I the problem no longer occurs and because code runs in System mode even though the field is read only the future statement can update the field but the user cannot from the GUI interface!

Is this a feasible assumption?