0

Is there a way to retrieve data from custom settings using getAll() on the name of the custom setting that is passed dynamically? Eg : If I pass CS1__c as custom setting name -> it should give data of CS1 If I pass CS2__c as custom setting name -> it should give data of CS2 so on

Thanks in advance.

  • Are these two different custom setting objects? are they essentially the same but with different data in them? – Nick Cook Aug 24 '16 at 5:17
  • Those are two different custom setting objects – user2689798 Aug 24 '16 at 5:26
1

I don't think there is a Salesforce magic method that will do that for your. Your best option I think is to build your own method using Database.query. At the end of the day a custom setting is an object which you can query. So you will have something like :

String objectName = 'CS1__c';
List<SObject> records = Database.query('SELECT ID FROM '+objectName); 

The only thing you will need to do is to get dynamically all the fields of the selected custom setting using Schema.getGlobalDescribe.

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.