function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
amruta_dhumalamruta_dhumal 

How to set object field value using custom setting in apex class

Hi There,

 

I am new to custom settings concept, I've created 1 custom setting with 3 custom fields and added 22 records.

Now I've to write trigger which will call apex class and thru class Account object custom fields should be updated.

 

I've to use custom settings in my class to run in dynamic manner

 

Require suggetions here how to use custom setting in apex class and how to implement.

 

 

Amruta

Best Answer chosen by Admin (Salesforce Developers) 
Vinit_KumarVinit_Kumar

Try using getValues() methods of salesforce.Sample code is below :-

 

List<TestCustom__c> mcs = TestCustom__c.getall().values();//TestCustom__c is custom setting

system.debug('#########' + mcs);
system.debug('********' + mcs[0].Location__c);//Location__c is field on custom setting

 

You can go through the below link to get more methods for custom settings :-

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_custom_settings.htm

All Answers

Vinit_KumarVinit_Kumar

Try using getValues() methods of salesforce.Sample code is below :-

 

List<TestCustom__c> mcs = TestCustom__c.getall().values();//TestCustom__c is custom setting

system.debug('#########' + mcs);
system.debug('********' + mcs[0].Location__c);//Location__c is field on custom setting

 

You can go through the below link to get more methods for custom settings :-

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_custom_settings.htm

This was selected as the best answer
amruta_dhumalamruta_dhumal

Thanks for the reply.....but can we update any object's field using this method?

 

Amruta

Vinit_KumarVinit_Kumar

No,getValues() is method available only for custom settings ,not for standard objects

amruta_dhumalamruta_dhumal

Thanks Vinit, It's worked.....

 

I used the method which you mentioned above and match the criteria,say if(mcs[0].Location__c =='xxx')then update object field value.

 

Amruta