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
Uves RavatUves Ravat 

Too many soql query????

Hi,

 

How can i make this soqgl query more efficent so i dont hit any govner limits

 

        String query;
        if(contractIds == null || contractIds.size() == 0)
            query = 'Select id FROM Ceto_Contract__c WHERE (Status__c = :statusActive OR Status__c = :statusPending) AND (Contract_Expiration_Date__c > :runDate OR Contract_Expiration_Date__c = null) AND (Cancellation_Date__c > :runDate OR Cancellation_Date__c = null)';
            
        if(Test.isRunningTest())
            query += ' limit 1';
        return query;

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
craigmhcraigmh

I think he's saying that the Ceto_Contract__c has more than 10k rows, and he's hitting that limit.

All Answers

Andy BoettcherAndy Boettcher

You need to post all of your code to get assistance on this.  The code you posted by itself wouldn't hit any governor limits.

 

-Andy

Uves RavatUves Ravat

Here is the whole query andy,

 

        String query;
        if(contractIds == null || contractIds.size() == 0)
            query = 'Select id FROM Ceto_Contract__c WHERE (Status__c = :statusActive OR Status__c = :statusPending) AND (Contract_Expiration_Date__c > :runDate OR Contract_Expiration_Date__c = null) AND (Cancellation_Date__c > :runDate OR Cancellation_Date__c = null)';
        else
            query = 'Select id FROM Ceto_Contract__c WHERE (Status__c = :statusActive OR Status__c = :statusPending) AND (Contract_Expiration_Date__c > :runDate OR Contract_Expiration_Date__c = null) AND (Cancellation_Date__c > :runDate OR Cancellation_Date__c = null) AND id IN :contractIds';
            
        if(Test.isRunningTest())
            query += ' limit 1';
        return query;

 

Thanks

Uves

Andy BoettcherAndy Boettcher

Not just the query - that by itself won't hit any governor limits.  How you are iterating through the results of that query would be more applicable.  SOQL / DML in loops, etc.

 

-Andy

craigmhcraigmh

I think he's saying that the Ceto_Contract__c has more than 10k rows, and he's hitting that limit.

This was selected as the best answer