You need to sign in to do that
Don't have an account?
BPOOR
Trigger invocation Error
Need some help on an issue that I am currently facing in a trigger.
In the OpportunityTrigger, I am trying to assign the Account Owner as the owner of the opportunity if the opportunity has specific list of record types. My sample code is below.
RecordType__c is a custom field on the Opportunity object that contains the name of the Record type.
However, when I test this code, I am getting the below error at line where strAccountOwnerId is getting assigned from the map.
Can someone help?
In the OpportunityTrigger, I am trying to assign the Account Owner as the owner of the opportunity if the opportunity has specific list of record types. My sample code is below.
List<String> strRecordTypes = new List<String>() {'Rtype 1', 'Rtype 2', 'Rtype 3'}; List<Id> lstAccountIds = new List<Id>(); Map<Id, Id> mapAccountOwnerIds = new map<Id, Id>(); for (Opportunity oppty : trigger.new) { if(oppty.AccountId != null) { lstAccountIds.add(oppty.AccountId); } } for (Account acc : [Select a.Id, a.OwnerId FROM Account a Where Id in :lstAccountIds AND a.Owner.IsActive = true]) { mapAccountOwnerIds.put(acc.Id, acc.OwnerId); } for (Opportunity oppty : trigger.new) { String strAcctOwnerId = ''; if (oppty.AccountId != null && MapSupportedRecType.size() > 0 && strRecordTypeNames.contains(oppty.RecordType__c)) { **strAcctOwnerId = mapAccountOwnerIds.get(oppty.AccountId);** if(strAcctOwnerId != null && strAcctOwnerId !='') { oppty.OwnerId = strAcctOwnerId; } } }
RecordType__c is a custom field on the Opportunity object that contains the name of the Record type.
However, when I test this code, I am getting the below error at line where strAccountOwnerId is getting assigned from the map.
> USER_DEBUG []|ERROR|==========> Trigger New Invocation is [2] which exceeds the limit of [2]. The logic will not run.
Can someone help?
Have you checked if there is any other trigger that is getting invoked when this is trigger is running??
Regards,
Anutej
The root cause of the issue appears to be using the RecordType__c which is the value of RecordType.DeveloperName where as the List has the names of the Recordtype. Once I changed the IF condition to use the variable oppty.RecordTypeName__c (another custom field on the Opportunity object which stores the RecordType.Name), the issue is resolved.
I am still not sure how the static variable for the Apex method was incremented before of the above code. If I find the issue, I will post an update.