0

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

1
  • There appears to be code missing from your trigger. Where are street, city, state, zipCode and country 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
1

Since State is a picklist, I am guessing that you have State and Country picklists enabled. If that is the case, then you should use ShippingStateCode and ShippingCountryCode in your trigger.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.