• Durvesh Shah 8
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 3
    Replies
All of a sudden I am unable to query quantity forecast and revenue forecast object. The code was working fine for the past 4 years and it suddenly stopped on 18/07/2020.

Please help someone. It's very urgent.

List<QuantityForecast> lstQuantity;  lstQuantity = [select Id, Quota,OwnerId, StartDate from QuantityForecast where OwnerId in: setofUser ];
This is my requirement! Can anyone post the solution! I need it a bit urgently.

Any Lead created in Salesforce after office hours shall be as assigned in queue and Queue requests shall be auto-assigned to users on the next working day at 10:30 AM and 11:30 AM (in cases no user has logged in by 10:30 AM- the secondary assignment will start at 11:30 AM.
User-added image
public class BuildingControllerext {
    
    public  String recordTypeId {get;set;}
    //public site__c site{get;set;}
    public string parentid{get;set;}
    public string site{get;set;}
    

    public buildingcontrollerext(ApexPages.StandardController controller)
    {
        String parentid= ApexPages.CurrentPage().getParameters().get('retURL');
        System.debug('This returnurl'+parentid);
        site =  parentid.right(15);
        System.debug('This site'+site);
    }
    
      
       public Pagereference redirectToVF()
    {
        Pagereference pg;
        String spPrefix = Building__c.SObjectType.getDescribe().getKeyPrefix(); 
       
        if(ApexPages.CurrentPage().getParameters().get('RecordType') != null )
        {      
            recordTypeId = ApexPages.CurrentPage().getParameters().get('RecordType');          
            
            if(recordTypeId == Schema.SObjectType.Building__c.getRecordTypeInfosByName().get('RCC').getRecordTypeId())
            {
               pg = new Pagereference('/apex' + '/showrcc?RecordType='+ RecordTypeId + '&site='+site);  
               pg.getParameters().put('nooverride','1');
             } 
            
                                               
            }
            else if(RecordTypeId == Schema.SObjectType.Building__c.getRecordTypeInfosByName().get('Ground/Parking').getRecordTypeId())
            {                                           
                pg = new Pagereference('/apex' + '/showground?RecordType=' + RecordTypeId + '&site='+site);  
                pg.getParameters().put('nooverride','1');
            }     
            else if(recordTypeId == Schema.SObjectType.Building__c.getRecordTypeInfosByName().get('Metal').getRecordTypeId())
            {                          
               pg = new Pagereference('/apex' + '/showmetal?RecordType=' + RecordTypeId + '&site='+site);  
                pg.getParameters().put('nooverride','1');
            }
            pg.setRedirect(true);
            return pg;
         }           
         
             return null;
         

         
    }
      
      
    
        
}

 
public class TriggerOnOfferInvoiceClass {
    public static Boolean isFirstTime = true; // to stop Recursiveness    
    public static void updateOfferAndInvoice(List<TOOH_Offer__c> triggerNew, Map<Id, TOOH_Offer__c> triggerNewMap, Map<id, TOOH_Offer__c> triggerOldMap) {
      List<Invoice__c> invs = new List<Invoice__c>();
        List<TOOH_Offer__c> offs = new List<TOOH_Offer__c>();
        Set<Id> duplicateSet = new Set<Id>();
        Set<Id> dup = new set<Id>();
        Set<Id> offIds = new Set<Id>();
        System.debug('triggerNew '+triggerNew);
        System.debug('triggerOldMap '+triggerOldMap);
        for(TOOH_Offer__c off : triggerNew){
            System.debug('1 '+ off.BC_NBC__c +' '+triggerOldMap.get(off.id).BC_NBC__c );
            //System.debug('2 '+ off.Percentage __c +' '+triggerOldMap.get(off.id).Percentage__c );
            System.debug('3 '+ off.Name +' '+triggerOldMap.get(off.id).Name );
            System.debug('4 '+ off.TOOH_Kind_Attn__c +' '+triggerOldMap.get(off.id).TOOH_Kind_Attn__c );
            System.debug('5 '+ off.Owner +' '+triggerOldMap.get(off.id).Owner );
            /*
            System.debug('1 @@@'+ off.BC_NBC__c != triggerOldMap.get(off.id).BC_NBC__c );
            System.debug('2 '+ String.valueOf(off.Percentage__c) != String.valueOf(triggerOldMap.get(off.id).Percentage__c) );
            System.debug('3 '+ off.Name != triggerOldMap.get(off.id).Name );
            System.debug('4 '+ off.TOOH_Kind_Attn__c != triggerOldMap.get(off.id).TOOH_Kind_Attn__c );
            System.debug('5 '+ String.valueOf(off.Owner) != String.valueOf(triggerOldMap.get(off.id).Owner) );
            */
            
            if(off.BC_NBC__c != triggerOldMap.get(off.id).BC_NBC__c 
               || String.valueOf(off.Percentage__c) != String.valueOf(triggerOldMap.get(off.id).Percentage__c)
               || off.Name != triggerOldMap.get(off.id).Name
               || off.TOOH_Kind_Attn__c != triggerOldMap.get(off.id).TOOH_Kind_Attn__c || String.valueOf(off.Owner) != String.valueOf(triggerOldMap.get(off.id).Owner)){
                   System.debug('offerId in IF '+off.Id);
              offIds.add(off.Id);
                   
               }
            System.debug('offerId out IF '+off.Id);
        }
        system.debug('!! +'+offIds);
        
        for(Invoice_Item__c obj : [SELECT Id, Invoice__c, Offer__c from Invoice_Item__c WHERE Offer__c IN :offIds ]){
            if(duplicateSet.contains(obj.Invoice__c))
                continue;
            
            duplicateSet.add(obj.Invoice__c);
            Invoice__c inv = new Invoice__c(
                Id=obj.Invoice__c,
                BC_NBC__c=triggerNewMap.get(obj.offer__c).BC_NBC__c, 
                Percentage__c=triggerNewMap.get(obj.offer__c).Percentage__c, 
                Brand_Name__c=triggerNewMap.get(obj.offer__c).Name, 
                Contact_Person__c=triggerNewMap.get(obj.offer__c).TOOH_Kind_Attn__c, 
                User__c=triggerNewMap.get(obj.offer__c).OwnerId
            );            
            invs.add(inv);            
        }
        if(invs.size() > 0){
            update invs;
        }
        system.debug(''+invs);

        
    for(Invoice_Item__c itobj : [SELECT Id, offer__c, invoice__c, 
                                     invoice__r.BC_NBC__c, invoice__r.Percentage__c, invoice__r.Brand_Name__c, 
                                     invoice__r.User__c, invoice__r.Contact_person__c
                                     from Invoice_Item__c WHERE Invoice__c IN :duplicateSet AND Offer__c NOT IN : offIds ]){
                                         
          if(dup.contains(itobj.offer__c))
                continue;
            dup.add(itobj.Offer__c);
            TOOH_Offer__c obj = new TOOH_Offer__c(
              id = itobj.Offer__c,
                BC_NBC__c = itobj.invoice__r.BC_NBC__c,
                Percentage__c = itobj.invoice__r.Percentage__c,          
                Name = itobj.invoice__r.Brand_Name__c,        
                TOOH_Kind_Attn__c = itobj.invoice__r.Contact_Person__c,
                OwnerId = itobj.invoice__r.User__c
                    
            );
            offs.add(obj);
        }
        
        if(offs.size() > 0){
            update offs;
        }
        system.debug(''+offs);
            
    }
}

 
User-added image
 I have grouped my account with respective account owner but i have queried in my for loop which is not a a best practice. Can Someone give me optimized version of my code. It will be of great help. Below is my Apex Class.
 
