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
RajevlsRajevls 

Update a field on opportunity by custom settings

I want to udpate a field on opportunity (Area) . Country is a field on account and related area is mapped in the custom setting (Area Mapping) . How can i use this custom setting to update the field on opportunity

Sonu Sharma.ax1610Sonu Sharma.ax1610

Hi Rajeev,

 

Please write a trigger on Opportunity object and using relationship get the value of field country from Account. After that use SOQL or get methods to retreive value from custom setting and store in a Map.

 

Use this map to get Area by passing Country or similar kind of logic.

 

Regards

Sonu Sharma

Vinit_KumarVinit_Kumar

Try using getall method of Custom settings and fetch the required field value,something like below :- 

 

List<TestCustom__c> mcs = TestCustom__c.getall().values();
Opportunity opp = new Opportunity(Id=opp.id,AccountId=acc.id);

opp.Area__c = mcs[0].Location__c; // here,Location__c is field on custom settings TestCustom__c

 

 

for more methods of custom setings please refer below :

 

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

RajevlsRajevls

It worked .. Thanks

Testing.ax1768Testing.ax1768

Hi Rajeev, 

 

could you please copy your Trigger code and custom setting snapshot.

 

I am new to programming or hardly write code/programs

 

I am also looking for something like this.

 

Thanks and regards

 

Sonu