You need to sign in to do that
Don't have an account?

Need to Re write the below simple trigger using "MAPS "
currently below code is working , i want to re write the same in maps !!!
//I'd like to update a boolean field " CheckMate__c " on contact to True when a specific opportunity stage is closed lost.
trigger ClosedLost on Opportunity (after insert ,after update)
{
list<contact> cont = new list<contact>();
for(opportunity opp : trigger.new)
{
if(opp.stagename == 'Closed Lost')
{
cont = [select id , name , CheckMate__c from contact where Accountid =:opp.accountid ];
for(contact c :cont)
{
c.CheckMate__c = true ;
}
update cont;
}
}
}
//I'd like to update a boolean field " CheckMate__c " on contact to True when a specific opportunity stage is closed lost.
trigger ClosedLost on Opportunity (after insert ,after update)
{
list<contact> cont = new list<contact>();
for(opportunity opp : trigger.new)
{
if(opp.stagename == 'Closed Lost')
{
cont = [select id , name , CheckMate__c from contact where Accountid =:opp.accountid ];
for(contact c :cont)
{
c.CheckMate__c = true ;
}
update cont;
}
}
}
Though I have not used map (used Set<Id>) , above code is optimized.
All Answers
Though I have not used map (used Set<Id>) , above code is optimized.
If you want to bulkify your code use the below trigger.
Let me know if you have any issues.
Mark it as best answer if it works.
Regards