Skip to main content
Nagendra Singh 님이 #Apex에 질문했습니다
Hi All,

I'm running one time update using Execute Anonymous and getting error "Salesforce SOQL Error Too many SOQL 001" for the following code, I tried few options to change the code but couldn't run the update, anyone can help with this code please: (Opportuntiy is master for custom object Sales Team, 1 : M)

List <Opportunity> OpptySalesRep = [Select Id,Sales_Rep__c From Opportunity Where  Sales_Rep__c !=null and (CreatedDate > 2014-11-01T00:00:00Z and CreatedDate <= 2014-11-30T00:00:00Z)];    

    set<Id> opportunityIdSet = new set<Id>();

        for (Opportunity Oppty : OpptySalesRep) {

          

            list<Sales_Team__c> newGSTmember = new list<Sales_Team__c>(); 

           

            opportunityIdSet.add(Oppty.Id); //Needed for following SOQL for GST       

           //Query to get all Sales team memeber for the opportunity                    

           List <Sales_Team__c> gst = [Select Sales_Team_Member__c,Primary__c,Producer__c,Opportunity__c,Id

                                             From Sales_Team__c

                                             Where Opportunity__c  IN: opportunityIdSet and  Producer__c = null and Opportunity__c <> null];

                                        

                                             system.debug('Number of Sales Team Member⌗ ' + gst.size());

            

            //Reset  opportunityIdSet for avoid duplicate iteration 

             opportunityIdSet.remove(Oppty.Id);

                           

            boolean IsnewSalesRep = true;  //to check if Sales Rep already exists in GST            

              

           // Loop through the list and update GST record that matches to Sales Rep

           for (Sales_Team__c OpptyGST : gst){

              system.debug('GST Memebr⌗ : ' + OpptyGST.Sales_Team_Member__c);                        

              

              //Update Sales Rep to Primary

              if (OpptyGST.Sales_Team_Member__c == Oppty.Sales_Rep__c){

                  system.debug('INSIDE If');

                  OpptyGST.Primary__c = true;

                    IsnewSalesRep = false;

                }

              // Update Sales reps to non-primary

                else if (OpptyGST.Sales_Team_Member__c != Oppty.Sales_Rep__c && OpptyGST.Primary__c == true){

                  system.debug('INSIDE else If');

                  OpptyGST.Primary__c = false;

              }

                            

              }

            

            //Add Sales Rep to GST          

             if (IsnewSalesRep == true)

             {

             Sales_Team__c newGST = new Sales_Team__c (); //instantiate the GST object to put values

                          

            newGST.Sales_Team_Member__c = Oppty.Sales_Rep__c;

             newGST.Primary__c = true;

             newGST.Opportunity__c = Oppty.Id;

             newGSTmember.add(newGST);

             insert newGSTmember;

             

              }

           

              update gst;  

                         

           }

답변 4개
  1. 2015년 7월 7일 오후 1:57
    Thanks Onkar, how to access child record to update, I tried as "OpptySalesRep.Sales_Team__c.Primary__c" and getting error "Initial term of field expression must be a concrete SObject: List<Opportunity>".
0/9000