0

I created a Custom Setting to store an Id so I do not have to hard-code it. The custom setting API name is SQUAD_GLOBAL_VALUE_SET_ID__c and is of type 'Hierarchy'. It has 1 field called Squad Picklist ID (api name Squad_Picklist_ID__c) and is of type text(50). I have set the default value of that field to the Id.

When I use:

SQUAD_GLOBAL_VALUE_SET_ID__c SQUAD_GLOBAL_VALUE_SET_ID = SQUAD_GLOBAL_VALUE_SET_ID__c.getInstance('Squad Picklist ID'); I get the error System.InvalidParameterValueException: Invalid SetupOwner for Custom Settings: Squad Picklist ID

When I use: SQUAD_GLOBAL_VALUE_SET_ID__c SQUAD_GLOBAL_VALUE_SET_ID = SQUAD_GLOBAL_VALUE_SET_ID__c.getOrgDefaults(); I do not get any errors, but the value returned is { }.

When I use:

SQUAD_GLOBAL_VALUE_SET_ID__c SQUAD_GLOBAL_VALUE_SET_ID = SQUAD_GLOBAL_VALUE_SET_ID__c.getValues('Squad Picklist ID'); I get the error Invalid SetupOwner for Custom Settings: Squad Picklist ID

Finally, when I run the SOQL Query select Id from SQUAD_GLOBAL_VALUE_SET_ID__c I do not get an error, but it says 'No rows returned' which is strange. I have Googled and tried lots of solutions but nothing works. I think I may have set up the custom setting incorrectly.

enter image description here

2

I recommend you read up on Custom Settings Methods. It covers what you need to understand here in detail.

Hierarchy Custom Settings do not work the way you are trying to use them. You get an instance for the Organization, a Profile, or a specific User. You pass in an Id for any of these values to getInstance, or you can call My_Setting__c.getOrgDefaults().

My_Setting__c orgDefault = My_Setting__c.getOrgDefaults();
My_Setting__c myProfileSetting = My_Setting__c.getInstance(UserInfo.getProfileId());
My_Setting__c myUserSetting = My_Setting__c.getInstance(UserInfo.getUserId());
  • Thank you. I used a custom metadata type instead and it works now – tom_12321 Sep 25 '18 at 22:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.