+ Start a Discussion
Lance BrownLance Brown 

Trigger look up from text field both on Account page

Trying to write a trigger to copy a custom zip code field on the account page to a lookup of a custom object.  

the custom zip code feild is Equipment_Zip_Postal_Code__c

The lookup field also on the account page is TZ__c

The Custom Object API name is TZDatabase__c

with a field name of Name that need to be copied over

So far I'm getting a Invalid bind expression type of Schema.SObjectField for colimn of type String.

Any help would be GREAT

trigger TZ on Account (after update) {
    String AccountId;
    String TextFieldValue;
    for(Account acc : Trigger.New)
        AccountId = acc.id;
        TextFieldValue = acc.Equipment_Zip_Postal_Code__c;
    list<TZDatabase__c> TZDatabaseList = new list<TZDatabase__c>();
    TZDatabaseList = [SELECT id, Name FROM TZDatabase__c WHERE Name =: account.Equipment_Zip_Postal_Code__c ];
    if(TZDatabaseList.size() > 0)
        for(TZDatabase__c acc : TZDatabaseList)
            account.TZ__c = Account.Equipment_Zip_Postal_Code__c;
               update TZDatabaseList;
        catch(Exception ex)
             //add error message
Probably you should do something like this
account.TZ__c = TextFieldValue;

instead of

account.TZ__c = Account.Equipment_Zip_Postal_Code__c;
By the way there are lot many issues with your code
  • Code doesnt look like is bulkified and will populate the values for only last account record

Lance BrownLance Brown
Any suggestions on how to make it  bulkified?

David "w00t!" LiuDavid "w00t!" Liu
That's a big topic but you can learn how to bulkify things here!

My site!