0
Id recordTypeId = Schema.SObjectType.Lead.getRecordTypeInfosByDeveloperName().get('ZS_Lead').getRecordTypeId();
System.debug('The FS Lead record Type Id is ' +recordTypeId );  // 011kjhjkhjkhkh


List<Lead> leads  = [Select Id, Name, LeadSource, OwnerId 
                 From Lead
                 Where RecordTypeId = recordTypeId AND CreatedDate = Today];   // error
                //Where RecordTypeId = '011kjhjkhjkhkh' AND CreatedDate = Today --- works

enter image description here

1
  • P.S. RecordType.Name is indexed, so you technically can just write WHERE RecordType.Name = 'ZS_Lead' and skip the describe call. It's worth knowing when you need to describe and when you don't (and here, you don't).
    – sfdcfox
    Mar 9 at 22:46
3

Your missing the colon : when referencing the variable in your query.

That line should read Where RecordTypeId = :recordTypeId AND CreatedDate = Today];

See https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL_variables.htm

1
  • Thank you for pointing that out!. Mar 9 at 22:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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