You need to sign in to do that
Don't have an account?
Help in trigger
i have object "Place" which contain "Next Travel date" Field.
I have Other Object Contact (Standard object) contains a field "Travel date"
Both are in relationship as lookup. there is a lookup field on Place for Contact.
Now when every time place gets update. all the records in it atonce.
the field of contact has to be updated with place travel date which are related to eachother.
trigger Candidate_Update on AVTRRT__Placement__c (after update)
{
for(AVTRRT__Placement__c winv:trigger.new)
{
contact ct=[select AVTRRT__Candidate_Id__c,Candidate_Travel_Date__c from contact where RecordTypeId='012D0000000hW06' and id=:winv.AVTRRT__Contact_Candidate__c];
if(ct.Candidate_Travel_Date__c!=winv.AVTRRT_Next_Travel__c)
{
ct.Candidate_Travel_Date__c=winv.AVTRRT_Next_Travel__c;
update ct;
}
}
}
Want it to make bulkify. I have no idea on bulkyfication.
Hi,
Try the below bulkily code(You have to simply remove the SOQL and DML from a loop):
trigger Candidate_Update on AVTRRT__Placement__c (after update)
{
list<id> ids=new list<id>();
list<contact> con=new list<contact>();
for(AVTRRT__Placement__c winv:trigger.new)
{
ids.add(winv.AVTRRT__Contact_Candidate__c);
}
for(contact ct:[select AVTRRT__Candidate_Id__c,Candidate_Travel_Date__c from contact where RecordTypeId='012D0000000hW06' and id in : ids])
{
if(ct.Candidate_Travel_Date__c!=winv.AVTRRT_Next_Travel__c)
{
ct.Candidate_Travel_Date__c=winv.AVTRRT_Next_Travel__c;
con.add(ct);
}
}
update con;
}
For more details go through the link below:
http://wiki.developerforce.com/page/Apex_Code_Best_Practices
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.