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
KaityKaity 

Need help to write the trigger

Hi experts,
I've a requirement as follows:
I have a custom Setting where I have mentioned the State code of all states:Like-
Sate---- Code
AP------- 001
UP------- 002
JK ------- 003
HD------- 004

Whenever a new account is created, based upon the state code of the state, a field in Account namely 'StateCode__c' will be updated.

Thanks,
Kaity

 
James LoghryJames Loghry
Hi Kaity,

These forums are not for free consulting, but rather help when questions around code or declaritive solutions come up.   You're on the right track as far as thinking of a solution (another potential is to use a process that kicks off a flow), but I suggest you either go to http://trailhead.salesforce.com to learn how to write a trigger, or engage with a Salesforce partner to work through the trigger with you / your business. 
KaityKaity
I understand and know the way. But this is a developer forum where everybody ask any solution if any developer got stuck anywhere. Thanks!
HARSHIL U PARIKHHARSHIL U PARIKH
Hi Kalty,
From my understanding you can accomplish this without an apex code though.

CASE( State_Name__c , 
'AP', '001', 
'UP', '002', 
'JK ', '003', 
'HD', '004', 'State Name Is Not Given Yet. ')
 
KaityKaity
Hi Govind,
Thank you for your reply.  Basically, I wanted to have a relationship between Account and State which needs to be tracked in StateCode__c field in Account.
There are records created in  State object as follows:

Sate---- Code
AP------- 001
UP------- 002
JK ------- 003
HD------- 004

If a Account has State field as AP, then StateCode__c in Accont will be updated by 001. So, for this I need to write a trigger. Thanks!