+ Start a Discussion
Karen HansonKaren Hanson 

trigger error Prospect

i have a  requirement when only account field type update to Prospect the related opp stage name  update's Prospect ,but her whenever i chage any field in account . the opp stage names update's Prospect .
 
trigger updateopportunities on Account(after update) 
{
    Set<Id> accountIds = new Set<Id>(); //new set of IDs 
    for(Account ac : Trigger.new)     //bulklification 
    {
         {
            if(ac.Type!=trigger.oldMap.get(ac.Id).name)   // er
         

         if(ac.Type=='Prospect')        //if axcount if of prospect
         accountIds.add(ac.Id);         //add it to set values 
       {
    }

     List<Opportunity> oppsToUpdate = new List<Opportunity>();      //new list 

     for(Opportunity opp : [select id, StageName from Opportunity where AccountId in: accountIds]) //bulklification   query for stagename ,id from opportunity
     {
          opp.StageName='Prospect';      
          oppsToUpdate.add(opp);         //  adding to the list     
     }

     update oppsToUpdate;               //update the opp
}
}
}

 
Best Answer chosen by Karen Hanson
KbhaskarKbhaskar
use this
for(Account ac : Trigger.new)     //bulklification 
    {
     Account acc = Trigger.oldMap.get(ac.id);
        if(ac.Type != acc.Type) {
         
        {

         if(ac.Type=='Prospect')        //if account is of prospect
         accountIds.add(ac.Id);         //add it to set values