0

I am not able to retrieve all values from custom settings object.My custom settings object API name is Products_ID_Without_AOP__c.It has a custom field as Products_ID__c with name and value like below.It has currently 4 records.

Name=xyz,Products_ID__c=789;Name=tyui,Products_ID__c=34567;Name=abc,Products_ID__c=123;Name=pqr,Products_ID__c=456;Name=asd,Products_ID__c=5678

I am using below lines to retrieve custom settings object .

List<Products_ID_Without_AOP__c> listCodes = Products_ID_Without_AOP__c.getAll().values();
system.debug('value of all codes ::: '+listCodes );

I am getting below in debug statement :

value of all codes ::: (Products_ID_Without_AOP__c:{LastModifiedDate=2016-09-27 16:06:04, IsDeleted=false, CreatedById=005W0000001dzlzIAA, CreatedDate=2016-09-27 16:06:04, Id=a1YW0000000iBnWMAU, CurrencyIsoCode=CAD, LastModifiedById=005W0000001dzlzIAA, SetupOwnerId=00DW0000008sTVQMA2, Name=xyz, SystemModstamp=2016-09-27 16:06:04, Products_ID__c=789}, Products_ID_Without_AOP__c:{LastModifiedDate=2016-09-27 16:06:36, IsDeleted=false, CreatedById=005W0000001dzlzIAA, CreatedDate=2016-09-27 16:06:36, Id=a1YW0000000iBngMAE, CurrencyIsoCode=CAD, LastModifiedById=005W0000001dzlzIAA, SetupOwnerId=00DW0000008sTVQMA2, Name=tyui, SystemModstamp=2016-09-27 16:06:36, Products_ID__c=34567}, Products_ID_Without_AOP__c:{LastModifiedDate=2016-09-27 16:05:31, IsDeleted=false, CreatedById=005W0000001dzlzIAA, CreatedDate=2016-09-27 16:05:31, Id=a1YW0000000iBnMMAU, CurrencyIsoCode=CAD, LastModifiedById=005W0000001dzlzIAA, SetupOwnerId=00DW0000008sTVQMA2, Name=abc, SystemModstamp=2016-09-27 16:05:31, Products_ID__c=123}, Products_ID_Without_AOP__c:{LastModifiedDate=2016-09-27 16:05:48, IsDeleted=false, CreatedById=005W0000001dzlzIAA, CreatedDate=2016-09-27 16:05:48, Id=a1YW0000000iBnRMAU, CurrencyIsoCode=CAD, LastModifiedById=005W0000001dzlzIAA, SetupOwnerId=00DW0000008sTVQMA2, Name=pqr, SystemModstamp=2016-09-27 16:05:48, Products_ID__c=456}, Products_ID_Without_AOP__c:{LastModifiedDate=2016-09-27 16:06:14, IsDeleted=false, CreatedById=005W0000001dzlzIAA, CreatedDate=2016-09-27 16:06:14, Id=a1YW0000000iBnbMAE, CurrencyIsoCode=CAD, LastModifiedById=005W0000001dzlzIAA, SetupOwnerId=00DW0000008sTVQMA2, Name=asd, SystemModstamp=2016-09-27 16:06:14, Products_ID__c=5678})

But i want to get values of Products_ID__c in list type.Any way to get only Products_ID__c

3

If you just want a collection of the values from one field, you need to loop through the records. You can use Set or List depending on your needs, but I usually find that Set is better suited to the task.

Set<String> productIds = new Set<String>();
for (MySetting__c setting : MySetting.getAll().values())
    productIds.add(setting.ProductIdField__c);

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.