You need to sign in to do that
Don't have an account?
CKR
Need help on the following trigger
Hi EveryOne,
I am a newbee, trying to cover the triggers topic, i am facing a prolem to finishing off writting the following trigger,Could someone help me with this,
I have a master Object Client__c and its child project__c,
1) On after Insert event a child record has to be created and i am successfull till here,
Now the problem is i have similar fields in both master and child objects Start_Date__c and End_Date__c (Date fields), i am unable to pop the same values of master record fields in the child record on after insert event.
2) On after Update The requirement is similar to after insert but the only difference is this has to be happend only on update event
Please refere to the If statement in the code,i am trying to make both events of this trigger work only on that particular condition.
The Error Message that i am seeing on after update even:
I am a newbee, trying to cover the triggers topic, i am facing a prolem to finishing off writting the following trigger,Could someone help me with this,
I have a master Object Client__c and its child project__c,
1) On after Insert event a child record has to be created and i am successfull till here,
Now the problem is i have similar fields in both master and child objects Start_Date__c and End_Date__c (Date fields), i am unable to pop the same values of master record fields in the child record on after insert event.
2) On after Update The requirement is similar to after insert but the only difference is this has to be happend only on update event
Please refere to the If statement in the code,i am trying to make both events of this trigger work only on that particular condition.
trigger AutoProjects on Client__c (After insert,After update){ if(Trigger.isafter){ if (trigger.Isinsert){ List <Project__c> NewProjs= new List <Project__c> (); for(client__c Clnt:trigger.new) { if (Clnt.High_Priority__c == true){ Project__c p=new project__c(); p.Name=Clnt.Name; // p.Start_date__c='Clnt.Start_date__c' ; // Field value has to be same as Start_date__c of master record // p.End_Date__c = 'Clnt.End_Date__c' ; // Field value has to be same as End_Date__c of master record p.Client_Type__c='Silver'; p.Location__c = Clnt.Location__c; p.Client__c= clnt.Id; //Master-detail relationship name NewProjs.add(p); } } if (NewProjs.size()>0){ Insert NewProjs; } } } if(Trigger.isafter){ if (trigger.IsUpdate){ List <Project__c> NewProjs= new List <Project__c> (); for(client__c Clnt:trigger.new) { if (Clnt.High_Priority__c == true){ Project__c p=new project__c(); p.Name=Clnt.Name; // p.Start_date__c='Clnt.Start_date__c' ; // Field value has to be same as Start_date__c of master record // p.End_Date__c = 'Clnt.End_Date__c' ; // Field value has to be same as End_Date__c of master record p.Client_Type__c='Silver'; p.Location__c = Clnt.Location__c; p.Client__c= clnt.Id; //Master-detail relationship name NewProjs.add(p); } } if (NewProjs.size()>0){ Update NewProjs; } } } }
The Error Message that i am seeing on after update even:
Let us know if this will help you. else please post your error
Thanks
Amit Chaudhary
All Answers
Thanks,
Amit Chaudhary
Let us know if this will help you. else please post your error
Thanks
Amit Chaudhary