i have custom object State and two field inside it StatesName and StatesCode . i want to write apex code in class that i write statename and return i get state code with help of soql . please solve my query ?
This can be achieved by creating the two fields as Picklists and created the dependent picklist as Statescode.Otherwise,you can update the field using the trigger based on the StateName field before insert function.
Sample code as follows:
trigger AccountTrigger on Account (before insert) {
for (Account a : Trigger.new) {
if(a.StateName.contains('United States')) {
a.StateCode='USA';
}
}
}
Kindly let me know if it helps you and close your query by marking it as best answer so that it can help others in the future.
Hi Shrisha Actually i want write soql in apex class for the custom object 'State ' . it contains two custom fields 'StateName ' and 'StateCode' . when i write stateCode in exnonymous window then In return i get StateName .
for example i wrire 'UP' then i will get 'Uttar Pradesh '. thank you
Greetings!
This can be achieved by creating the two fields as Picklists and created the dependent picklist as Statescode.Otherwise,you can update the field using the trigger based on the StateName field before insert function.
Sample code as follows:
Kindly let me know if it helps you and close your query by marking it as best answer so that it can help others in the future.
Warm Regards,
Shirisha Pathuri
Actually i want write soql in apex class for the custom object 'State ' . it contains two custom fields 'StateName ' and 'StateCode' . when i write stateCode in exnonymous window then In return i get StateName .
for example i wrire 'UP'
then i will get 'Uttar Pradesh '.
thank you