public with sharing class MapofAccountsExt{

 public List<Account> Accountlist{get;set;}
 public Map<String,List<Account>> AccountMap{get;set;}
 public Map<String,List<User>> UserMap{get;set;}
 
 public MapofAccountsExt(ApexPages.StandardController controller) 
    {
        thismethod();
    }

 public PageReference thismethod()
    {
      Accountlist = new List<Account>();
      Accountlist = [select id,AccountNumber,name,owner.name,email__c,Active__c from Account];
        Set<id> setofids = new Set<id>();
        for(Account thisAccount : Accountlist)
        {
            setofids.add(thisAccount.ownerid);
            system.debug('the whole set of id '+setofids);
        }
        list<Account> newAccountList = new List<Account>();
        
        newAccountList= [Select id,AccountNumber,name,ownerid,owner.name,email__c,Active__c from Account where ownerid in:setofids];
        system.debug('this expense id for the list '+newAccountList);
        
        
        AccountMap= new Map<String,List<Account>>();
        List<Account> accList = new List<Account>();
        for(Account thisAccountid: newAccountList)
        {
                accList = [select id,AccountNumber,name,ownerid,owner.name,email__c,Active__c from Account where ownerid=:thisAccountid.ownerid and (id = '0016F00002PEDkg' or id ='0016F00002PEECU' or id='0016F00002PF4Bt' or id = '0016F00002PF5UK')];
                AccountMap.put(thisAccountid.owner.name,accList);
                system.debug('this Account id '+AccountMap);

        }
        List<User> Userlist = new List<User>();
        Userlist = [select id,name,email from User];
        UserMap = new Map<String,List<User>>();
        List<User> Userlist1 = new List<User>();
        for(User thisUser1 : Userlist)
        {
            Userlist1 = [select id,name,email from User where email=:thisuser1.email limit 1];
            UserMap.put(thisuser1.name,Userlist1);
        }
        
        
        return null;       
    }
}

 
User-added image
 I have grouped my account with respective account owner but i have queried in my for loop which is not a a best practice. Can Someone give me optimized version of my code. It will be of great help. Below is my Apex Class.
 
