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
SabrentSabrent 

Account.RecordType.Name

IN SOQL can't we compare Account.RecordType.Name to the contents of a set ?

 

In the code below if i add Account.RecordType.Name in :recordTypeSet  in the Where clause, the query returns 0 rows.

 

Is it a wrong way to check if the Account Recrd Type Name exists in a set?

 

Please advice? Thanks in advance.

 

Set<ID> recordTypeSet = new set<ID>();

List<RecordType> rtList = [Select Id, SobjectType, Name From RecordType  Where SobjectType in ('Lead', 'Account') and Name in ('Supplier Record Type', 'Temp Record Type', 'Supplier Registration', 'Temp Registration')];

system.debug('rtlist size ' +rtlist.size());

for(RecordType rt : rtList){
  recordTypeSet.add(rt.Id);
}

system.debug('record type set ' +recordTypeSet);

public Map<String, String> holdingMap = new Map<String, String>();

holdingMap.put('rova@acme.com','USA');
holdingMap.put('samp@axis.com','USA');


List<Contact> contactUser = [Select Id, Account.Id, Account.Name, Account.CreatedDate, Account.RecordType.Name,Name, Email From Contact WHERE Account.RecordType.Name in :recordTypeSet AND Email in :holdingMap.keySet()];

system.debug('SIZZZZZZZZ ' +contactUser.size());

for(Contact c : contactUser){
system.debug('Record Type ' +c.Account.RecordType.Name);
}

 

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Sean TanSean Tan

It's because you're comparing the record type name to the Ids that you store in the set. Try this:

 

Set<ID> recordTypeSet = new set<ID>();

List<RecordType> rtList = [Select Id, SobjectType, Name From RecordType  Where SobjectType in ('Lead', 'Account') and Name in ('Supplier Record Type', 'Temp Record Type', 'Supplier Registration', 'Temp Registration')];

system.debug('rtlist size ' +rtlist.size());

for(RecordType rt : rtList){
	recordTypeSet.add(rt.Id);
}

system.debug('record type set ' +recordTypeSet);

public Map<String, String> holdingMap = new Map<String, String>();

holdingMap.put('rova@acme.com','USA');
holdingMap.put('samp@axis.com','USA');


List<Contact> contactUser = [Select Id, Account.Id, Account.Name, Account.CreatedDate, Account.RecordType.Name,Name, Email From Contact WHERE Account.RecordTypeId in :recordTypeSet AND Email in :holdingMap.keySet()];

system.debug('SIZZZZZZZZ ' +contactUser.size());

for(Contact c : contactUser){
	system.debug('Record Type ' +c.Account.RecordType.Name);
}

 

All Answers

Sean TanSean Tan

It's because you're comparing the record type name to the Ids that you store in the set. Try this:

 

Set<ID> recordTypeSet = new set<ID>();

List<RecordType> rtList = [Select Id, SobjectType, Name From RecordType  Where SobjectType in ('Lead', 'Account') and Name in ('Supplier Record Type', 'Temp Record Type', 'Supplier Registration', 'Temp Registration')];

system.debug('rtlist size ' +rtlist.size());

for(RecordType rt : rtList){
	recordTypeSet.add(rt.Id);
}

system.debug('record type set ' +recordTypeSet);

public Map<String, String> holdingMap = new Map<String, String>();

holdingMap.put('rova@acme.com','USA');
holdingMap.put('samp@axis.com','USA');


List<Contact> contactUser = [Select Id, Account.Id, Account.Name, Account.CreatedDate, Account.RecordType.Name,Name, Email From Contact WHERE Account.RecordTypeId in :recordTypeSet AND Email in :holdingMap.keySet()];

system.debug('SIZZZZZZZZ ' +contactUser.size());

for(Contact c : contactUser){
	system.debug('Record Type ' +c.Account.RecordType.Name);
}

 

This was selected as the best answer
SabrentSabrent
Thanks!!!!!
Why didn't I think of that ?