You need to sign in to do that
Don't have an account?
Marty Dorren
does map exsist?
I have triggers that reach out to other custom objects subsequently firing their triggers. at the beginning of each trigger for each object, I create a map at the begining of each trigger containing all recordtypes in case needed, which is not usually a problem however, when these triggers start firing one another, I run the risk of reaching my SOQL limit.
The simple solution for me would be to only create the map if it doesn't exist from a previously called trigger.
Is there a way that I can test for the existence of a map before creating it again?
Thanks,
Marty
The simple solution for me would be to only create the map if it doesn't exist from a previously called trigger.
Is there a way that I can test for the existence of a map before creating it again?
Thanks,
Marty
Hello,
I am not sure if I got it right but if you are trying to persist a Map across your triggers that it is not possible. And if you are getting these RecordTypes by a SOQL statement you should consider using the Schema.
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_class_Schema_RecordTypeInfo.htm
I would be something like this:
Map<String, Schema.RecordTypeInfo > rts = yourCustomSObject.sObjectType.getDescribe().getRecordTypeInfosByName();
Id rtId = rts.get('Record Type Name').getRecordTypeId();
Regards
Thanks for the quick reply. It seems that the describe method is more granular in it's execution as opposed to one soql query such as:
string RecTypeMapKey = null;
Map<string,Id> RecTypeMap = new Map<string,Id>();
list<Recordtype> RecTypeList = [select Id,name,SObjectType from RecordType where isactive = true];
for(RecordType RecTypeLoop : RecTypeList){
RecTypeMapKey = RecTypeLoop.name+RecTypeLoop.SObjectType;
RecTypeMap.put(RecTypeMapKey,RecTypeLoop.Id);
}
So I suppose my next question would be:
Can I persisist a variable across my triggers?
If so, I could could put the above code at the beginning of my triggers inside an IF condition asking if the variable was true or false:
if(RecTypeStaticVar == false){
//Above code
}
Am I making any sense here? :)
Thanks
I am afraid you cannot persist variables between triggers as static variables in Salesforce does not behave as you are expecting.
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_static.htm (https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_static.htm" target="_blank)
Furthermore, using the schema you can also check if a recordtype is active without querying it using SOQL.
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_class_Schema_RecordTypeInfo.htm#apex_Schema_RecordTypeInfo_isAvailable (https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_class_Schema_RecordTypeInfo.htm#apex_Schema_RecordTypeInfo_isAvailable" target="_blank)
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.