Sunday, February 21, 2021

Opportunity StageName is changed then change Account Rating to Hot

Requirement: When ever Opportunity stageName is changed to 'Closed Won' then update the Account Rating to 'HOT'. First we have to set the id with AccountId. Then we should query the records. Then we have to give condition in(if Statement) Then we have to update the acclist. =====================================================================
trigger OpportunityHandler  on  opportunity(after insert,after update)
{
    set<id> setid=new set<id>();
    list<Account>   acclist=new list<Account>();
    for(opportunity opp:trigger.new)
    {
        setid.add(opp.Accountid);
    
    acclist =[select id,Name from  Account where id in:setid];
    if(opp.StageName=='Closed Won')
        {
            
            for(Account acc:acclist)
            {
                acc.Rating='Hot';
            }
            update acclist;
        }  
   } 
}

No comments:

Post a Comment

Automatically Covert a lead to Account,contact,Opportunity Trigger.

 How   to   convert    Automatically  lead to Account,contact,Opportunity   Trigger. trigger LeadHandler on Lead (after insert) {     list&l...