You need to sign in to do that
Don't have an account?
Regarding bulk trigger
Hi all,
Could anyone help me out to turn the following code into bulk version. I'm learning bulk trigger and still feel confused. Thanks in advance.
trigger CampaignMemberRelationshipTrigger on CampaignMember (after insert, after update) {
for(CampaignMember CM : Trigger.New){
if((CM.ContactId != NULL)&&(CM.Opt_Out__c == TRUE)){
Contact con = [SELECT Id, Relationship__c FROM Contact WHERE Id =: CM.ContactId];
Campaign cam = [SELECT Id, Account__c FROM Campaign WHERE Id =: CM.CampaignId];
Relationships__c rs = [SELECT Id, Status__c, Contact__c,List_Owner__c FROM Relationships__c WHERE Id =: con.Relationship__c];
if(rs.List_Owner__c == cam.Account__c)
{
rs.Status__c = 'Opt-Out';
Update rs;
}
}
}
}
This was pretty fun.
Original Post:
Total queries: linear (3n).
Total DML: linear (n).
Suggested solution:
Total queries: constant (3).
Total DML: constant (1).
Please let me know if I messed up the translation anywhere, or if there are any bugs.
Cheers!
All Answers
This was pretty fun.
Original Post:
Total queries: linear (3n).
Total DML: linear (n).
Suggested solution:
Total queries: constant (3).
Total DML: constant (1).
Please let me know if I messed up the translation anywhere, or if there are any bugs.
Cheers!
Many thanks for your patient to answer this question.