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
nnknnk 

Trigger to update a field based upon the value in the look up

Hi,

 

I want update a currency field on Account to be in sync with the Account's Parent's Territory(Custom Object) Currency. Account has Territory as the lookup field.

 

I am not getting any errors but it is not working. If i see the system log it shows that the currency field is correctly assigned. Any thoughts?

 

My Code:

 

trigger UpdateCurrencyISOCode on Account (after insert, before update){


        for(Account a :  [Select id, CurrencyISOCode, Parent.Territory__r.CurrencyISOCode from account where id IN : trigger.new])
        {
                      {a.CurrencyISOCode= a.Parent.Territory__r.CurrencyISOCode;}
         
        }

 

 

minkeshminkesh

Hello nnk,

                   after assinging the currencyISOcode are you updating the account ? and you should use before insert before update.

minkeshminkesh

Hello,

       one More suggetion is that you can do it using workflow also so try to do it with workflow.

nnknnk

We cannot use workflow as it does not have the option to update currency field, secondly if i use the after update event it goes in to recurssive loop.

minkeshminkesh

Hello nnk,

                   i know that it will go to loop but you can put static class there and avoid the looping.

                   refer this link-- http://developer.force.com/cookbook/recipe/controlling-recursive-triggers

 

nnknnk

we cannot have e dml operation if we are using before update hence i cannot update th assignment of currency code.