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
rameshramesh 

Whenever an Opportunity is Created, Updated and Deleted then Roll-up the Opportunity amount to Account's Annual Revenue

Whenever an Opportunity is Created, Updated and Deleted then
Roll-up the Opportunity amount to Account's Annual Revenue
rameshramesh
Using triggers 
AnkaiahAnkaiah (Salesforce Developers) 
Hi Saki,

try with below code. Replace Opportunity_amount__c with your field API name.
trigger OppAmountUpdate on Opportunity ( after insert, after update, after delete) {

    Map<Id, List<Opportunity>> acctoopp = new Map<Id, List<Opportunity>>();
    Set<Id> acctIds = new Set<Id>();
    List<Opportunity> opptyList = new List<Opportunity>();
    if(trigger.isUpdate || trigger.isInsert){
        for(Opportunity oppty : trigger.New){
            if(oppty.AccountId != null){
                acctIds.add(oppty.AccountId);
            }
        }    
    }
    if(trigger.isDelete){
        for(Opportunity oppty : trigger.old){
            if(oppty.AccountId != null){
                acctIds.add(oppty.AccountId);
            }
        }    
    }
    if(acctIds.size() > 0){
        opptyList = [SELECT Amount, AccountId FROM Opportunity WHERE AccountId IN : acctIds];
        for(Opportunity oppty : opptyList){
            if(!acctoopp.containsKey(oppty.AccountId)){
                acctoopp.put(oppty.AccountId, new List<Opportunity>());
            }
            acctoopp.get(oppty.AccountId).add(oppty); 
        }   
        List<Account> acctList = new List<Account>();
        acctList = [SELECT Opportunity_amount__c  FROM Account WHERE Id IN: acctIds];
        for(Account acct : acctList){
            List<Opportunity> opplist = new List<Opportunity>();
            opplist = acctoopp.get(acct.Id);
            Double oppyamount = 0;
            for(Opportunity oppty : opplist){
                if(oppty.Amount != null){
                    oppyamount += oppty.Amount;
                }
            }
            acct.Opportunity_amount__c  = oppyamount;
        }
        update acctList;
    }

}

If this helps, Please mark it as best answer.

Thanks!!