1

I've this query for checking existing contact on Salesforce

string queryString="select Id from Contact where Applicant_Email__c = 'testuser78@mailinator.com' or email = 'testuser78@mailinator.com' or Secondary_Email__c = 'testuser78@mailinator.com' or Third_Email__c = 'testuser78@mailinator.com' or Fourth_Email__c = 'testuser78@mailinator.com'";

QueryResult qr = null;
        try
        {
            qr = binding.query(queryString);
        }

but this query is taking long time to execute, is there any way to optimize this query and make faster?

Ramesh
  • 243
  • 1
  • 4
  • 15
  • *this query is taking long time to execute* define long time? – Izzy Oct 07 '15 at 09:19
  • @lzzy long time - taking more then 60 seconds to return results – Ramesh Oct 07 '15 at 09:21
  • First, how do you it is quert and not something in your code which is taking time? if it is really query, how much time does it take? Can you show us the structure of contact table? what is primary key in Contact table? is there any Clustered or Non clustered index on that table? – Viru Oct 07 '15 at 09:22
  • @lzzy moreover it's not SQL query it's SOQL query(salesforce).. – Ramesh Oct 07 '15 at 09:23

1 Answers1

0

There are several things you need to consider here:

  1. How many records are you getting back?
  2. How long does the same query take in the developer console?
  3. What is the selectivity of the SOQL query?

These points can direct you towards the problem. For example, if the same query is fast in the developer console and is returning a large number of records then the problem is most likely not using compression in the SOAP response. See SOAP Compression

If the selectivity of the query is poor then you should look at getting indexes added or reworking the query. See Make SOQL query selective.

Incidentally, the Salesforce StackExchange is a great place to ask Salesforce specific questions.

Daniel Ballinger
  • 13,187
  • 11
  • 69
  • 96