+ Start a Discussion
Shruthi NarsiShruthi Narsi 

Add all amount on opportunity

Add all amount on opportunity on quota actual amount 

User-added image
public with sharing class listopponquota {
    
    public list<Opportunity> oppList{get;set;}
    
    public listopponquota()
    {
        String selectedVal ='';
        oppList = new list<Opportunity>();
        oppList();
    }
    
    public pageReference oppList() {
        Id qId = (Id) ApexPages.currentPage().getParameters().get('id');
        system.debug('Id-->'+qId);    
        List<quota__c> quotaList1 = new List<quota__c>();
        List<Opportunity> oppList1 = new List<Opportunity>();
        quotaList1 =[select Id, Name,Start_Date__c,End_Date__c,Assign_to_User__c,Actual_Amount__c,OwnerId from quota__c where Id   =: qId Limit 1];
        oppList1 = [Select Id, Name, CloseDate, StageName,Amount,OwnerId From Opportunity where StageName = 'Closed Won'];
        
        system.debug('quotaList1-->'+quotaList1);
        if(quotaList1.size() > 0){
            for(quota__c q : quotaList1){
                system.debug('Name-->'+q.Name);
                for(Opportunity opp : oppList1){
                    system.debug('closedDate-->'+opp.CloseDate);
                    if(opp.CloseDate  >=  q.Start_Date__c  && opp.CloseDate <= q.End_Date__c && q.Assign_to_User__c == q.OwnerId && q.RecordTypeId == '0122v000002KFRAAA4'){
                        oppList.add(opp);
                    } 
                    if( q.RecordTypeId == '0122v000002KFRAAA4') {
                    q.Actual_Amount__c = 0;
                } else {
                    q.Actual_Amount__c = q.Actual_Amount__c + Decimal.ValueOf(String.ValueOf(q.get('Actual_Amount__c')));                    
                    quotaList1.add(q);
                }
            }
        }
        if(quotaList1.size()>0) {            
            update quotaList1;
             
        
        }
    }
        system.debug('oppList-->'+oppList);
            return null;
}
}