• awoelfel
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 10
    Replies

I'm trying a different approach for programming a trigger I need to update a lookup field called Zipcode_Lookup__c on our Account object from a previous post of mine. I used an example from pacstrats. Here is my code:

 

trigger ZipcodeLookup on Account (before insert, before update) {
List<String> BillingPostalCodes = new List<String>();
for (Account a:Trigger.new)
{
BillingPostalCodes.add(a.BillingPostalCode);
}
List <Zip_Code__c> ZipCodeList = [Select Name from Zip_Code__c where Name in :BillingPostalCodes];
for (Integer i = 0; i < Trigger.new.size(); i++)
{
if (Trigger.new[i].BillingPostalCode != null)
{
Trigger.new[i].Zipcode_Lookup__c = ZipcodeList[i].Name;
}
else
{
Trigger.new[i].Zipcode_Lookup__c = null;
}
}
}

 

The jest of it is to populate the Zipcode_Lookup__c custom lookup field on Account with the BillingPostalCode field on Account if it is available. The lookup is to the Name field on a custom object called Zip_Code__c.

 

When I go to update a record (or add one) I recieve this error: ZipCodeUpdate: execution of BeforeUpdate caused by: System.StringException: Invalid id: 32403: Trigger.ZipCodeUpdate: line 12, column 1

 

I've received this Invalid id exception error with a simple version of this trigger also.

 

I would appreciate any advise as I need this lookup field populated to get around the limitations of Account Assignment rules in the Manage Territories Hierarchy.

 

Thank you!

 

 

I am new to trigger writing having only written a few and I haven't found a good example to try and understand how to write this trigger. I am trying to write a trigger to update a lookup field (Zipcode_Lookup__c) on our Account object with the Account BillingPostalCode field if it is populated.

 

Here is what I have so far:

 

trigger territoryZip on Account (after update){
    if(trigger.isUpdate){
    for(Account a : trigger.new){
    a.Zipcode_Lookup__c = Account.getBillingPostalCode ();
    }
   }
  }

 

I've tried various things such as complicated mapping values to this very simple trigger and I consistantly receive Compile Errors with the Zipcode_Lookup__c = Account.BillingPostalCode entries.

 

Here is another version I've tried:

 

trigger

territoryZip onAccount (afterinsert, afterupdate){

 

for (Account acc : Trigger.New){

List<

Account> ListAccount = [SELECT BillingPostalCode from Account where AccountID =: acc.id];

 

for (Accountacc2 : listAccount2){

acc2.Zip_Code_Lookup = acc.BillingPostalCode;

}

updatelistAccount2;

}

}

 

I would appreciate any advice as I would really like to learn this concept of updating lookup fields on the same object.

 

Thank you!

 

I'm trying a different approach for programming a trigger I need to update a lookup field called Zipcode_Lookup__c on our Account object from a previous post of mine. I used an example from pacstrats. Here is my code:

 

trigger ZipcodeLookup on Account (before insert, before update) {
List<String> BillingPostalCodes = new List<String>();
for (Account a:Trigger.new)
{
BillingPostalCodes.add(a.BillingPostalCode);
}
List <Zip_Code__c> ZipCodeList = [Select Name from Zip_Code__c where Name in :BillingPostalCodes];
for (Integer i = 0; i < Trigger.new.size(); i++)
{
if (Trigger.new[i].BillingPostalCode != null)
{
Trigger.new[i].Zipcode_Lookup__c = ZipcodeList[i].Name;
}
else
{
Trigger.new[i].Zipcode_Lookup__c = null;
}
}
}

 

The jest of it is to populate the Zipcode_Lookup__c custom lookup field on Account with the BillingPostalCode field on Account if it is available. The lookup is to the Name field on a custom object called Zip_Code__c.

 

When I go to update a record (or add one) I recieve this error: ZipCodeUpdate: execution of BeforeUpdate caused by: System.StringException: Invalid id: 32403: Trigger.ZipCodeUpdate: line 12, column 1

 

I've received this Invalid id exception error with a simple version of this trigger also.

 

I would appreciate any advise as I need this lookup field populated to get around the limitations of Account Assignment rules in the Manage Territories Hierarchy.

 

Thank you!

 

 

I am new to trigger writing having only written a few and I haven't found a good example to try and understand how to write this trigger. I am trying to write a trigger to update a lookup field (Zipcode_Lookup__c) on our Account object with the Account BillingPostalCode field if it is populated.

 

Here is what I have so far:

 

trigger territoryZip on Account (after update){
    if(trigger.isUpdate){
    for(Account a : trigger.new){
    a.Zipcode_Lookup__c = Account.getBillingPostalCode ();
    }
   }
  }

 

I've tried various things such as complicated mapping values to this very simple trigger and I consistantly receive Compile Errors with the Zipcode_Lookup__c = Account.BillingPostalCode entries.

 

Here is another version I've tried:

 

trigger

territoryZip onAccount (afterinsert, afterupdate){

 

for (Account acc : Trigger.New){

List<

Account> ListAccount = [SELECT BillingPostalCode from Account where AccountID =: acc.id];

 

for (Accountacc2 : listAccount2){

acc2.Zip_Code_Lookup = acc.BillingPostalCode;

}

updatelistAccount2;

}

}

 

I would appreciate any advice as I would really like to learn this concept of updating lookup fields on the same object.

 

Thank you!