You need to sign in to do that
Don't have an account?

Apex governor limit warning
I could use some help solving an Apex governor limit warning issue. I have two problems. First, I don't know for sure which trigger or class is causing the error (but I think I know) ... and ... I don't know how to fix the trigger (assuming I'm correct about the culprit).
Assuming I'm right, the trigger below is the culprit. In short, its simple purpose is to set the account record type based on a custom formula field that derives its values from a custom picklist field. The trigger works just as I expect it to. However, when I try to use API tools like dataloader, I get the governor limit warnings. I have it set up to send me an email until I get it solved. If possible, please give guidance on how I can determine for sure what is the cause, and if you agree the below trigger is the cause, any assistance in 'bulkifying' this trigger is much appreciated.
trigger SET_ACCOUNT_RTYPE_TRIGGER2 on Account (before insert, before update) {
Map<String, Id> typeMap = New Map<String, Id>();
for(RecordType RT: [Select DeveloperName, Id From RecordType Where sObjectType = 'Account']) {
typeMap.put(RT.DeveloperName, RT.Id);
}
for (Account ACT : trigger.new) {
id recid = typeMap.get(ACT.Rtype_FM__c);
recordtype rectype = [select id, developername from recordtype where id=:recid];
ACT.RecordTypeid = rectype.id;
}
}
Assuming I'm right, the trigger below is the culprit. In short, its simple purpose is to set the account record type based on a custom formula field that derives its values from a custom picklist field. The trigger works just as I expect it to. However, when I try to use API tools like dataloader, I get the governor limit warnings. I have it set up to send me an email until I get it solved. If possible, please give guidance on how I can determine for sure what is the cause, and if you agree the below trigger is the cause, any assistance in 'bulkifying' this trigger is much appreciated.
trigger SET_ACCOUNT_RTYPE_TRIGGER2 on Account (before insert, before update) {
Map<String, Id> typeMap = New Map<String, Id>();
for(RecordType RT: [Select DeveloperName, Id From RecordType Where sObjectType = 'Account']) {
typeMap.put(RT.DeveloperName, RT.Id);
}
for (Account ACT : trigger.new) {
id recid = typeMap.get(ACT.Rtype_FM__c);
recordtype rectype = [select id, developername from recordtype where id=:recid];
ACT.RecordTypeid = rectype.id;
}
}
I think this query ([Select DeveloperName, Id From RecordType Where sObjectType = 'Account']) is returning too much records. You must Start to do "SOQL for loops" (its a best practice):
for(List<RecordType> RTS: [Select DeveloperName, Id From RecordType Where sObjectType = 'Account']) {
...
}
i hope it helps! :D