When an Account is created with Annual Revenue more than 1 Million, automatically create a related Opportunity.

public class AccountOpportunityCreator {
    
    public static void createOpportunityForAccount(List<Account> accList) {
        List<Opportunity> oppList = new List<Opportunity>();
        
        for(Account acc : accList) {
            if(acc.AnnualRevenue != null && acc.AnnualRevenue > 1000000) {
                Opportunity opp = new Opportunity();
                opp.Name = acc.Name + ' Initial Opportunity';
                opp.StageName = 'Prospecting';
                opp.CloseDate = System.today().addMonths(1);
                opp.Amount = acc.AnnualRevenue * 0.2; // Example: 20% of Annual Revenue
                opp.AccountId = acc.Id;
                oppList.add(opp);
            }
        }
        
        if(!oppList.isEmpty()) {
            insert oppList;
        }
    }
}

Usage:

  • Attach this method to a Trigger on Account (after insert).
  • Or you can call from Flow → Apex Action.

Sample Trigger

trigger AccountTrigger on Account (after insert) {
    AccountOpportunityCreator.createOpportunityForAccount(Trigger.new);
}

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top