Skip to main content
I have this existing trigger, which pulls values from the Object Zip Code table and enters them into the Account.  Now we have a new Object called Mexico Zip Code Table and that needs to have a trigger to do the same thing.

 

Here is the mapping required

 

Field Mexico_Postal_Code__c.IC_Channel_Manager__c goes to Account.IC_Account_Manager__c

 

Mexico_Postal_Code__c.AT_SF_FAE__c goes to Account.AT_Account_Manager__c and

 

Mexico_Postal_Code__c.AT_SF_FAE__c.Email goes to Account.Account_Manager_Email__c

 

Here is the current trigger. CAn anyone help?

 

1

 

2

 

3

 

4

 

5

 

6

 

7

 

8

 

9

 

10

 

11

 

12

 

13

 

14

 

15

 

16

 

17

 

18

 

19

 

20

 

21

 

22

 

23

 

24

 

25

 

26

 

27

 

28

 

29

 

30

 

31

 

32

 

33

 

34

 

35

 

36

 

37

 

38

 

39

 

40

 

41

 

42

 

43

 

44

 

45

 

46

 

47

 

48

 

49

 

50

 

51

 

52

 

53

 

54

 

55

 

56

 

57

 

58

 

59

 

60

 

61

 

62

 

63

 

64

 

65

 

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

 

  list<string> zipcodeList = new List<string>();

 

  string zipCode;

 

  for (integer i = 0; i <trigger.new.size(); i++) {

 

    zipcode = trigger.new[i].billingpostalCode;

 

    system.debug('ZipCode: ' + zipcode);

 

    if (zipcode != null) {

 

      integer index = zipcode.indexof('-',0);

 

      if (index != -1) {

 

      zipcode = zipcode.substring(0, index);

 

      }

 

      // could not find delimiter, then try space instead for Canada zip code

 

      else

 

      {

 

       index = zipcode.indexof(' ',0);

 

       if(index != -1) {zipcode = zipcode.substring(0,index);}

 

       }

 

      system.debug('ZipCode after the filter: ' + zipcode);

 

      zipcodeList.add(zipCode);

 

    }

 

  }

 

  system.debug('zipcode size: ' + zipcodelist.size());

 

    if (zipcodelist.size() > 0) {

 

      List<Zip_Code_Table__c> zipCodeTableList = [Select id, name from Zip_Code_Table__c where name in :zipcodeList];

 

    system.debug('Data returned by zipcodeTable : ' + zipCodeTableList.size());

 

    if (zipCodeTableList.size() > 0) {

 

      //Add the zip code into a map

 

      map<string, id> mapZipName= new map<string, id>();

 

    for (integer i=0; i<zipcodeTableList.size(); i++) {

 

      mapZipName.put(zipcodeTableList[i].name, zipcodeTableList[i].id);

 

    }

 

     

 

      //There is possibility that the number of zipcode from account is more than the zipcodeid return from zipcode table

 

      id zipcodeid;

 

      for (integer i = 0; i <trigger.new.size(); i++) {

 

      zipcode = trigger.new[i].billingpostalCode;

 

      if (zipcode != null) {

 

        integer index = zipcode.indexof('-',0);

 

 

 

        if (index != -1) {

 

        zipcode = zipcode.substring(0, index);

 

        }

 

       // could not find delimiter, then try space instead for Canada zip code

 

      else

 

      {

 

       index = zipcode.indexof(' ',0);

 

       if(index != -1) {zipcode = zipcode.substring(0,index);}

 

       }

 

        zipcodeid = mapZipName.get(zipcode);

 

        system.debug('zipcodeid: ' + zipcodeid);

 

        Trigger.new[i].Zip_Code__c = zipcodeid;

 

      }

 

      }

 

    }

 

    }

 

}
1 Antwort
  1. 24. Juli 2014, 17:42
    Hi I would also suggest you to post this question to the developer community for speedy resolution !

     

    This Answers Community is focused on configuration and design questions. Programmatic questions are best submitted to the developer forums at https://developer.salesforce.com where the forums and participants are geared toward programming troubleshooting and support.
0/9000