• Leo Darkstar
  • NEWBIE
  • 35 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 18
    Questions
  • 24
    Replies

I am attempting to call a class with a @Future method by using Process Builder. In order to do this I believe I need to initially call a class with an @InvocableMethod to in-turn call that @Future class. I could be wrong on that.


This is my @Future class which I am trying to run :

 

public class FutureApexCallout {
@future(callout=true) 
    public static void pardotCallout(String contactId) {
        
        String returnedResponseFromPardot = Http_Utility_Pardot.pardotCreateProspect(new Set<Id> {contactId});            
        }
}


I'm having problems trying to call that class. This is what I have so far, but I know it is not correct. I'm just trying to place the Contact__c field from my current record into call out :

 

public class MakeApexCallout {

  @InvocableMethod
   public static void invokeapexcallout(list<Program_Contact_Role__c> pcr) {
     Futureapexcallout.pardotcallout(pcr[0].contact__c);
   }    
   
}


I apologize ahead of time for rudimentary question. I'm a rookie just getting to know this.


I would be very grateful for any help I can get on this.

I am calling a class with a Process Builder. There are two methods in the class. I have an @InvocableMethod in front of the first method. Do I also need one in front of the second one, or will the first one also trigger the 2nd method ? Also, the 2nd one has a @Future annotation in front of it. Is it possible to use @InvocableMethod along with a @Future annotation ? 

Here is the 2nd method of the class. I didn't include the entire class because I was hoping to keep this as simple as possible. 
 

@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. 

I'm calling a class through the Process Builder. It has two methods within it, with one having using a @Future method being used on it. I'm using the @InvocableMethod on the first method of the class in order to be able to call it from a Proc Builder. But I didn't use it on the method, and I'm not seeing that method in my debugs. At first I thought maybe it was because it had a @Future annotation on it, but I'm seeing other FutureHandlers in the debug, so I'm guessing that's not it. 

 

Do I need to use another @InvocableMethod with that method as well ? If so, is it even possible to use an @InvocableMethod on a method which already has a @Future associated with it ? 

 

Here is that method at the end of the class. I'm not including the entire class because I want to try and keep it simple, but if you think I need to include that as well I can do that. 

 

@future(callout=true) 
    public static void pardotCallout(String contactId) {
                
        String returnedResponseFromPardot = Http_Utility_Pardot.pardotCreateProspect(new Set<Id> {contactId});
        System.debug('TESTER DEBUGGER-POST-FUTURE2');        
        }

Any help you can provide will be very appreciated. 

I am attempting to call this class from a Process Builder. I apparently need to use an @InvocableMethod command with it, but I can't get it to work because I get this error : 

 

Valid invocable parameters must be List types
 

I also need to use a @Future command with it. Is that possible in this scenario ?

Here is the actual method : 

@future(callout=true)
public static void pardotCallout(String contactId) {
        String returnedResponseFromPardot = Http_Utility_Pardot.pardotCreateProspect(new Set<Id> {contactId});
              }
 

 

I am using Process Builder to call this class. Everything is running correctly in it, except it is not running the last method which I have running at the end. At first I thought it had something to do with the @Future command, but it still didn't execute even after I commented that out. Do you have any idea why that last method at the end of the class is not running ? Does it possibly have anything to do with the fact that I'm calling it with Process Builder ? Do I need an @InvocableMethod in front of that method as well ? 

 

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];
            }
            
  

            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');    
         }
}

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
	}
}
 

 

I am currently calling this class with a Process Builder. But I can't see the results of the code following the @Future statement. I've looked through debug logs as well as in the Apex Jobs list and cannot find them. Am I unable to see them run because they are following a @Future statement ? Or is it because it's a second method in a class being called by a Process Builder ? Or is there another way I need to try and see it run ? 

Should I be calling the methods individually from a trigger ?

 

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
	}
}

I'm trying to call this class which uses @Future with a trigger. I'm unsure how to reference the class in the trigger. Also, since I am attempting to trigger the code with a field change it is difficult because I can't have the callout execute after an update. So, I'm not sure what trigger context should be used as well. 

 

Here is my trigger : 

trigger Trigger_ProgramContactRole on Program_Contact_Role__c (after insert, after update, before insert, before update ,after delete) {
    //Checking for the event type
    if(Trigger.isAfter){
        
        
        if(Trigger.isInsert){
                     
                        
        }
        
        
        if(Trigger.isUpdate){
                     
            
            
        }


But I don't know how to start this class with it : 

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);                                                    

 pardotCallout(contactToBeupdate[0].Id);
    {

        @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.
    }

        if(contactToBeupdate.size() > 0){
            update contactToBeupdate;  
        }
        
        return 'Updated Successfully';
    }
}

