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
jpatrickpatrick76jpatrickpatrick76 

Copy New Activity From Parent Account to all Child Accounts

I have a client who would like the ability to create one activity at the parent account level and copy it to all child accounts associated with that Parent.

 

For Instance:  The company brings on all Chic-fil-a's in Wachington DC metro) .  They want to create an activity to:  Call Manager and Discuss Marketing Plan and copy it across the Child Accounts which might be Chicfila - Chantilly, Chic-fil-a Reston, Chic-fila-Ashburn etc. 

 

I thought a custom button on the parent account page with some sort of apex trigger would work in this scenario...any ideas on how to make this work?  I'm an admin, not a developer.  I believe I have exhausted all of the native functionality option with no clear path forward.

Andy BoettcherAndy Boettcher

Questions to formulate a proper approach:

 

1)  Do you want this to be a button on the Parent Account that you hit to spin these activities up?

 

2)  Do you want this to be a checkbox on the new Activity screen that says something like "Copy to all Contacts"?

 

-Andy

jpatrickpatrick76jpatrickpatrick76

Actually, I like the suggestion of a checkbox at the activity level.  How hard is this to do?

WorkhardWorkhard

Hi,

You have to write a trigger on task and event for thsi. So when ever a new activity is created on parent account automaticaly new activity is created on child records. Try the below code and apex class( for handling recursive call)Trigger is not for bulk handling so make changes accordingly.

 

trigger ParentToChildActivity on task(after insert)
{
    String str = Trigger.new[0].whatId;
    list<Task> tsk=new list<Task>();
    if(str != null)
    {
            str  = str.substring(0,3);
    }
    if(str =='001' & FollowUpTaskHelper.hasAlreadyCreatedFollowUpTasks()== false)
    {
        system.debug('@@@@@@@@@@@@@@@@@'+trigger.new[0].id);
        for(account ac:[select id from account where parentid =: trigger.new[0].whatid])
        {
            system.debug('@@@@@@@@@@@@@@@@@');
            task t=new task(whatid=ac.id,ownerId =trigger.new[0].ownerid,Subject = trigger.new[0].Subject,ActivityDate = trigger.new[0].activitydate,Status = 'Not Started');    
            tsk.add(t);
        }
        FollowUpTaskHelper.setAlreadyCreatedFollowUpTasks();
        insert tsk;
    }
}

 

//////////////////   Calss for handling recusive call //////////////////////////////

public class FollowUpTaskHelper {

   

    private static boolean alreadyCreatedTasks = false;


    public static boolean hasAlreadyCreatedFollowUpTasks() {
        return alreadyCreatedTasks;
    }

  
    
    public static void setAlreadyCreatedFollowUpTasks() {
        alreadyCreatedTasks = true;
    }

    

}

jpatrickpatrick76jpatrickpatrick76

I will give this a shot.