You need to sign in to do that
Don't have an account?
sfdcIs
List<RecordType>
I am trying to compare the account recordtype name to the zone record type name from an Account sObject. If it matches than further processing should be done. I tried it this way but realzied the hard way that each object have their own record type id. What is the best way to match the record type name?
List<Zone__c> zList = [select recordtypeid from Zone_c];
List<RecordType> rtList = [select id, name from RecordType ];
for(Account a: aList)
{
if( a.recordtypeid ==zList.get(i).recordtypeid )
{
// some processing
}
Remove :(colon) after IN, it works.
sObjectType Column on RecordType expects a string format . so, it should be enclosed in single quotes.
All Answers
Hi !
Try these one
Map<Id,RecordType> Rt_map = new Map<Id,RecordType>([Select id,Name from RecordType where sObjectType IN: ('Account','Zone__c')]);
for(Account a: aList){
for(Zone__c z: zList){
if(Rt_map.get(a.recordtypeid).Name == Rt_map.get(z.recordtypeid).Name){
//do Task
}
}
Try Avoiding as much as for loops you can , as its a bad practise. Instead place them in a map and access it, saves Processing time
Using MAP totally makes sense. I think it will work soon but I keep getting a syntax error on this, says expecting ) found ','
do the sObjects need to be wrapped around single quotes?
Map<Id,RecordType> Rt_map = new Map<Id,RecordType>([Select id,Name from RecordType where sObjectType IN: ('Account','Zone__c')]);
Remove :(colon) after IN, it works.
sObjectType Column on RecordType expects a string format . so, it should be enclosed in single quotes.
try putting commented code inside of catch block. so that if any exception arises,your exception will be logged.
something like this
catch (Exception e)
{
System.debug('There was an error!');
Error_Log__c eLog = new Error_Log__c();
List<Error_Log__c> eLogList = new List<Error_Log__c>();
for (Integer iex = 0; iex < 2; iex++)
{
eLog.Description__c = e.getDmlMessage(iex);
eLogList.add(eLog);
}
try{
insert eLogList;
}
catch(exception e){
system.debug('There is an error while saving);
}
}