Any help you can give would be very appreciate. Thank you.

My question is two-fold :

 

I am trying to call a Class with a Trigger upon the editing of a field value. However, that Class also has a callout, and apparently we cannot be executed when there is an uncommitted transaction. 

Here :

You have uncommitted work pending... (https://help.salesforce.com/articleView?id=000328873&type=1&mode=1)

So, I'm wondering if I am able to call this Class using a 'before update' setting in the trigger. 

If I can do that, I would need to put the necessary code into this already existing trigger for the object : 

trigger Trigger_ProgramContactRole on Program_Contact_Role__c (after insert, after update, before insert, before update ,after delete) {
    //Checking for the event type
    if(Trigger.isAfter){
        
        //Checking for the request type
        if(Trigger.isInsert){
            
            // Update Servicer on contact
            ProgramContactRoleTriggerHelper.updateServicerOnPCR(Trigger.new);
            
        }
        
        //Checking for the request type
        if(Trigger.isUpdate){
            
            // call deleteProgramContactRoleRecors
            ProgramContactRoleTriggerHelper.deleteProgramContactRoleRecors(Trigger.new);
            
        }


That would need to call this Class :

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;  
        }
        
        return 'Updated Successfully';
    }
}
    //Calling  Http_Utility_Pardot class pardotCreateProspect method for the creation of Prospect record.
    String returnedResponseFromPardot = Http_Utility_Pardot.pardotCreateProspect(new Set<Id> {contactToBeupdate[0].Id});


The Pardot callout which is causing the error is coming from the last two lines of the class. ​​​​​​​

How can this be incorporated into this trigger - and only done when a field is changed ? 

Thank you very much for any help you can give. 

I'm getting this error from a class referenced by an Email Service. From what I understand, the error is kicked off when a reference is made to a list which exceeds the number of items in the list.

 

In this case, the class is referencing the attachments included in an email. Ultimately, it intends to re-save the attachment as a file in a SF record. Here are the lines which are causing the error. I will also include the entire class later in this post :

//Set file Name
 fileName  = fileStartName+pCR.Contact__r.Name +' )';
 version = Integer.valueOf(attachment.Name.split('V1.')[1].removeEnd('.csv').isNumeric() ? attachment.Name.split('V1.')[1].removeEnd('.csv') : '0');  
                            fileName +=  '.csv';


In the debug logs the line beginning with 'version' seems to be the line causing the error.


I am confused by the code so would really appreciate any input which you can provide on why this error is happening. I do know that the code will work some times. Thank you very much.


I have included the whole class here :

