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
Preeti ShettyPreeti Shetty 

Update Task field from related contact

I need to copy a field to the Task Object from its related contact.The Contact field "Activity Conversion Days" is a number field which gets updated based on a workflow rule. I want to copy dat field to task. I have created a number field in thr Task object with the same name. I tried creating a Process but I am getting errors. Can someone please help me with this. Also this is the first time I am using Process Builder and Flows. I am attaching a screenshot of the Process and Flow I have created.

User-added imageUser-added imageUser-added imageUser-added image
Balayesu ChilakalapudiBalayesu Chilakalapudi
Instead of creating processbuilder on Task object, Create it on Contact object. After the Criteria add the action as update records.
You can access contact field for task like this
   
[Contact].Activity_Conversion_Days__c

Try like this,

User-added image

Let us know if it helps.
GauravGargGauravGarg
Hi Preeti,

I tried myself, but we cannot use Relationship field over here. The only approach which seems here is Trigger:
 
Trigger taskTrigger_AT on Task(before insert, before update){
	List<Id> conId = new List<id>();
	String Contact_prefix = Schema.SObjectType.Contact.getKeyPrefix();
	for(Task t: Trigger.new())
		if(t.whoId.startsWith(Contact_prefix)){
			conId.add(t.whoId);
		}
	Map<Id, Contact> conMap = new Map<id, Contact>([select fieldName from Contact where Id IN :conId]);
	
	for(Task t: Trigger.new()){
		if(t.whoId.startsWith(Contact_prefix) && conMap != null && conMap.size()>0 && conMap.containsKey(t.whoId)){
			t.taskFielName = conMap.containsKey(t.whoId).fieldName;
		}
	}
}


Hope This helps!!!

Thanks,

Gaurav
Skype: gaurav62990
 

Preeti ShettyPreeti Shetty
@Bala Yesu Chilakalapudi - I used the flow its working fine when i am updating a single record.. but when i update contact records in bulk using Data Loader I get the following error -
The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 3010O000000D2HA. Flow error messages: <b>An unhandled fault has occurred in this flow</b><br>An unhandled fault has occurred while processing the flow.  Please contact your system administrator for more information.  Contact your administrator for help.
Balayesu ChilakalapudiBalayesu Chilakalapudi
Add your action as Apex method,
create an invocable method like this,
 
public class updateTask{
 @invocable
public void updaterecords(Id recid){
 List<Task> tasklist=new List<Task>();
  List<Contact> contlist=[SELECT Activity_Conversion_Days__c,Id,(Select Id,taskActivityConversionDays__c from tasks) from Contact  WHERE   Id=:recid];
  for(Contact c:contlist){
         for(Task t:c.tasks){
             t.taskActivityConversionDays__c =c.Activity_Conversion_Days__c;
             tasklist.add(t);
         }
  }
   try{
​        update tasklist;
   }catch(Exception e){
      System.debug(e);
   }
}
}