am trying to read values from few fields (standard shipping address text and dropdown fields in Account object)in a before insert Account trigger. but to my surprise, when am trying to read values from drop down fields am getting null values while inserting a record. but inserted record shows valid values in drop down lists.
while updating a record it works as expected
below is my code,
trigger [assignLocation] on Account (before Insert, before Update) {
for (Account account : Trigger.new) {
street.add(account.ShippingStreet);
city.add(account.ShippingCity);
state.add(account.ShippingState);
zipCode.add(account.ShippingPostalCode);
country.add(account.ShippingCountry);
}
}
System.debug('--streetstreet --: ' + street ); // am getting desired value
System.debug('--citycity --: ' + city ); // am getting desired value
System.debug('--statestate --: ' + state ); // this is drop down field, in trigger. It shows null while debugging when inserting a record.
System.debug('--zipCode --: ' + zipCode ); // am getting desired value
System.debug('--countrycountry --: ' + country ); // this is drop down field, in trigger it shows null while inserting a record.
as i have to update a field before inserting/updating a account record .I have to use BEFORE INSERT BEFORE UPDATE TRIGGER,
Thank you
street
,city
,state
,zipCode
andcountry
list variables defined at in your trigger and why are you adding the values from trigger.new to them? I assume they must be lists since your adding values to them from trigger.new. – crmprogdev Sep 18 '15 at 18:54