global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email,Messaging.InboundEnvelope envelop)
{
    
    Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
    
    //String to hold message
    String message = '';
    String fileStartName = '';
    String fileEndName = '';
    String fileName = '';
    
    Integer version = 0;
    
    //List to hold Error log records
    List<Error_Log__c> errorLogs = new List<Error_Log__c>();
    
    //Get From Address
    String fromAddress = email.FromAddress;
    
    //Get Contact
    Contact contactRecord;
    
    List<Contact> contacts = [SELECT Id , Name , AccountId FROM Contact WHERE Email =: fromAddress ORDER BY Name DESC LIMIT 1];
    
    if(contacts.size() > 0)
        contactRecord = contacts[0];    
    
    if (email.binaryAttachments != null && email.binaryAttachments.size() > 0) 
    {
        
        //Map to hold the Funder Contact Role Details with Funder
        Map<Id, Program_Contact_Role__c> mapPCRsWithProgram = new Map<Id, Program_Contact_Role__c>();
        
        //List to hold Content versions
        List<ContentVersion> contentVersions = new List<ContentVersion>();
        
        
       for(integer i =0, s = email.binaryattachments.size(); i < s; i++) 
       {


      if(email.binaryAttachments[i].mimeTypeSubType.equals('application/vnd.ms-excel') || email.binaryAttachments[i].mimeTypeSubType.equals('text/csv') ||email.binaryAttachments[i].filename.contains('.csv')) 
       
            {

            try
            {
                System.debug('Attachment matched a criteria');
                //Get Attachment details
                List<String> attachmentSplitsByRows = new List<String>();
                
                //Insatnce of attachemnts
                Attachment attachment = new Attachment();
                
                // Get attachment name and body
                attachment.Name = email.binaryAttachments[0].filename;
                attachment.Body = email.binaryAttachments[0].body;
                
                System.debug('Attachment Body '+(attachment.Body).toString());
                
                //Convert to string
                String attachmentBody = (attachment.Body).toString();
                attachmentBody = attachmentBody.unescapeCsv();
                
                //Split the data by new line 
                attachmentSplitsByRows = attachmentBody.split('\n');
                
                //Set to hold the Onbording Ids
                Set<Id> setOnbordingIds = new Set<Id>();
                
                //Map to hold the Onbording Record
                Map<Id, Program_Onboarding__c> mapProgramOnboardings = new Map<Id, Program_Onboarding__c>();
                
                //Set to hold the Program Onbording ids to check Funder is already approved or not 
                Set<Id> setOfProgOnboardingIds = new Set<Id>();
                
                //List of Milestone to create a new Milestone
                List<Milestone__c> milestones = new List<Milestone__c>();
                
                Boolean firstRow = true;
                
                //Loop over the Attachments
                for(String csvRow : attachmentSplitsByRows)
                {
                    
                    //Skip header row
                    if(!firstRow){
                        
                        //Get the onbording details
                        List<String> attachmentSplitByColumns = csvRow.split(',');
                        
                        //Add Onbording Id in set
                        setOnbordingIds.add(attachmentSplitByColumns[0]);
                    }
                    firstRow = false;
                }
                
                firstRow = true;
                
                //Check onbordings
                if(setOnbordingIds.size() > 0) {
                    
                    //Get Onboardings
                    mapProgramOnboardings = new Map<Id, Program_Onboarding__c>([Select Id, Supplier__c, Supplier__r.Supplier__c, Funder__c, Program__c From Program_Onboarding__c Where Id IN : setOnbordingIds]);
                    
                    //Get Milestones
                    for(Milestone__c ml : [Select Id , Onboarding__c FROM Milestone__c WHERE Onboarding__c IN: setOnbordingIds AND Milestone_Type__c =: Constants.PROGRAM_MILESTONE_MILESTONE_TYPE_APPROVED_BY_FUNDER])
                        setOfProgOnboardingIds.add(ml.Onboarding__c);
                    
                    //Set to hold the Program Details
                    Set<Id> setProgramIds = new Set<Id>();
                    
                    //Loop over the Onboardings
                    for(Program_Onboarding__c pO : mapProgramOnboardings.values())
                        setProgramIds.add(pO.Program__c);
                    
                    //Set file Name
                    fileStartName = 'Response - '+attachment.Name.split('.csv')[0].trim()+' - ( ';
                    
                    //Get Funder Program Contact Role
                    for(Program_Contact_Role__c pCR : [Select Id, Program_Name__c, Funder__c , Contact__c , Contact__r.Name From Program_Contact_Role__c Where Program_Name__c IN : setProgramIds AND Contact__r.Email =: fromAddress AND RecordTypeId =: Constants.PROGCONTACTROLE_RT_ID_FUNDER]){
                        mapPCRsWithProgram.put(pCR.Program_Name__c, pCR);
                        
                        //Set file Name
                        fileName  = fileStartName+pCR.Contact__r.Name +' )';
                        version = Integer.valueOf(attachment.Name.split('V1.')[1].removeEnd('.csv').isNumeric() ? attachment.Name.split('V1.')[1].removeEnd('.csv') : '0');  
                        fileName +=  '.csv';
                                                
                        //Insert File under Program
                        // convert from string to blob
                        Blob tempBlob = attachment.Body;
                        
                        // convert base64 encode from the blob
                        string csvFile = EncodingUtil.base64Encode(tempBlob);
                        
                        //Decoding base64Data
                        String base64Data = EncodingUtil.urlDecode(csvFile, 'UTF-8');
                        
                        ContentVersion contentVersionData = new ContentVersion();
                        contentVersionData.Title = fileName;
                        contentVersionData.PathOnClient = '/' + fileName;
                        contentVersionData.FirstPublishLocationId = pCR.Program_Name__c;
                        contentVersionData.VersionData = EncodingUtil.base64Decode(base64Data);
                        contentVersionData.IsMajorVersion = true;
                        
                        //Add content version
                        contentVersions.add(contentVersionData);
                        
                    }
                    
                }
                System.debug('attachmentSplitsByRows '+attachmentSplitsByRows[0].split(',').size());
                
                if(attachmentSplitsByRows.size()>0 && attachmentSplitsByRows[0].split(',').size() > 8){
                                    
                    //Loop over the Onbording details
                    for(String csvRow : attachmentSplitsByRows){
                        
                        //Skip header row
                        if(!firstRow){
                            
                            //Get the onbording details
                            List<String> attachmentSplitByColumns = csvRow.split(',');
                            
                            //Get last column
                            Integer lastColumn = attachmentSplitByColumns.size();
                            if(attachmentSplitByColumns.size() > 8){
                                
                                //Check Approved by funder is Yes or True then update program onboarding status to 'Trading Set Up - Pending Supplier'
                                if(attachmentSplitByColumns.size() > 8 && String.isNotBlank(attachmentSplitByColumns[0]) && !setOfProgOnboardingIds.contains(attachmentSplitByColumns[0]) && (attachmentSplitByColumns[lastColumn-1].trim().equalsIgnoreCase('True') || attachmentSplitByColumns[lastColumn-1].trim().equalsIgnoreCase('Yes'))){
                                    
                                    //Update onbording
                                    mapProgramOnboardings.get(attachmentSplitByColumns[0]).Status__c = Constants.ONBOARDING_STATUS_PENDING_SUPPLIER;
                                    
                                    //Add a new Milestone
                                    milestones.add(milestone(mapProgramOnboardings.get(attachmentSplitByColumns[0]), mapPCRsWithProgram, Constants.PROGRAM_MILESTONE_MILESTONE_TYPE_APPROVED_BY_FUNDER));
                                    
                                } else if(attachmentSplitByColumns.size() > 8 && String.isNotBlank(attachmentSplitByColumns[0]) && !setOfProgOnboardingIds.contains(attachmentSplitByColumns[0]) && (attachmentSplitByColumns[lastColumn-1].trim().equalsIgnoreCase('False') || attachmentSplitByColumns[lastColumn-1].trim().equalsIgnoreCase('No'))){
                                    
                                    //Update onbording
                                    mapProgramOnboardings.get(attachmentSplitByColumns[0]).Status__c = Constants.ONBOARDING_STATUS_BUYER_REVIEW;
                                    
                                    //Add a new Milestone
                                    milestones.add(milestone(mapProgramOnboardings.get(attachmentSplitByColumns[0]), mapPCRsWithProgram, Constants.PROGRAM_MILESTONE_MILESTONE_TYPE_BUYER_REVIEW_REQUESTED));
                                    
                                }else if(setOfProgOnboardingIds.contains(attachmentSplitByColumns[0])){
                                    
                                    message = 'Funder File is already processed.';
                                    
                                    if(mapProgramOnboardings.containsKey(attachmentSplitByColumns[0])){                              
                                        
                                        //Add error Log
                                        errorLogs.add(errorLog(mapProgramOnboardings.get(attachmentSplitByColumns[0]) , message , contactRecord));
                                    }
                                }else if(attachmentSplitByColumns.size() > 8 && (!attachmentSplitByColumns[lastColumn-1].trim().equalsIgnoreCase('Yes') || !attachmentSplitByColumns[lastColumn-1].trim().equalsIgnoreCase('No'))){
                                    message = 'Funder replies back with '+attachmentSplitByColumns[lastColumn-1].trim()+' instead of Yes or No.';
                                    
                                    //Add error Log
                                    errorLogs.add(errorLog(mapProgramOnboardings.get(attachmentSplitByColumns[0]) , message , contactRecord));

                                }
                            }else{
                                    message = 'Funder replies back with blank value instead of Yes or No.';
                                    
                                    //Add error Log
                                    errorLogs.add(errorLog(mapProgramOnboardings.get(attachmentSplitByColumns[0]) , message , contactRecord));
                            }
                        }
                        firstRow = false;
                    }
                }else{
                    
                    message = 'Funder file formate is not correct , please check funder file.';
                    
                    //Add Error log
                    errorLogs.add(errorLog(null , message , contactRecord));
                    
                }
                
                //check size
                if(mapProgramOnboardings.size() > 0)
                    update mapProgramOnboardings.values();
                
                //Check milestone list
                if(milestones.size() > 0)
                    insert milestones;
                
                //Check content versions
                if(contentVersions.size() >0)
                    insert contentVersions;
            
            }catch(Exception ex){

Thank you.

I am attempting to start this Apex class with Process Builder, triggered by a field change. I've never done this before and I'm unsure what invoke code needs to be added in order to accomplish this. I tried adding @InvocableMethod but I'm getting an error telling me this :

 

Compile Error: Unsupported parameter type String. 
Valid invocable parameters must be List types like List<T> 
where T is a supported type at line 26 column 27

It is a class which is currently being invoked with a Lightning Component button in a record.

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;  
        }
        
        return 'Updated Successfully';
    }
}

Thank you very much for any help you can give with this. It is very appreciated.

Apparently we are unable to use the Owner as the From value in an Email Alert. Is there no workaround for this ? I don't want to use the org default or any other hard coded email address. 

 

Our users currently use the Email part of Activities to create and send an email which in turn also becomes an Email Message record and appears in the Activities History section of that record. We are now automating that email and the users will no longer be creating it. How do I make that new automated email appear in the Activities History section ? Do I somehow automatically create a new Email Message record ?

I've made a action button to call a Component in order to clone a record. The component basically takes a bunch of values from the current record and maps them to the new record. I'm also trying to populate a checkbox field to TRUE (or 1). But I'm having trouble populating the field.


Here is the Component :

<aura:component controller="CloneOpp" implements="force:lightningQuickActionWithoutHeader,lightning:actionOverride,force:hasRecordId">
    <ltng:require styles="/resource/SLDS202/assets/styles/salesforce-lightning-design-system.css"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="oppName" type="String" />
    <aura:attribute name="typePick" type="String" />
    <aura:attribute name="campaign" type="String" />
    <aura:attribute name="clone" type="boolean" />
  
     <aura:dependency resource="c:createRecord"/>
    <!-- Load the navigation events in the force namespace. -->
    <aura:dependency resource="markup://force:*" type="EVENT"/>
    
    
</aura:component>


Here is the Helper of the component :

({
        queryOpp: function(component,  event, helper) {
        //var self = this;  
        var recordId = component.get("v.recordId");
            if(recordId!=undefined){
            
            
            alert(recordId);
            var action = component.get("c.getDetailsFromOpp");
            action.setParams({
                recordId: recordId
            });
            action.setCallback(this, function(response){
                var state = response.getState();
               
                if (state === "SUCCESS") {
                    var opp = response.getReturnValue();
                    component.set("v.oppName", opp.Name); 
                    component.set("v.campaign", opp.CampaignId);
                   
                    helper.createOppRecord(component, event, helper);
                  
                }
               
            });
            
            $A.enqueueAction(action);
            }
        },
         createOppRecord : function (component, event, helper) {
           var name=  component.get("v.oppName"); 
           var campaign=  component.get("v.campaign");
           var clone= 1; 
        var createOpportunityEvent = $A.get("e.force:createRecord");
        createOpportunityEvent.setParams({
        "entityApiName": "Opportunity",
        "defaultFieldValues": {
            'Name' : 'New Opp',
            'CampaignId' : campaign,
            'Clone__c' : clone,   
            }
        });
        createOpportunityEvent.fire();
        },
        
    })


All I want to do is have the Clone__c field set to 1 or TRUE.


Thank you for any help.

In the Connected App there is an Initial Access Token and a Generate button for it.


The description for the field is as such :

Generate an initial access token for an org’s parent OAuth 2.0 client app. 
Salesforce requires this token to authenticate the client app’s request 
at the dynamic client registration endpoint.


In the online documenation this is written about that token :

After generating the initial access token, register it 
with your external API gateway.

How\where do I "register" that access token ?
Here is the full documenation I am referencing :

Generate an Initial Access Token (https://help.salesforce.com/articleView?id=remoteaccess_oidc_initial_access_token.htm&type=5)

Thank you for any input you can provide.

I am having problems properly setting up a Connected App for a sandbox. I've got the Connected App working in Production. With that configuration I have the API Host listed as such in the login configuration :

 

MYDOMAIN.my.salesforce.com/services/Soap/c/24.0/ORGID


And that's working - even though my API is 49.0 (not 24.0) in that URL.


But I can't get the external login to work for a sandbox. I'm not sure what the API Host should be in the login configuration for a sandbox.


I've tried this :

MYDOMAIN--NAMEOFSANDBOX.LOCATION.my.salesforce.com/SANDBOXORGID
 

But is there another URL that should be used for a sandbox ? Should it have 'test' in the URL or something else ? Should the MYDOMAIN not even be in it ? Does SOAP need to be in it ? Do I need the sandbox ORG ID at the end ?


Thank you for any help you can give on this.

Needless to say, this is my first venture into Components.....

 

I'm attempting to use this to create a clone of an Opp. It's set map over two fields. But I can't get it to work. It will only produce a blank square dialog box when the action is used.
Here are the different pieces.


Component :
 

<aura:component controller="CloneOpp" implements="force:lightningQuickActionWithoutHeader,lightning:actionOverride">
    <ltng:require styles="/resource/SLDS202/assets/styles/salesforce-lightning-design-system.css"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="oppName" type="String" />
    <aura:attribute name="typePick" type="String" />
    <aura:attribute name="campaign" type="String" />
  
     <aura:dependency resource="c:createRecord"/>
    <!-- Load the navigation events in the force namespace. -->
    <aura:dependency resource="markup://force:*" type="EVENT"/>
    
    
</aura:component>
 

Controller : 

({
     doInit: function(component, event, helper) {
      //call the helper function with pass [component, Controller field and Dependent Field] Api name 
     // alert('Hi');
      helper.queryOpp(component, event, helper);
   },
   
})
 

Helper : 

({
    queryOpp: function(component,  event, helper) {
      var recordId = component.get("v.recordId");
        if(recordId!=undefined){
        
        
        alert(recordId);
        var action = component.get("c.getDetailsFromOpp");
        action.setParams({
            recordId: recordId
        });
        action.setCallback(this, function(response){
            var state = response.getState();
           
            if (state === "SUCCESS") {
                var opp = response.getReturnValue();
                component.set("v.oppName", opp.Name); 
                component.set("v.typePick", opp.pcikListTest__c);
                component.set("v.campaign", opp.CampaignId);
               
                helper.createOppRecord(component, event, helper);
              
            }
           
        });
        
        $A.enqueueAction(action);
        }
    },
     createOppRecord : function (component, event, helper) {
       var name=  component.get("v.Name"); 
       var picklist = component.get("v.typePick"); 
        var campaign=  component.get("v.campaign");
        // alert(picklist);
       //  alert(campaign);
    var createOpportunityEvent = $A.get("e.force:createRecord");
    createOpportunityEvent.setParams({
    "entityApiName": "Opportunity",
    "defaultFieldValues": {
        'Name' : 'New Opp',
        'Type' : 'Existing Customer - Upgrade',
        'pcikListTest__c' : picklist,
        'CampaignId' : campaign
        }
    });
    createOpportunityEvent.fire();
    },
    
})
 

Class :

public class CloneOpp {
 @AuraEnabled 
    public static Opportunity getDetailsFromOpp(string recordId){
       Opportunity opp = [select Id,Name,CampaignId,TrackingNumber__c,pcikListTest__c
        from Opportunity Where Id = :recordId limit 1];
       return opp ;
    }

}
 

Does anything stand out as out of place ? Any help you can give would be appreciated.


Thank you.

I am attempting to parse out the values from attachments in emails which are coming in through Email Service. However, some emails have other attachments in them which are not UTF-8 format (sometimes they're graphics files in an email signature). So the code will error when attempting to scan those files. So I'm trying to skip over the files whose content type is not text-based. 
 
I am getting this error when attempting to save it : 

"variable does not exist : contentType"

This is an early portion of my code
 
if (email.binaryAttachments != null && email.binaryAttachments.size() > 0) 
        {
                       
            Map<Id, Program_Contact_Role__c> mapPCRsWithProgram = new Map<Id, Program_Contact_Role__c>();
            
            //List to hold Content versions
            List<ContentVersion> contentVersions = new List<ContentVersion>();
                        
           for(integer i =0, s = email.binaryattachments.size(); i < s; i++) 
           {

            if(email.binaryAttachments[i].contentType.startsWith('text/')) 
                {

                try
                {
                
                    //Get Attachment details
                    List<String> attachmentSplitsByRows = new List<String>();
                    
                    //Insatnce of attachemnts
                    Attachment attachment = new Attachment();
                    
                    // Get attachment name and body
                    attachment.Name = email.binaryAttachments[0].filename;
                    attachment.Body = email.binaryAttachments[0].body;

Thank you for any help you can provide. 

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
	}
}
 

 

I'm trying to call this class which uses @Future with a trigger. I'm unsure how to reference the class in the trigger. Also, since I am attempting to trigger the code with a field change it is difficult because I can't have the callout execute after an update. So, I'm not sure what trigger context should be used as well. 

 

Here is my trigger : 

trigger Trigger_ProgramContactRole on Program_Contact_Role__c (after insert, after update, before insert, before update ,after delete) {
    //Checking for the event type
    if(Trigger.isAfter){
        
        
        if(Trigger.isInsert){
                     
                        
        }
        
        
        if(Trigger.isUpdate){
                     
            
            
        }


But I don't know how to start this class with it : 

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);                                                    

 pardotCallout(contactToBeupdate[0].Id);
    {

        @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.
    }

        if(contactToBeupdate.size() > 0){
            update contactToBeupdate;  
        }
        
        return 'Updated Successfully';
    }
}

Any help you can give would be very appreciate. Thank you.

My question is two-fold :

 

I am trying to call a Class with a Trigger upon the editing of a field value. However, that Class also has a callout, and apparently we cannot be executed when there is an uncommitted transaction. 

Here :

You have uncommitted work pending... (https://help.salesforce.com/articleView?id=000328873&type=1&mode=1)

So, I'm wondering if I am able to call this Class using a 'before update' setting in the trigger. 

If I can do that, I would need to put the necessary code into this already existing trigger for the object : 

trigger Trigger_ProgramContactRole on Program_Contact_Role__c (after insert, after update, before insert, before update ,after delete) {
    //Checking for the event type
    if(Trigger.isAfter){
        
        //Checking for the request type
        if(Trigger.isInsert){
            
            // Update Servicer on contact
            ProgramContactRoleTriggerHelper.updateServicerOnPCR(Trigger.new);
            
        }
        
        //Checking for the request type
        if(Trigger.isUpdate){
            
            // call deleteProgramContactRoleRecors
            ProgramContactRoleTriggerHelper.deleteProgramContactRoleRecors(Trigger.new);
            
        }


That would need to call this Class :

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;  
        }
        
        return 'Updated Successfully';
    }
}
    //Calling  Http_Utility_Pardot class pardotCreateProspect method for the creation of Prospect record.
    String returnedResponseFromPardot = Http_Utility_Pardot.pardotCreateProspect(new Set<Id> {contactToBeupdate[0].Id});


The Pardot callout which is causing the error is coming from the last two lines of the class. ​​​​​​​

How can this be incorporated into this trigger - and only done when a field is changed ? 

Thank you very much for any help you can give. 

I am attempting to start this Apex class with Process Builder, triggered by a field change. I've never done this before and I'm unsure what invoke code needs to be added in order to accomplish this. I tried adding @InvocableMethod but I'm getting an error telling me this :

 

Compile Error: Unsupported parameter type String. 
Valid invocable parameters must be List types like List<T> 
where T is a supported type at line 26 column 27

It is a class which is currently being invoked with a Lightning Component button in a record.

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;  
        }
        
        return 'Updated Successfully';
    }
}

Thank you very much for any help you can give with this. It is very appreciated.
Our users currently use the Email part of Activities to create and send an email which in turn also becomes an Email Message record and appears in the Activities History section of that record. We are now automating that email and the users will no longer be creating it. How do I make that new automated email appear in the Activities History section ? Do I somehow automatically create a new Email Message record ?

I've made a action button to call a Component in order to clone a record. The component basically takes a bunch of values from the current record and maps them to the new record. I'm also trying to populate a checkbox field to TRUE (or 1). But I'm having trouble populating the field.


Here is the Component :

<aura:component controller="CloneOpp" implements="force:lightningQuickActionWithoutHeader,lightning:actionOverride,force:hasRecordId">
    <ltng:require styles="/resource/SLDS202/assets/styles/salesforce-lightning-design-system.css"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="oppName" type="String" />
    <aura:attribute name="typePick" type="String" />
    <aura:attribute name="campaign" type="String" />
    <aura:attribute name="clone" type="boolean" />
  
     <aura:dependency resource="c:createRecord"/>
    <!-- Load the navigation events in the force namespace. -->
    <aura:dependency resource="markup://force:*" type="EVENT"/>
    
    
</aura:component>


Here is the Helper of the component :

({
        queryOpp: function(component,  event, helper) {
        //var self = this;  
        var recordId = component.get("v.recordId");
            if(recordId!=undefined){
            
            
            alert(recordId);
            var action = component.get("c.getDetailsFromOpp");
            action.setParams({
                recordId: recordId
            });
            action.setCallback(this, function(response){
                var state = response.getState();
               
                if (state === "SUCCESS") {
                    var opp = response.getReturnValue();
                    component.set("v.oppName", opp.Name); 
                    component.set("v.campaign", opp.CampaignId);
                   
                    helper.createOppRecord(component, event, helper);
                  
                }
               
            });
            
            $A.enqueueAction(action);
            }
        },
         createOppRecord : function (component, event, helper) {
           var name=  component.get("v.oppName"); 
           var campaign=  component.get("v.campaign");
           var clone= 1; 
        var createOpportunityEvent = $A.get("e.force:createRecord");
        createOpportunityEvent.setParams({
        "entityApiName": "Opportunity",
        "defaultFieldValues": {
            'Name' : 'New Opp',
            'CampaignId' : campaign,
            'Clone__c' : clone,   
            }
        });
        createOpportunityEvent.fire();
        },
        
    })


All I want to do is have the Clone__c field set to 1 or TRUE.


Thank you for any help.

In the Connected App there is an Initial Access Token and a Generate button for it.


The description for the field is as such :

Generate an initial access token for an org’s parent OAuth 2.0 client app. 
Salesforce requires this token to authenticate the client app’s request 
at the dynamic client registration endpoint.


In the online documenation this is written about that token :

After generating the initial access token, register it 
with your external API gateway.

How\where do I "register" that access token ?
Here is the full documenation I am referencing :

Generate an Initial Access Token (https://help.salesforce.com/articleView?id=remoteaccess_oidc_initial_access_token.htm&type=5)

Thank you for any input you can provide.

Needless to say, this is my first venture into Components.....

 

I'm attempting to use this to create a clone of an Opp. It's set map over two fields. But I can't get it to work. It will only produce a blank square dialog box when the action is used.
Here are the different pieces.


Component :
 

<aura:component controller="CloneOpp" implements="force:lightningQuickActionWithoutHeader,lightning:actionOverride">
    <ltng:require styles="/resource/SLDS202/assets/styles/salesforce-lightning-design-system.css"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="oppName" type="String" />
    <aura:attribute name="typePick" type="String" />
    <aura:attribute name="campaign" type="String" />
  
     <aura:dependency resource="c:createRecord"/>
    <!-- Load the navigation events in the force namespace. -->
    <aura:dependency resource="markup://force:*" type="EVENT"/>
    
    
</aura:component>
 

Controller : 

({
     doInit: function(component, event, helper) {
      //call the helper function with pass [component, Controller field and Dependent Field] Api name 
     // alert('Hi');
      helper.queryOpp(component, event, helper);
   },
   
})
 

Helper : 

({
    queryOpp: function(component,  event, helper) {
      var recordId = component.get("v.recordId");
        if(recordId!=undefined){
        
        
        alert(recordId);
        var action = component.get("c.getDetailsFromOpp");
        action.setParams({
            recordId: recordId
        });
        action.setCallback(this, function(response){
            var state = response.getState();
           
            if (state === "SUCCESS") {
                var opp = response.getReturnValue();
                component.set("v.oppName", opp.Name); 
                component.set("v.typePick", opp.pcikListTest__c);
                component.set("v.campaign", opp.CampaignId);
               
                helper.createOppRecord(component, event, helper);
              
            }
           
        });
        
        $A.enqueueAction(action);
        }
    },
     createOppRecord : function (component, event, helper) {
       var name=  component.get("v.Name"); 
       var picklist = component.get("v.typePick"); 
        var campaign=  component.get("v.campaign");
        // alert(picklist);
       //  alert(campaign);
    var createOpportunityEvent = $A.get("e.force:createRecord");
    createOpportunityEvent.setParams({
    "entityApiName": "Opportunity",
    "defaultFieldValues": {
        'Name' : 'New Opp',
        'Type' : 'Existing Customer - Upgrade',
        'pcikListTest__c' : picklist,
        'CampaignId' : campaign
        }
    });
    createOpportunityEvent.fire();
    },
    
})
 

Class :

public class CloneOpp {
 @AuraEnabled 
    public static Opportunity getDetailsFromOpp(string recordId){
       Opportunity opp = [select Id,Name,CampaignId,TrackingNumber__c,pcikListTest__c
        from Opportunity Where Id = :recordId limit 1];
       return opp ;
    }

}
 

Does anything stand out as out of place ? Any help you can give would be appreciated.


Thank you.