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
                //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('"',''));
                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
  • No error here running the equivalent in my org, looks like it might be related to the DealTriggerHandler/TriggerFactory code you mentioned. Can you share more of that code?
    – Girbot
    Apr 7, 2021 at 14:49
  • @Girbot Sure I'll edit the post adding in the details for the handler and factory
    – PaulyP
    Apr 7, 2021 at 14:52
  • 2
    Check the API version of your trigger and class. Try updating to the latest version.
    – sfdcfox
    Apr 7, 2021 at 15:09

1 Answer 1


getInstance method is a new addition that is supported on api version v51 and upwards. You need to update your DealTriggerHandler class api version to 51.

Here is the relevant documentation

  • After updating to v51.0 everything worked. Thanks!
    – PaulyP
    Apr 7, 2021 at 16:00
  • I run into an api version issue maybe once a year. This time I only wasted an hour on it, thanks to your reminder. Mar 2, 2022 at 3:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .