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
Marilyne PMarilyne P 

Dynamic custom field CustomField__{YYYY}__c YYYY can be dynamic

Hello,

I have created a fields like below :
CustomField__2017__c
CustomField__2018__c
CustomField__2019__c
CustomField__2020__c

I want to store values in them but the field should be dynamic

CustomField__{YYYY}__c = 'XXX'

YYYY can be 2017 or 2020, how can i do it in Apex

Thank you for advise 

 
Best Answer chosen by Marilyne P
Arun MKArun MK
Can you try the following: I am assuming this is in Account. If it is not not, you can change the object.
 
Account acc = new Account();
acc.put('CustomField_'+year+'__c', fieldValue);

Please mark my answer was solved if it fixes your issue