Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I have a batch class that runs on all leads unless the user has entered a specific lead Record Type into a custom setting field. I'm getting an "System.QueryException: Invalid alias" even though when I have tested out the query in the query editor and it works fine. Below is the code for the base batch query and the expanded one if they have entered a lead type.

    batchquery = 'SELECT Name, Email, id, Compete__CompeteURL__c, Compete__CompeteUVs__c, Compete__CompeteVisits__c, Compete__CompeteLastUpdated__c FROM lead';
    if(setup.Lead_Record_Type__c != null){
      batchquery += 'WHERE RecordType.Name = \'' + setup.Compete__Lead_Record_Type__c + '\'';
      }else{}

Where is the invalid alias error coming from?

share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

Perhaps you are missing space in string formation.

batchquery += ' WHERE RecordType.Name = \'' + setup.Compete__Lead_Record_Type__c + '\'';

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.