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
akallioWileyakallioWiley 

soql optimization question

Can anybody help me figure out why the following 2 soql queries seem to take forever...they timeout in the workbench. Do you see anything I could to imporve their performance? Thanks!

 

Select Contact__c,ISBN_13__c,Order_Date__c,Id,Ship_Date__c,Ship_Method_Description__c,Contact__r.Email,Product__r.Name From Comp_Item__c where (LastModifiedDate >=2013-04-07T20:50:40.9793994Z or CreatedDate <=2013-04-07T20:50:40.9793994Z) and Contact__r.Email like '%@%' and Contact__c != Null And (NOT Contact__r.Email like '%@wiley.com') and Contact__r.Inactive__c = FALSE

 

Select ContactId,Id,OpportunityId,Contact.Email,Opportunity.BRV__c,Opportunity.CA_Tier__c,Opportunity.Custom__c,Opportunity.CloseDate,Opportunity.Enrolment__c,Opportunity.MarketConsultant__c,Opportunity.Type,Opportunity.OwnerId,Opportunity.Primary_Long_Title__c,Opportunity.Primary_Title_Author__c,Opportunity.PrimaryTitleCourseCodeNum__c,Opportunity.Primary_Title_ISBN_13__c,Opportunity.Priority_Target__c,Opportunity.Renew__c,Opportunity.Semester__c,Opportunity.StageName,Opportunity.Est_Revenue__c,Opportunity.Tier__c,Opportunity.WileyPLUS__c,Opportunity.Year__c From OpportunityContactRole where ((OpportunityContactRole.LastModifiedDate >=2013-04-07T20:51:55.6877994Z or CreatedDate <=2013-04-07T20:51:55.6877994Z) or (Opportunity.LastModifiedDate >=2013-04-07T20:51:55.6877994Z) or (Contact.LastModifiedDate >=2013-04-07T20:51:55.6877994Z)) and (Contact.Email like '%@%' and (NOT Contact.Email like '%@wiley.com') and Contact.Inactive__c = FALSE)

 

MohammadMohammad

Probably you should do something like this -

 

1. check if Conatct__c is not null. first thing. this reduced the scope of records

2. then check Inactive is false again for the same reason

3. Email will always be '%@%' format so no need to check this instead just use the NOT condition for wiley.com.

 

Let me know if this works.

 

Select Contact__c,ISBN_13__c,Order_Date__c,Id,Ship_Date__c,Ship_Method_Description__c,Contact__r.Email,Product__r.Name From Comp_Item__c where (LastModifiedDate >=2013-04-07T20:50:40.9793994Z or CreatedDate <=2013-04-07T20:50:40.9793994Z) and Contact__c  != null AND Contact__r.Inactive__c = false And (NOT Contact__r.Email like '%@wiley.com')
Bhawani SharmaBhawani Sharma
Why you are using :
LastModifiedDate >=2013-04-07T20:50:40.9793994Z or CreatedDate <=2013-04-07T20:50:40.9793994Z
criteria. I do no see if thsi is of any use. This will always pick all the records from System.