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
ani123ani123 

Custom setting value update trigger

hi all, can anyone give me sampple code for custom setting trigger .

one record is inserted the field should get update in custom setting

 

bob_buzzardbob_buzzard

Are you looking to update the custom setting from a trigger on an sobject record?

 

If so, you'd just do it like a regular sobject - retrieve the details using SOQL, make the change and then use the update call to save the changes.

ani123ani123

i am getting error while saving record invalid id

bob_buzzardbob_buzzard

Care to post some code?

ani123ani123

can u give me some sample code

bob_buzzardbob_buzzard

This is because you are creating new objects, storing them in a list and attempting to update the list.  You aren't using the existing custom settings that you have retrieved.  You will get an error if you attempt to update a newly created custom setting that doesn't have an id.