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
Leo DarkstarLeo Darkstar 

How to see Future activities in logs ?

I am attempting to see the portion of this code which is part of the @Future method run in logs. But I don't see it in the Debug Logs. Shouldn't it be showing up with a Future Handler label ? Is there a different user I need to track in order to see Future Handler logs ? I also can't find it in the Apex Jobs.

 

I really just want to verify that the @Future code is actually being run. 

 

...or is just not being run ? 

public class UpdateContactPCRController {

    @InvocableMethod
    public static String  updateContact(String recordId){        
       
        String contactId = '';       
        
        List<Contact> contactToBeupdate = new List<Contact>();        
        
        if(String.isNotBlank(recordId)){            
            
            List<Program_Contact_Role__c> programContacList = [SELECT Id,Contact__c,Program_Name__c FROM Program_Contact_Role__c WHERE Id =:recordId AND Contact__c != null];
            contactId = programContacList[0].Contact__c;
            
            if(String.isNotBlank(contactId)){
                
                contactToBeupdate = [Select Id,Pardot_Action_Trigger__c,PCR_Register_Button_Link__c,PCR_URL_for_UI__c FROM Contact Where Id =: contactId Limit 1];                
                
                contactToBeupdate[0].Program_Contact_Role_Id__c = recordId;
            }
			List<Program_Communication_Recipients__c> programCommunicationRecs = [Select Id,Name,
					  Program_Communication__r.Program__r.Buyer__r.Name,Receipient__c,                
								  From Program_Communication_Recipients__c Where 
											   Program_Communication__r.Program__c =: programContacList[0].Program_Name__c AND 
											   Receipient__c =: programContacList[0].Id];                                           
					
	
			contactToBeupdate[0].PCR_Welcome_Message__c = String.valueOf(programCommunicationRecs[0].Program_Communication__r.Welcome_Message__c);                                                    
			
			if(contactToBeupdate.size() > 0){
				update contactToBeupdate;  
			}
			pardotCallout(contactToBeupdate[0].Id);
    
			return 'Updated Successfully';
		}
		else{
			return 'some message';
		}
    }
	
	@future(callout=true) 
	public static void pardotCallout(String contactId) {
		String returnedResponseFromPardot = Http_Utility_Pardot.pardotCreateProspect(new Set<Id> {contactId});
		// new treatment here with the returned value included DML operations.
		// further logic if any based on the response you get from Pardot
	}
}
 

 

VinayVinay (Salesforce Developers) 
Hi Leo,

Future methods can be debugged in two ways. First, you can open the developer console and perform the action that causes the future method to be called. Second, you can enable debug logs in Setup / Monitoring / Debug Logs.

If you do not see anything in logs then you can confirm your method is not being invoked.

Reference:
https://salesforce.stackexchange.com/questions/200920/why-do-debug-logs-not-always-work-for-a-future-method
https://salesforce.stackexchange.com/questions/76893/debug-or-view-status-of-a-future-method/76894

Thanks,
Leo DarkstarLeo Darkstar

Vinay, 

 

That first reference you gave seems to be the same type of case as me. It sounds like he was able to see FutureHandler in the Logs portion of DeveloperConsole. But I'm not sure how to run this code in DeveloperConsole because it would require a field change to initiate. So is there a way for me to see FutureHandler in the Debug Log ? I am currently tracking my test user in there. Can I track a different type of 'system' user in order to see Future Handler operations in the Debug Log ? I also don't see it in Apex Job. Thank you very much.  

VinayVinay (Salesforce Developers) 
Would suggest you find the required fields and try to execute from developer console with required fields so that can help you to narrow down the issue.

Thanks,
Leo DarkstarLeo Darkstar

I've now gotten other Future Handler operatons to show up on my Debug Log. But I still can't see a Future Handler for the @future I have in this particular class. I've never run code which required field input through the Developer Console before. This is the full class. Do I have any reason to think that the @Future code at the end of the class is not executing ? 

 

public class UpdateContactPCRController_SELECTED {