public with sharing class MapofAccountsExt{

 public List<Account> Accountlist{get;set;}
 public Map<String,List<Account>> AccountMap{get;set;}
 public Map<String,List<User>> UserMap{get;set;}
 
 public MapofAccountsExt(ApexPages.StandardController controller) 
    {
        thismethod();
    }

 public PageReference thismethod()
    {
      Accountlist = new List<Account>();
      Accountlist = [select id,AccountNumber,name,owner.name,email__c,Active__c from Account];
        Set<id> setofids = new Set<id>();
        for(Account thisAccount : Accountlist)
        {
            setofids.add(thisAccount.ownerid);
            system.debug('the whole set of id '+setofids);
        }
        list<Account> newAccountList = new List<Account>();
        
        newAccountList= [Select id,AccountNumber,name,ownerid,owner.name,email__c,Active__c from Account where ownerid in:setofids];
        system.debug('this expense id for the list '+newAccountList);
        
        
        AccountMap= new Map<String,List<Account>>();
        List<Account> accList = new List<Account>();
        for(Account thisAccountid: newAccountList)
        {
                accList = [select id,AccountNumber,name,ownerid,owner.name,email__c,Active__c from Account where ownerid=:thisAccountid.ownerid and (id = '0016F00002PEDkg' or id ='0016F00002PEECU' or id='0016F00002PF4Bt' or id = '0016F00002PF5UK')];
                AccountMap.put(thisAccountid.owner.name,accList);
                system.debug('this Account id '+AccountMap);

        }
        List<User> Userlist = new List<User>();
        Userlist = [select id,name,email from User];
        UserMap = new Map<String,List<User>>();
        List<User> Userlist1 = new List<User>();
        for(User thisUser1 : Userlist)
        {
            Userlist1 = [select id,name,email from User where email=:thisuser1.email limit 1];
            UserMap.put(thisuser1.name,Userlist1);
        }
        
        
        return null;       
    }
}