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
sfdc03sfdc03 

Can someone tell me solution for this trigger?

Whenever existing Account is updated with  AnnualReneue  more than 10k and Industry as Technology  then create a new opportunity for this account with same account name, stage name prospecting...

 
SAKTHIVEL MSAKTHIVEL M
Hi,

Use the below code for your requirement to create new opp when the account AnnualReneue is more than 10K.
 
Trigger update_child on Account (after update){

    list<opportunity> oplist = new list<opportunity>();
    set<id> setid = new set<id>();
	
    list<opportunity> createOpps = new list<opportunity>();
    
    for(account acc : trigger.new)
    {
        
		
		if(acc.AnnualReneue > 10000) {
			opportunity createOpp = new opportunity();
			createOpp.AccountId = acc.Id;
			createOpp.StageName = 'Prospecting';
			createOpps.add(createOpp);
		
		}
    }
	
	if(createOpps != null && !createOpps.isEmpty()) {
		insert createOpps;
		
	}
}


also, you can achieve using the process builder to achieve the same functionality.

Thanks & Regards,
Sakthivel Madesh
Deepali KulshresthaDeepali Kulshrestha
Hi sfdc03,

Please try this code below to get expected results-

Trigger:
trigger AccountFieldToOpp on Account (after insert,after update) {
AccountTrigg.createOpp(trigger.new);
}
Trigger Handler:

public class AccountTrigg {
 public static void createOpp(List<Account> acList)
 {
     List<Opportunity> opList =new List<Opportunity>();
     for(Account ac: acList)
     {
        if(ac.AnnualRevenue > 10000 && ac.Industry=='Technology') 
        {
         Opportunity op =new Opportunity();
         op.Name =ac.name;
         op.AccountId=ac.id;
         op.StageName='Prospecting';
         op.CloseDate= date.today();
         opList.add(op);
        }
     }
     insert opList;
 }
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
Raju yadavRaju yadav
Hi,
Please try Below code
Trigger insertOpportunity on Account (after update){

    List<opportunity> oppList = new List<opportunity>();
    
    for(account acc : trigger.new)
    {
        
		
		if(acc.AnnualReneue > 10000 && && acc.Industry=='Technology') {
			opportunity thisOpp = new opportunity();
			thisOpp.AccountId = acc.Id;
			thisOpp.StageName = 'Prospecting';
			oppList.add(createOpp);
		
		}
    }
	
	if(oppList!= null && !oppList.isEmpty()) {
		insert oppList;
		
	}
}

Thanks