0

I created a custom label AccRecordTypes in that I added 2 record type Names as Partner Account, Customer Account.

In my class I am trying to fetch Account records that has record type name as Partner or customer Account. But when the custom label has only single record type name Partner Account or Customer Account it is fetching the records otherwise the list is coming as null even though we have some records. Not sure what I am missing here, can anyone please guide me?

enter image description here

String recordtypes = System.Label.AccRecordTypes;
    Set<String> AccRecTypeSet = new Set<String>();
    if(recordtypes != null)
    {
        for(String str : recordtypes.split(','))
        {
            AccRecTypeSet.add(str);
        }
    }
    System.debug('AccRecTypeSet-->'+AccRecTypeSet);// debug shows as {Partner Account, Customer Account}
        List<Account> accl = [Select Id,Name,RecordType.Name from Account where RecordType.Name IN:AccRecTypeSet];
    system.debug('===='+accl);

1 Answer 1

0

It's likely due to the extra space you have after the comma. Also, you can write this in about two lines of code. I've modified the below example so it won't care if there's extra spaces.

Set<String> accountRecordTypes = new Set<String>(Label.AccRecordTypes.split(',\\s*'));
Account[] acc1 = [SELECT Name,RecordType.Name FROM Account WHERE RecordType.Name + :accountRecordTypes];

As a side note, it's probably better to use DeveloperName, which doesn't have spaces.

1
  • Thank you so much.
    – SF_Learner
    Commented Jul 23, 2021 at 20:02

You must log in to answer this question.

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