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
AFTAB ALI 6AFTAB ALI 6 

how to create apportunity if rating is hot full code ?

PriyaPriya (Salesforce Developers) 
Hi Aftab,

You need to write a trigger for this. 

Try this code :-
trigger demoCreateOppOnAccount on Account (after insert) {
    
    List<Opportunity> oppList = new List<Opportunity>();
       
        for(Account a : trigger.new){
            if(a.rating == 'Hot'){
                Opportunity op = new Opportunity();
                op.name=a.name;
                op.AccountId = a.id;
                op.StageName ='prospecting';
                op.CloseDate = system.today()+15;
                op.Type ='New Customer';
                
                oppList.add(op);
            }
            
        }
    insert oppList;
}
  Description :- Whenever you create any account with Rating Hot, one new opportunity will be created under that account. If you want this logic to run when you edit any record with value Rating as Hot, then add the after Update event also 

Kindly mark it as the best answer if it works for you.

 

Thanks & Regards,

Priya Ranjan