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
Pradeep Pradhan 21Pradeep Pradhan 21 

Write a trigger to replicate the rollup summary field on lookup relation objects to count sum of amount on account object from the opportunity amount field.

SwethaSwetha (Salesforce Developers) 
HI Pradeep,
Try below code
trigger rollupopp on Opportunity (after delete,after update,after insert,after undelete) {
    set<ID>AccIds = new set<ID>();
    if(trigger.isinsert || trigger.isundelete){
        for(opportunity opp : trigger.new){
            AccIds.add(opp.AccountId);
        }
    }
    if(trigger.isdelete){
        for(opportunity opp : trigger.old){
            AccIds.add(opp.AccountId);
        }
    }
    if(trigger.isupdate){
        for(opportunity opp:trigger.new){
            AccIds.add(opp.AccountId);
            if(trigger.oldmap.get(opp.id).AccountId != opp.AccountId && trigger.oldmap.get(opp.id).AccountId != null ){
                AccIds.add(trigger.oldmap.get(opp.id).AccountId);
            }
        }
    }
    map<id,double> amtmap = new map<id,double>();
    for(aggregateresult ag : [select AccountId ,SUM(Amount) SOA,count(id) cc from opportunity where AccountId in:AccIds group by AccountId]){
        amtmap.put((ID)ag.get(‘AccountId’), double.valueof(ag.get(‘SOA’)));
    }
    list<account>acclist = new list<account>();
    for(id iid : AccIds){
        account acnt = new account(id=iid);
        if(amtmap.containskey(iid)){
            acnt.Total_Amount__c  = amtmap.get(iid);
        }else{
            acnt.Total_Amount__c  = 0;
        }
        acclist.add(acnt);
    }
    if(acclist.size()>0){
        update acclist;
    }
}

If this information helps, please mark the answer as best. Thank you