I'm writing a Apex class to auto delete Case records of record type claims and service failure with created date older than 6 Years here is the code. But i'm failing to Refer the record type in the code can i get some help on it

global class DeletecaseBatchClass implements Database.Batchable<sObject>{
    global DeletecaseBatchClass(){

    global String query;
    global Database.QueryLocator start(Database.BatchableContext BC) {
        query = 'SELECT Id, createddate, RecordType.Name from case where createddate < date.today()-2190 AND RecordType.Name IN ()';
        return Database.getQueryLocator(query);

    global void execute(Database.BatchableContext BC, List<case>scope){
        delete scope;

    global void finish(Database.BatchableContext BC){

1 Answer 1


You can refer to them in the same way you do any other property. If you wish to obtain an Id, you can do it this way:


(Note that uses the API Name, not the label)

If you're writing a query, you can do it this way:

... RecordType.DeveloperName IN ('AAA','BBB')

I recommend you use DeveloperName and not Name. RecordType labels can change often but the DeveloperName should seldom, if ever, do.

PS: I noticed you are inside of a string, don't forget to escape your inner quotes. For example, in the code above, you would write (\'AAA\',\'BBB\')

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