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
Jessica HousemanJessica Houseman 

Update Child Record date from change on Parent Record Date

I am using the application "Milestones PM" and when the project start date is updated on the Parent record I need the child records (milstones, tasks) dates to update accordingly. 

Example: Project start date changed to 4/9/2011 and Task #1's due date equals (Project Start date + 3) how can I get this to filter down?

Workflow obviously does not work or filter down so I guess I need a trigger but I do not know where to start...  

Ramu_SFDCRamu_SFDC
Hi Jessica,

Below is the sample code that I tested for a sample custom object 'travel__c'. Travel__c has a date field with the name 'Start_date__c'. The below trigger updates the related tasks(if any) due dates for the corresponding travel record by 3 days after an update event on Travel__c;


trigger traveltaskcreateupdate on travel__c (after update) {
    set<id> ids=new set<id>();
    for(travel__c travel:trigger.new){
        ids.add(travel.Id);
    }
    list<task> taskstoupdate=new list<task>();
   List<task> task1=new List<task>([select id,activitydate,whatid from task where whatid=:ids]);
   map<id,travel__c> travelmap=new map<id,travel__C>([select id,start_date__c from travel__c where id=:ids]);
    for(task task2:task1){
        if(travelmap.containskey(task2.WhatId)){
            if(travelmap.get(task2.WhatId).start_date__c!=null){
            task2.ActivityDate=travelmap.get(task2.WhatId).start_date__c+3;
            taskstoupdate.add(task2);
        }
        }
    } 
    update taskstoupdate;
}


In the above code I did not add the logic to process the trigger only when the start date is changed which you can do by following the guidelines as per the below post
http://salesforce.stackexchange.com/questions/11191/just-update-when-a-specific-field-changes

Hope this helps!!