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
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;
}
}
    
Prateek Prasoon 25Prateek Prasoon 25
public class QuotaOpportunityController {
    public List<Opportunity> oppList{get;set;}
    
    public QuotaOpportunityController() {
        oppList = new List<Opportunity>();
    }
    
    public PageReference oppList() {
        Id qId = (Id) ApexPages.currentPage().getParameters().get('id');
        System.debug('Id-->' + qId);    
        List<Quota__c> quotaList = new List<Quota__c>();
        List<Opportunity> oppList1 = new List<Opportunity>();
        quotaList = [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('quotaList-->' + quotaList);
        if (quotaList.size() > 0) {
            for (Quota__c q : quotaList) {
                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);
                        q.Actual_Amount__c = q.Actual_Amount__c + opp.Amount;
                    } 
                }
            }
            update quotaList;
        }
        System.debug('oppList-->' + oppList);
        return null;
    }
}