I'm using a Custom Metadata type to hold the counter for a round robin. The following code provokes an error:
Account_Managers_List__mdt AMList = Account_Managers_List__mdt.getInstance('m0717000000DDIYAA4');
Which causes this error: DealTrigger: execution of BeforeUpdate caused by: System.TypeException: Unsupported sobject type and/or version Class.DealTriggerHandler.beforeUpdate: line 57, column 1 Class.TriggerFactory.execute: line 46, column 1
Any thoughts on what's causing Unsupported Sobject type? When I put this line in execute Async it works fine. in fact, the whole counter works perfect in execute Async, but when I update the deal object it returns this error.
This is the DealTrigger
public void beforeUpdate()
{
System.debug('In am in beforeUpdate'+DealTriggerHandler.firstRun);
Map<Id, Deal__c> oldMap = (Map<Id, Deal__c>)trigger.oldMap;
Map<Id, Deal__c> newMap = (Map<Id, Deal__c>)trigger.newMap;
for(Deal__c deal : (List<Deal__c>)Trigger.New) {
//if(deal.StageName__c == 'Contracts Approved') {
if((oldMap.get(deal.Id).StageName__c != newMap.get(deal.Id).StageName__c)
&& newMap.get(deal.Id).StageName__c == 'Contracts Approved'
&& oldMap.get(deal.Id).Contracts_Approved_Date__c == null) {
deal.Contracts_Approved_Date__c = System.today();
//Begin Intro Closing Call Agent Assignment Counter
//Get count from Custom Settings
IntroClosingCallAgentAssignCounter__c AssignmentCount = IntroClosingCallAgentAssignCounter__c.getOrgDefaults();
integer Count = Math.round(AssignmentCount.CounterNumber__c);
//Get list of Account Managers
Account_Managers_List__mdt AMList = Account_Managers_List__mdt.getInstance('m0717000000DDIYAA4');
//Serialize and map a copy to work from
String str = JSON.serialize(AMList);
Map<String, Object> AMObjMap = (Map<String,Object>)JSON.deserializeUntyped(str);
//Remove fluff
AMObjMap.remove('DeveloperName');
AMObjMap.remove('Id');
AMObjMap.remove('Label');
AMObjMap.remove('Language');
AMObjMap.remove('MasterLabel');
AMObjMap.remove('NamespacePrefix');
AMObjMap.remove('attributes');
AMObjMap.remove('QualifiedApiName');
//Get a list from the remaining values
List<Object> AccountManagers = AMOBjMap.values();
//Take the Modulus and round it
integer RefModulus = Math.round(Math.mod(Count, AccountManagers.size()));
//Get the account manager as an Id
Id i = Id.valueOf(JSON.serialize(AccountManagers[RefModulus]).replaceAll('"',''));
//Increment
AssignmentCount.CounterNumber__c=Count+1;
//Assign
deal.Intro_Closing_Call_Agent__c = i;
//Update Counter
update AssignmentCount;
}
else if((oldMap.get(deal.Id).StageName__c != newMap.get(deal.Id).StageName__c)
&& newMap.get(deal.Id).StageName__c == 'Contracts Approved') {
deal.Last_Contracts_Approved_Date__c = System.now();
}
}
}
this is the factory
public static void createHandler(Type t)
{
// Get a handler appropriate to the object being processed
ITrigger handler = getHandler(t);
// Make sure we have a handler registered, new handlers must be registered in the getHandler method.
if (handler == null)
{
throw new TriggerException('No Trigger Handler found named: ' + t.getName());
}
// Execute the handler to fulfil the trigger
execute(handler);
}