• SPrajapati
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Is there any tool to analyze the apex logs other than the Log Inspector in Developer Console.
The log I am trying to analyze is deleted from the org but I have a local copy of that and I am trying to resolve a CPU Timeout issue.
Tried https://apextimeline.herokuapp.com but it is not working.
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.
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:
User-added image

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!