+ Start a Discussion
F SmoakF Smoak 

Update Address as Account field value updates

Hi Guys,

I have written a trigger. The objective is if No See on Account is TRUE, Zip code of address appends to Address name and in turn zip code updates to 'nosee'. My trigger is almost working with one small defect that is address name is getting appended to zip numeric value and new value ie, no see. How doI correct it to display only old zip numeric value . Please find code below:

trigger TKD_Update_Address_Zip_Code on Account (after update) {
Set<Id> accountIds = new Set<Id>();
for(Account newAcc: Trigger.new){
    Account oldAcc = Trigger.oldMap.get(newAcc.Id);

    if(oldAcc.TKD_No_See__c != newAcc.TKD_No_See__c && newAcc.TKD_No_See__c == true) {
     List<Address_vod__c> addressAddressLine = [select Zip_vod__c, Name from Address_vod__c where Account_vod__c in :accountIds];
     for(Address_vod__c AddressLine:addressAddressLine){
        AddressLine.Name= AddressLine.Name + ',' + AddressLine.Zip_vod__c;        
    if(addressAddressLine.isEmpty()== false)
        update addressAddressLine;
    List<Address_vod__c> addressZipCodes = [select Zip_vod__c from Address_vod__c where Account_vod__c in :accountIds];
         for(Address_vod__c zip:addressZipCodes){
     if(addressZipCodes.isEmpty()== false)
        update addressZipCodes;
Vivek PawarVivek Pawar
can you please tell What is field type of zip.Zip_vod__c  ... it should be text so u can replace it
F SmoakF Smoak
Yes zip field is a text field.

Currently with this code, if zip=123,addr name = abc then as per my code its showing
add name=abc,123,nosee and zip = nosee. I want addr nameupdated as abc,123