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
streetstreet 

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.

Navatar_DbSupNavatar_DbSup

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.