You need to sign in to do that
Don't have an account?
Josh Davis 47
After insert from APEX no record is actually created even though debug log says it was
Hey Everyone, I am having an issue with some code and can't find the answers I'm looking for, hopefully someone else has ran into this before.
Issue: Even though the code inserts the 'AsyncRequests__c' records and I can see in the debug log that they are inserted. There is nothing in Salesforce that shows that they were. If I go to the URL with the ID as specified it says 'Unfortunately, there was a problem. Please try again. If the problem continues, get in touch with your administrator with the error ID shown here and any other related details. The requested resource does not exist', there is no DML operations indicating deletion, there are no new records visible in the UI or anything in the recycling bin. It is interesting to note that in my various tests
Trigger that Calls the Class, it is very simple and for the problem I am describing can be summed up by saying that 'Trigger.new' gets dumped into 'ContactList' used by the class.
Apex Class:
Debug Log:
The final oddity in all of this is that even though there is no trace of the inserted records, the autonumbering in Salesforce does skip like the records were inserted.
I am at a loss for why this would be happening and wondering if someone might be able to point me in the right direction of what I am missing. Thanks in advance!
Issue: Even though the code inserts the 'AsyncRequests__c' records and I can see in the debug log that they are inserted. There is nothing in Salesforce that shows that they were. If I go to the URL with the ID as specified it says 'Unfortunately, there was a problem. Please try again. If the problem continues, get in touch with your administrator with the error ID shown here and any other related details. The requested resource does not exist', there is no DML operations indicating deletion, there are no new records visible in the UI or anything in the recycling bin. It is interesting to note that in my various tests
Trigger that Calls the Class, it is very simple and for the problem I am describing can be summed up by saying that 'Trigger.new' gets dumped into 'ContactList' used by the class.
trigger AsyncNPICall on Contact (after insert, after update) { AsyncProcessing.handleNPITrigger(trigger.new, trigger.newMap, trigger.oldMap, trigger.operationType); }
Apex Class:
public class AsyncProcessing { // Simple protection from workflows and triggers private static Boolean alreadyProcessed = false; public static void handleNPITrigger(List<Contact> ContactList, Map<ID, Contact> newMap, Map<ID, Contact> oldMap, TriggerOperation operation) { if(alreadyProcessed) return; alreadyProcessed = true; List<AsyncRequest__c> newAsyncRequests = new List<AsyncRequest__c>(); List<String> textChangedIds = new List<ID>(); System.debug('Total Contacts in Contact List: ' + ContactList.size()); for(Contact co: ContactList) { // If the record is new and NPI != blank or if the NPI has changed if(operation == TriggerOperation.AFTER_INSERT && !String.isBlank(co.NPI__c) || co.NPI__c!= oldMap.get(co.id).NPI__c && !String.isBlank(co.NPI__c)) { textChangedIds.add(co.id); } // Once 99 records have been looped, group them for Asynchronus Processing, join their IDs into a long text field on the custom object 'AsyncRequest__c' if(textChangedIds.size()>99) { newAsyncRequests.add( new AsyncRequest__c( AsyncType__c = 'NPI API Call', Params2__c = string.Join(textChangedIds,',') ) ); System.debug('Current Async Request Size in Loop: '+newAsyncRequests.size()); textChangedIds.clear(); } } // Whatever is left over after processing all the records if the amount never reached 99, create a final 'AsyncRequest__c' record to house them if(textChangedIds.size()>0){ newAsyncRequests.add( new AsyncRequest__c( AsyncType__c = 'NPI API Call', Params2__c = string.Join(textChangedIds,',') ) ); } // System Debugging to ensure all values are present System.debug('Async Request Size:' + newAsyncRequests.size()); for( AsyncRequest__c a: newAsyncRequests){ System.debug(a.Name + a.params2__c); } insert(newAsyncRequests); // Debugging the final insert of the records for (AsyncRequest__c ar : newAsyncRequests) { System.debug(ar.id); } } }
Debug Log:
The final oddity in all of this is that even though there is no trace of the inserted records, the autonumbering in Salesforce does skip like the records were inserted.
I am at a loss for why this would be happening and wondering if someone might be able to point me in the right direction of what I am missing. Thanks in advance!
Can you please check if you have any triggers running on the AsyncRequest__c object? The only possible case is that records are somwhow deleted from the triggers running on this object.
If this also looks fine then I dont see any reason why the records are deleted.
The other reason might be that the user fro which you are trying to view these newly created records do not have the permission to view them. Please check the access on the object as well.
Let me know if you find anything on this. I am also available to connect on a call in case this is urgent.
Thanks,
Abhishek Bansal.
Gmail: abhibansal2790@gmail.com
Skype: abhishek.bansal2790
Phone: +917357512102
Hi Josh,
In your main org / production where you are unable to access these records from UI, what happens if you try to run a report or SOQL in dev console?
Leads me to my Next Question: Why does having a single record in batch that has a problem with duplicate rules cause only the AsyncRequest__c records from being rolled back for that batch? The contacts get inserted correctly (all except the one) so there is no issue there, but only the AsyncRequest__c records that were created from the batch get rolled back. Is there a way for me to catch this rollback in a system.debug of somekind? I can reliably replicate it, but I can't see it in any debug statement anywhere or in any error.
Current Code for my AsyncProcessing class (change is at the end by the insert where I have added more system.debug statements)
My only Trigger on the AsyncRequest__c object
My only other class that performs an update action against the contacts (at the very end)