• Chris Barry
  • NEWBIE
  • 25 Points
  • Member since 2008

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

Feels like I'm really close... 

 

I'm still struggling with trying to populate a lookup field to another table based on the value in a text field.

 

I have...

 a map of accounts with their associated scrubbed zip-code ("accountmap")

 a set of unique scrubbed zip-codes ("accountzips")

 a map of zip codes ("zipcodes")

 

The code compiles, but fails on execution:

        a.ZipId__c = zipcodes.get(accountmap.get(a.id)).id; 

 

Error:  "Apex trigger PopZipId caused an unexpected exception, contact your administrator: PopZipId: execution of BeforeUpdate caused by: System.StringException: Invalid id: 10041"

 

Full trigger is shown below.  Thanks for any/all guidance.  I'm pulling my hair out.

 

//  Set<string> accountzips = new Set<string>();

trigger PopZipId on Account (before insert, before update) {

    String billzip;
    integer dashpos;

    Map<id, string> accountmap = new Map<id, string>();
    Set<string> accountzips = new Set<string>();

    for (Account a : Trigger.new) {
        // only include accounts being inserted or where the BillingPostalCode is changing
        if (
                System.Trigger.isInsert
            || (System.Trigger.isUpdate && a.BillingPostalCode != System.Trigger.oldMap.get(a.Id).BillingPostalCode)
           )
        {
            // remove leading zeros, remove zip+4
            if (a.BillingPostalCode != Null) {
                dashpos = (a.BillingPostalCode + '-').indexof('-');
                billzip = (a.BillingPostalCode.substring(0,Dashpos)).replaceAll('^0+(?!$)','');
                //if we accidentally nulled out the zip code, use the '0' zip code:
                if (billzip == Null) {
                    billzip = '0';
                }
            } else {
                billzip = '0';
            }
        accountmap.put(a.id, billzip);
        accountzips.add(billzip);
        }
    } 
   
    Map<id, zip__c> zipcodes = new Map<id, zip__c>([Select id, name from zip__c where name in :accountzips]);

    for (Account a : Trigger.new) {
        //a.ZipId__c = 'a0kT0000000K7dI';     
        a.ZipId__c = zipcodes.get(accountmap.get(a.id)).id; 
    }
}

 

Pete

I'm trying to get this to work...

<apex:page standardController="Account" showHeader="true" tabStyle="account" > {!$CurrentPage.parameters.tabFocus} <br/><br/> <apex:tabPanel switchType="client" escape="false" selectedTab="{!$CurrentPage.parameters.tabFocus}" id="tabPanel" > <apex:tab label="Details" name="AccDetails" id="tabdetails"> <apex:detail relatedList="false" title="true"/> </apex:tab> <apex:tab label="Contacts" name="Contacts" id="tabContact" > <apex:relatedList subject="{!account}" list="contacts" /> </apex:tab> </apex:tabPanel> </apex:page>

 ...by requesting this URL: https://c.cs1.visual.force.com/apex/TabbedAccount?id=15DigitAccountId&tabFocus=Contacts

I know {!$CurrentPage.parameters.tabFocus} works, because it displays "Contacts".
And the selectedTab attribute works great if I hard-code it to "Contacts".

But the combo does nothing. Is this disabled because of Cross site scripting attacks? Or am I missing something? Any help appreciated.

At the end of the day, I'm trying to set the focus of a tab in a tab panel in this VF page when returning from a different page in the app.

Thanks,

cb
Message Edited by Chris Barry on 03-18-2009 12:10 PM

Feels like I'm really close... 

 

I'm still struggling with trying to populate a lookup field to another table based on the value in a text field.

 

I have...

 a map of accounts with their associated scrubbed zip-code ("accountmap")

 a set of unique scrubbed zip-codes ("accountzips")

 a map of zip codes ("zipcodes")

 

The code compiles, but fails on execution:

        a.ZipId__c = zipcodes.get(accountmap.get(a.id)).id; 

 

Error:  "Apex trigger PopZipId caused an unexpected exception, contact your administrator: PopZipId: execution of BeforeUpdate caused by: System.StringException: Invalid id: 10041"

 

Full trigger is shown below.  Thanks for any/all guidance.  I'm pulling my hair out.

 

//  Set<string> accountzips = new Set<string>();

trigger PopZipId on Account (before insert, before update) {

    String billzip;
    integer dashpos;

    Map<id, string> accountmap = new Map<id, string>();
    Set<string> accountzips = new Set<string>();

    for (Account a : Trigger.new) {
        // only include accounts being inserted or where the BillingPostalCode is changing
        if (
                System.Trigger.isInsert
            || (System.Trigger.isUpdate && a.BillingPostalCode != System.Trigger.oldMap.get(a.Id).BillingPostalCode)
           )
        {
            // remove leading zeros, remove zip+4
            if (a.BillingPostalCode != Null) {
                dashpos = (a.BillingPostalCode + '-').indexof('-');
                billzip = (a.BillingPostalCode.substring(0,Dashpos)).replaceAll('^0+(?!$)','');
                //if we accidentally nulled out the zip code, use the '0' zip code:
                if (billzip == Null) {
                    billzip = '0';
                }
            } else {
                billzip = '0';
            }
        accountmap.put(a.id, billzip);
        accountzips.add(billzip);
        }
    } 
   
    Map<id, zip__c> zipcodes = new Map<id, zip__c>([Select id, name from zip__c where name in :accountzips]);

    for (Account a : Trigger.new) {
        //a.ZipId__c = 'a0kT0000000K7dI';     
        a.ZipId__c = zipcodes.get(accountmap.get(a.id)).id; 
    }
}

 

Pete