You need to sign in to do that
Don't have an account?

When field A is updated, copy value from a field A of Object A to a field B in Object B.
Source Object - Activity
Source Field - FT_Emp__c
Destination Object - Account
Destination Field - Total_FTE__c
I want Total_FTE__c to be equal to FT_Emp__c when FT_Emp__c is updated. Here's the trigger I've come up with so far.
The trigger doesn't seem to work and also I'm getting an error - "Save error: Entity is not api accessible". Any guidance would be appreciated.
Thanks
Source Field - FT_Emp__c
Destination Object - Account
Destination Field - Total_FTE__c
I want Total_FTE__c to be equal to FT_Emp__c when FT_Emp__c is updated. Here's the trigger I've come up with so far.
trigger Update_employee_count_in_activity on Task (after insert, after update) { // set up lists you will need List<Account> accsToUpdate = new List<Account>(); Map<Id, Task> taskMap = new Map<Id, Task>(); // go through the list of tasks that were inserted for (Task t: Trigger.New) { taskMap.put(t.WhoId, Activity.FT_Emp__c); } if (taskMap.size() > 0) { // get all of the contacts related to the tasks accsToUpdate = [SELECT Id, Total_FTE__c FROM Account WHERE Id IN: taskMap.keySet()]; // go through the list for each contact for (Account c: accsToUpdate) { // total_fte_c should be equal to FT_Emp__c (Activity field) c.Total_FTE__c = taskMap.get(c.Id); } if (accsToUpdate.size() > 0) { update accsToUpdate; } } }
The trigger doesn't seem to work and also I'm getting an error - "Save error: Entity is not api accessible". Any guidance would be appreciated.
Thanks
taskMap.put(t.WhoId, Activity.FT_Emp__c); //key value doesn't seems to be matching to defined type.
You should define the values of map same type as it is of field "Activity.FT_Emp__c".
trigger Update_employee_count_in_activity on Task (after insert, after update) {
// set up lists you will need
List<Account> accsToUpdate = new List<Account>();
Map<Id, Task> taskMap = new Map<Id, Task>();
// go through the list of tasks that were inserted
for (Task t: Trigger.New)
{
taskMap.put(t.WhoId, t);
}
if (taskMap.size() > 0)
{
// get all of the contacts related to the tasks
accsToUpdate = [SELECT Id, Total_FTE__c
FROM Account
WHERE Id IN: taskMap.keySet()];
// go through the list for each contact
for (Account c: accsToUpdate)
{
// total_fte_c should be equal to FT_Emp__c (Activity field)
c.Total_FTE__c = taskMap.get(c.Id).FT_Emp__c;
}
if (accsToUpdate.size() > 0)
{
update accsToUpdate;
}
}
}
this could work.
Please help