+ Start a Discussion
Love SFDCLove SFDC 

SOQL query exceeding the 20000 character limit - workaround

Hi everyone !
I'm looking for some good design practice for the below scenario.
I've an object which has lot of fields and a record is being created/updated in one of the class (say mainClass). Query in the mainClass is going to exceed
20000 characters which is the max limit of SOQL query. We're going to add few more fields in the near future and definetely the query size exceeds the
max limit. I can create a query2 for the same object, but the issue is to leverage the doSOmething() in the Helper class, which has lot of business logic in it.
How can I leverage my doSomething() method in this situation.

Any pointers on this is much appreciated.

public class mainClass {

    public void sampleMethod1(){
      Object1 query1 = [SELECT field1__c,field2__c,field3__c,field4__c,......
                      .......
                      .......
                      FROM Object1 LIMIT1]; // This query is GOING TO exceed 20,000 characters which is the max limit for a SOQL query in Salesforce  

       query1.field1__c='test1';
       query1.field2__c='test2';
       Helper hlp = new Helper();
       hlp.doSometing(query1);
       update obj1;
      
    }
}


public class Helper{

    Object1 o1;
    public Helper(){
       o1 = new Object1();
    }
    
   public void doSomething(Object1 obj1){   
       o1=obj1;
       o1.field3__c = 'test3';
       o1.field4__c='test4';
       o1.field5__c='test5';
       .
       .
       .
       .
       .//lot of business logic exist here to map the Object1 fields
       .    
       .
       .       
   }
}

 
olegforceolegforce
create two queries and combine results into one object using SObject methods for setting the fields. Should work.
Love SFDCLove SFDC
HI Olegforce,
Thanks for the response. Can you pls throw some light on that. If possible, what method of SObject should be used. An Example of the scenario will be great.

Thanks,
olegforceolegforce
I am guessing you are trying to add all fields from object to query and send it to the method. Is that correct? 
Love SFDCLove SFDC
assigning values to some fields of an object happens in one class and rest of the field assignment happens in another class. The DML operation insert/update happens in the original class. Hope this makes sense.
olegforceolegforce
My question is  - what causes limit exception? Is it number of fields or filters in query?