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
JohnDuraiJohnDurai 

custom label in SOQL as Parmater Error

Hi - I am trying to user below query in batch class querylocator, I want to change the lastmodified date from configuration level without touching code. So, I am using custom label and my custom label input field as number and i am passing it in query, but getting error can someone suggest how to fix?

return Database.getQueryLocator([SELECT Id, Status,RecordTypeId, Resolution_Status__c, LastModifiedDate FROM CampaignMember where RecordTypeId ='0120p000000Fy09AAC' AND (Resolution_Status__c ='Resolved' OR Resolution_Status__c ='Closed') AND LastModifiedDate < LAST_N_DAYS:Integer.valueOf(system.Label.LastmodifiedDateforCM)]);

Error: Missing 'INTEGER_LITERAL' at 'Integer.valueOf'
Extra 'IDENTIFIER', at '('.
expecting a number, found 'Integer.valueOf'
AnkaiahAnkaiah (Salesforce Developers) 
Hi John,

try with below query.
 
integer Y = Integer.valueof(system.label.LastmodifiedDateforCM.trim());
return Database.getQueryLocator('SELECT Id, Status,RecordTypeId, Resolution_Status__c, LastModifiedDate FROM CampaignMember where RecordTypeId ='0120p000000Fy09AAC' AND (Resolution_Status__c ='Resolved' OR Resolution_Status__c ='Closed') AND LastModifiedDate < LAST_N_DAYS:'+Y);
Refer the below link.
https://stackoverflow.com/questions/70631498/custom-label-value-not-working-in-soql-query

If this helps, Please mark it as best answer.

Thanks!!