• Josh Harsh
  • NEWBIE
  • 0 Points
  • Member since 2014
  • Concept Services, LTD

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 14
    Replies
I am trying to develop a visualforce page that allows a user to see the Companies Website without having to leave the Account page. Is this possible?
Hello,

Below are a trigger and its test class. Understanding that the coverage needs to be 75% in order to send it to production, I seem to be stuck with my code, and I am hoping that someone may be able to push me in the right direction.


trigger updatezipcode on Account (before update, before insert) {
    List<String> BillingPostalCodes = new List<String>();
   
    for (Account a:Trigger.new){
        BillingPostalCodes.add(a.BillingPostalCode.substring(0,5));
    }

    List <Zip_Code__c> ZipCodeList = [Select ID, Name from Zip_Code__c where Name in :BillingPostalCodes];

    for (Integer i = 0; i <Trigger.new.size(); i++){
        if (ZipCodeList.size() > 0 && Trigger.new[i].BillingPostalCode.substring(0,5) !=null){
                        for (Zip_Code__c z:ZipCodeList){
                if (Trigger.new[i].BillingPostalCode.substring(0,5) == z.name){
                        Trigger.new[i].Zip_Code_Territory__c = z.ID;

                                }
                        }
        }
        else{
        Trigger.new[i].Zip_Code_Territory__c = null;
        }
       
    }
}

@isTest
private class TestZip {
    static testMethod void testZipChange() {
        Account[] Accounttest = new Account[]{
         new Account(Name ='Tester1', BillingPostalCode = '44281'),
         new Account(Name ='Tester2', BillingPostalCode = '44282'),
         new Account(Name ='Tester3', BillingPostalCode = '44283'),
         new Account(Name ='Tester4', BillingPostalCode = '44284'),
         new Account(Name ='Tester5', BillingPostalCode = '44285'),
         new Account(Name ='Tester6', BillingPostalCode = '44286',OwnerId = '005C0000006nFc6')
         };
         insert Accounttest;
           
        Test.startTest();
        Accounttest[0].BillingPostalCode = '44281';
        update Accounttest;
        Test.stopTest();
       
        Accounttest = [SELECT id, BillingPostalCode, Zip_Code_Territory__c FROM Account WHERE id IN:Accounttest];


    }
}

The bolded area in the trigger is what is not covered in the class. 

Thank you for any help!
I am hoping someone can help me out with this, I have a custom object called Zip Code and it stores all Zip Codes within the United States. I would like to create a trigger that takes the first 5 digits of a US zip code and places it in a lookup field matching that 5 digit billing zip code.

I do not really have much knowledge with apex and was hoping someone would be able to point me in the right direction or possibly someone has already accomplished this sames situation.

Thank you for your help!