    @InvocableMethod
    public static List<String> updateContact(List<String> recordId){ 
        
        //Variable to hold the contact Id
        String contactId = '';
        
        //List ot update contact
        List<Contact> contactToBeupdate = new List<Contact>();
        

        if(recordId.size()> 0){  
            
            //Get Program Contact Role
            //List<Program_Contact_Role__c> programContacList = [SELECT Id,Contact__c,Program_Name__c FROM Program_Contact_Role__c WHERE Id =:recordId AND Contact__c != null];
            //SELECTED
            List<Program_Contact_Role__c> programContacList = [SELECT Id,Contact__c,Program_Name__c FROM Program_Contact_Role__c WHERE Id =:recordId[0] AND Contact__c != null];
            System.debug(recordId[0]);
    
            //if(programContacList.size() > 0)
                contactId = programContacList[0].Contact__c;
                
            
            if(String.isNotBlank(contactId)){
                
                contactToBeupdate = [Select Id,Pardot_Action_Trigger__c,PCR_Register_Button_Link__c,PCR_URL_for_UI__c FROM Contact Where Id =: contactId Limit 1];
                
                contactToBeupdate[0].Pardot_Action_Trigger__c = 'Send Welcome Email';                contactToBeupdate[0].Program_Contact_Role_Id__c = recordId[0];
            }
            
Added new custom fileds From_Email__c, Reply_to_Email__c in query  

            List<Program_Communication_Recipients__c> programCommunicationRecs = [Select Id,Name,Program_Communication__r.Welcome_Message__c,
                                                                                         Program_Communication__r.Program__r.Buyer__r.Name,Receipient__c,
                                                                                         Program_Communication__r.Program__r.Buyer__r.Account_Name_for_Communications__c,
                                                                                         Program_Communication__r.Logo_Public_Url__c ,Welcome_Page_with_IDs__c, 
                                                                                         Program_Communication__r.URL_for_UI__c ,Program_Communication__r.Learn_More_link__c,
                                                                                         Program_Communication__r.Reply_to_Email__c,Program_Communication__r.From_Email__c                
                                                                                         From Program_Communication_Recipients__c Where 
                                                                                         Program_Communication__r.Program__c =: programContacList[0].Program_Name__c AND 
                                                                                         Receipient__c =: programContacList[0].Id];
                                                   
            
            if(programCommunicationRecs.size() > 0){
                
                if(String.isNotBlank(programCommunicationRecs[0].Welcome_Page_with_IDs__c))
                    contactToBeupdate[0].PCR_Register_Button_Link__c = programCommunicationRecs[0].Welcome_Page_with_IDs__c;
                
                
                
                if(String.isNotBlank(programCommunicationRecs[0].Program_Communication__r.Learn_More_link__c))
                            contactToBeupdate[0].PCR_Learn_More_Link__c = programCommunicationRecs[0].Program_Communication__r.Learn_More_link__c;
                        
                if(String.isNotBlank(programCommunicationRecs[0].Program_Communication__r.URL_for_UI__c))
                    contactToBeupdate[0].PCR_URL_for_UI__c = programCommunicationRecs[0].Program_Communication__r.URL_for_UI__c;
                    

               
               if(String.isNotBlank(programCommunicationRecs[0].Program_Communication__r.Program__r.Buyer__r.Account_Name_for_Communications__c))
                    contactToBeupdate[0].PCR_Buyer_Name__c = programCommunicationRecs[0].Program_Communication__r.Program__r.Buyer__r.Account_Name_for_Communications__c;
               if(String.isBlank(programCommunicationRecs[0].Program_Communication__r.Program__r.Buyer__r.Account_Name_for_Communications__c))
                    contactToBeupdate[0].PCR_Buyer_Name__c = programCommunicationRecs[0].Program_Communication__r.Program__r.Buyer__r.Name;
               //END CHANGE
                
                if(String.isNotBlank(programCommunicationRecs[0].Program_Communication__r.Welcome_Message__c) && String.valueOf(programCommunicationRecs[0].Program_Communication__r.Welcome_Message__c).length()> 254)
                    contactToBeupdate[0].PCR_Welcome_Message__c = String.valueOf(programCommunicationRecs[0].Program_Communication__r.Welcome_Message__c).substring(0, 254);
                else 
                    contactToBeupdate[0].PCR_Welcome_Message__c = String.valueOf(programCommunicationRecs[0].Program_Communication__r.Welcome_Message__c);
                
                contactToBeupdate[0].PCR_Buyer_Logo_Url__c = programCommunicationRecs[0].Program_Communication__r.Logo_Public_Url__c;
                
                 
                contactToBeupdate[0].From_Email__c = programCommunicationRecs[0].Program_Communication__r.From_Email__c;
                contactToBeupdate[0].Reply_to_Email__c = programCommunicationRecs[0].Program_Communication__r.Reply_to_Email__c;
            }
        }

        
System.debug('TESTER DEBUGGER1');
        if(contactToBeupdate.size() > 0){
            update contactToBeupdate;  
        }
        

        List<String> response = new List<String>();
        System.debug('TESTER DEBUGGER2');
        response.add('Updated Successfully');
        System.debug('TESTER DEBUGGER-PRE-FUTURE');
        return response;
        
    }
   
    @future(callout=true) 
    public static void pardotCallout(String contactId) {
        String returnedResponseFromPardot = Http_Utility_Pardot.pardotCreateProspect(new Set<Id> {contactId});
        System.debug('TESTER DEBUGGER-POST-FUTURE');

    }
}

Thank you for any help you can give.