1

Based on the requirement i have written a batch and schedule class for an email notification to be sent before 90 days. I have used the below query in the code ,where i used to get an email notification mail.

return Database.getQueryLocator('Select  id, Contract_Name__c , EndDate ,Contact_Email__c, Contract_End_Date_2__c ,ownerId,Owner.Email, Account.Owner.Email  FROM Contract  WHERE Id IN: setContractIds');

Now we had few conditions to be added in the code ,

Condition is when the "Renewal_Status__c" is equal to 'Pushed Forward To Next Quarter','In Pipe' AND when "Next_Quarter_Renewal_Status__c" is not equal to'Renewed','Renewal lost’.

The System throws an Error as :

Compile Error: expecting a right parentheses, found ',' at line 22 column 298 When i use this query

Database.getQueryLocator([Select id, Contract_Name__c , EndDate ,Contact_Email__c, Contract_End_Date_2__c, Owner.Email, Owner.Manager.Email ,Account.Owner.Email,Account.Owner.Manager.Email  FROM Contract  WHERE Id IN: setContractIds AND Renewal_Status__c IN :('Pushed Forward To Next Quarter','In Pipe') AND Next_Quarter_Renewal_Status__c IN :('Renewed','Renewal lost’)]);

If i use in another way :

return Database.getQueryLocator('Select  id, Contract_Name__c , EndDate ,Contact_Email__c, Contract_End_Date_2__c, Owner.Email, Owner.Manager.Email ,
                                   Account.Owner.Email,Account.Owner.Manager.Email  FROM Contract  WHERE Id IN: setContractIds
                                         AND Renewal_Status__c IN :(\'Pushed Forward To Next Quarter\', \'In Pipe\') 
                                         AND Next_Quarter_Renewal_Status__c IN :(\'Renewed\', \'Renewal lost\')');

the system throws another error as :

line breaks not allowed in string literals at line 18 column -1

Any help very much appreciated.

5
  • Bit of a guess, but try adding values in IN :('Pushed Forward To Next Quarter','In Pipe') and IN :('Renewed','Renewal lost’) to Sets?
    – Dan Jones
    Commented Apr 11, 2016 at 10:56
  • I guess that salesforce doesn't support multiline strings. I think you should do like: String query = 'select Id' + <line break> ' FROM Account' + <line break> + ...
    – kurunve
    Commented Apr 11, 2016 at 10:58
  • 'Renewed','Renewal lost’ the , after lost as superscript is typo in first method? Commented Apr 11, 2016 at 11:02
  • 1
    first should be Database.getQueryLocator([Select id, Contract_Name__c , EndDate ,Contact_Email__c, Contract_End_Date_2__c, Owner.Email, Owner.Manager.Email ,Account.Owner.Email,Account.Owner.Manager.Email FROM Contract WHERE Id IN setContractIds AND Renewal_Status__c IN ('Pushed Forward To Next Quarter','In Pipe') AND Next_Quarter_Renewal_Status__c IN ('Renewed','Renewal lost’)]); without colon
    – Ratan Paul
    Commented Apr 11, 2016 at 11:03
  • @Poet,@Kurunve,@ Vigneshwaran G,@sfdcweb:Thanks for your response.When i use Query return Database.getQueryLocator('Select id, Contract_Name__c , EndDate ,Contact_Email__c, Contract_End_Date_2__c ,ownerId,Owner.Email, Account.Owner.Email FROM Contract WHERE Id IN: setContractIds');The i get the email notification but when i give the condition and use the query as stated above ,i dont get any email notification.Any Suggestion please. Commented Apr 11, 2016 at 11:16

1 Answer 1

1

In first method, : is not required since you are not using any bind variables.

Database.getQueryLocator([Select id, Contract_Name__c , EndDate ,Contact_Email__c, Contract_End_Date_2__c, Owner.Email, Owner.Manager.Email ,Account.Owner.Email,Account.Owner.Manager.Email  FROM Contract  WHERE Id IN: setContractIds AND Renewal_Status__c IN ('Pushed Forward To Next Quarter','In Pipe') AND Next_Quarter_Renewal_Status__c IN ('Renewed','Renewal lost')]);

In second method, querylocator doesn't allow multi line string as input. So it should be single line and here also : is not required.

return Database.getQueryLocator('Select  id, Contract_Name__c , EndDate,Contact_Email__c, Contract_End_Date_2__c, Owner.Email, Owner.Manager.Email , Account.Owner.Email,Account.Owner.Manager.Email  FROM  Contract  WHERE Id IN: setContractIds AND Renewal_Status__c IN (\'Pushed Forward To Next Quarter\', \'In Pipe\') AND Next_Quarter_Renewal_Status__c IN (\'Renewed\', \'Renewal lost\')');

Hope it helps.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .