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

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...


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 :
		if(acc.AnnualReneue > 10000) {
			opportunity createOpp = new opportunity();
			createOpp.AccountId = acc.Id;
			createOpp.StageName = 'Prospecting';
	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 AccountFieldToOpp on Account (after insert,after update) {
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();
     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
Please try Below code
Trigger insertOpportunity on Account (after update){

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