I don't write code, so bear with me.

I have a portion of an Apex Class that pulls a list of record types for Cases. However, I need to add a criteria here that then looks at the received records and only includes the records where a certain field is filled in.

Current code:

List<RecordType> residentialRecordTypes = [SELECT Id
                                           FROM RecordType
                                           WHERE (DeveloperName = 'Residential' OR DeveloperName = 'Carpet' OR DeveloperName = 'Manufacturing_Distribution' OR DeveloperName = 'Residential_Service_Claims' OR DeveloperName = 'Mannington_Rubber')
                                           AND SobjectType = 'Case'
                                           AND Id in: casesByRecordTypeId.keySet()
                                           LIMIT 1];

So I essentially need to add something like:

AND Case.Division__c LIKE 'Residential'

Any idea how I would do this?

Thank you!


  • 2
    You're looking at the wrong lines of code. The query you'd need to change is against Case, not RecordType. Although I'll also note that this RecordType query makes no sense and is almost certainly wrong.
    – David Reed
    Aug 29 at 0:12
  • 2
    You can get started with SOQL at Trailhead, but bear in mind that changes to Apex require changes to Apex tests in many cases, so you may need to work with a developer.
    – David Reed
    Aug 29 at 0:13
  • You dont need to query RecordType. It counts your SOQL Limit .So You have to Use Schema. Aug 30 at 6:56

I looked at the code again and found the area where the initial criteria for where "List Case" (not record types) were being pulled from and I added my criteria there instead.

After some testing, it seems to be working.

        List<Case> casesToAssign = new List<Case>();

        for (Case newCase: caseRecordsToUpdate){
            Case oldCase = oldMap.get(newCase.Id);

            if (newCase.Status == 'Claim Authorized' && oldCase.Status != 'Claim Authorized' && newCase.Division__c.CONTAINS ('Residential') && (newCase.RecordType.DeveloperName == 'Residential' || newCase.RecordType.DeveloperName == 'Carpet' || newCase.RecordType.DeveloperName == 'Manufacturing_Distribution' || newCase.RecordType.DeveloperName == 'Residential_Service_Claims' || newCase.RecordType.DeveloperName == 'Mannington_Rubber')){

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.