• Kabb1
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
I have written this trigger and when I write my test class I only get 67% coverage can someone help me write test class for this trigger please.....


trigger regionName2 on Account (before insert,before update) {
set<string> AlpineS=new Set<string>{'3737', '3862', '3691', '3893', '3739', '3699', '3741', '3737', '3741', '3691', '3741', '3737', '3741', '3691', '3737', '3691', '3699', '3740', '3741', '3737', '3738', '3740', '3741', '3740', '3691', '3741', '3697', '3698', '3691', '3744', '3862', '3737'};
set<string> EastGippslandS=new Set<string>{'3885', '3898', '3875', '3889', '3900', '3885', '3888', '3875', '3896', '3898', '3880', '3875', '3888', '3896', '3885', '3890', '3875', '3902', '3898', '3885', '3889', '3875', '3890', '3875', '3889', '3862', '3889', '3898', '3701', '3875', '3895', '3893', '3878', '3895', '3889', '3895', '3875', '3864', '3875', '3898', '3862', '3875', '3902', '3909', '3887', '3865', '3875', '3892', '3889', '3891', '3875', '3904', '3701', '3875', '3885', '3707', '3875', '3886', '3882', '3890', '3887', '3909', '3896', '3888', '3909', '3880', '3898', '3888', '3880', '3895', '3893', '3885', '3903', '3896', '3875', '3893', '3885', '3890', '3864', '3885', '3707', '3890', '3896', '3909', '3885', '3900', '3887', '3891', '3875', '3891', '3890', '3891', '3885', '3885', '3875'};
set<string> AraratRC=new Set<string>{'3377', '3375', '3379', '3361', '3294', '3469', '3293', '3381', '3351', '3381', '3351', '3375', '3351', '3293', '3351', '3381', '3271', '3379', '3377', '3373', '3378', '3272', '3378', '3272', '3378', '3373', '3378', '3377', '3379', '3272', '3378'};
set<string> BallaratC=new Set<string>{'3352', '3350', '3364', '3354', '3351', '3356', '3357', '3363', '3356', '3363', '3355'};
set<string> BanyuleC=new Set<string>{'3081', '3088', '3083', '3084', '3095', '3084', '3095', '3088', '3084', '3081', '3079', '3093', '3085', '3094', '3087'};
set<string> BassCoastS=new Set<string>{'3984', '3937', '3995', '3991', '3992', '3995', '3925', '3984', '3922', '3992', '3979', '3990', '3984', '3996', '3984', '3979', '3951', '3945', '3925', '3951', '3984', '3996', '3923', '3925', '3923', '3922', '3984', '3945'};
set<string> BawBawS=new Set<string>{'3825', '3833', '3823', '3871', '3818', '3233', '3820', '3825', '3821', '3825', '3824', '3822', '3840', '3818', '3821', '3825', '3822', '3833', '3854', '3953', '3981', '3825', '3833', '3816', '3821', '3820', '3833', '3816', '3956', '3988', '3824', '3832', '3831', '3832', '3831', '3821', '3833', '3987', '3833', '3988', '3825', '3950', '3825', '3833', '3824', '3856', '3833', '3953', '3833'};
set<string> BaysideC=new Set<string>{'3193', '3186', '3187', '3192', '3186', '3188', '3190', '3189', '3191'};
set<string> BenallaRC=new Set<string>{'3723', '3670', '3723', '3672', '3669', '3720', '3675', '3723', '3672', '3669', '3720', '3675', '3725', '3723', '3673', '3726', '3725', '3669', '3726', '3675', '3673', '3723', '3675', '3673', '3725', '3675', '3732', '3773', '3725', '3666', '3673', '3723', '3675', '3670', '3673', '3726', '3723', '3672', '3678', '3670', '3673'};
set<string> BrimbankC=new Set<string>{'3021', '3020', '3022', '3012', '3023', '3049', '3023', '3037', '3030', '3020', '3875', '3021', '3036', '3038', '3033', '3036', '3021', '3042', '3023', '3037', '3038', '3043'};
set<string> CampaspeS=new Set<string>{'3561', '3558', '3564', '3623', '3559', '3551', '3559', '3558', '3561', '3571', '3570', '3564', '3558', '3561', '3624', '3566', '3616', '3564', '3565', '3567', '3622', '3621', '3620', '3559', '3561', '3620', '3563', '3564', '3572', '3573', '3612', '3620', '3610', '3557', '3551', '3561', '3564', '3572', '3573', '3561', '3523', '3561', '3564', '3559', '3612', '3564', '3623', '3622', '3620', '3572', '3573', '3575', '3561', '3621', '3551', '3562', '3616', '3612', '3564', '3620', '3621'};
set<string> CardiniaS=new Set<string>{'3782', '3981', '3807', '3808', '3815', '3984', '3978', '3981', '3782', '3781', '3814', '3981', '3808', '3782', '3814', '3783', '3782', '3815', '3984', '3816', '3812', '3159', '3816', '3984', '3781', '3812', '3987', '3809', '3810', '3782', '3810', '3984', '3815', '3980', '3813', '3814', '3981'};
set<string> CaseyC=new Set<string>{'3807', '3806', '3977', '3978', '3177', '3805', '3803', '3976', '3806', '3977', '3975', '3156', '3805', '3804', '3807', '3805', '3912', '3980'};
set<string> CentralGoldfieldsS=new Set<string>{'3465', '3371', '3475', '3472', '3465', '3472', '3465', '3364', '3371', '3475', '3465', '3370', '3465', '3472', '3462', '3371', '3465', '3472', '3465', '3370', '3371', '3472', '3465', '3371', '3364', '3371'};
set<string> ColacOtwayS=new Set<string>{'3237', '3249', '3233', '3249', '3243', '3251', '3237', '3242', '3237', '3260', '3233', '3239', '3233', '3239', '3250', '3249', '3254', '3237', '3249', '3322', '3251', '3249', '3250', '3251', '3237', '3236', '3237', '3239', '3243', '3238', '3221', '3238', '3221', '3238', '3249', '3266', '3237', '3238', '3249', '3239', '3221', '3249', '3238', '3233', '3236', '3243', '3249', '3237', '3241', '3249', '3235', '3233', '3249', '3221', '3266', '3233', '3260', '3237', '3249', '3243', '3237', '3251', '3243', '3241', '3237'};
set<string> CorangamiteS=new Set<string>{'3249', '3268', '3323', '3260', '3265', '3260', '3361', '3268', '3266', '3260', '3249', '3239', '3260', '3239', '3260', '3266', '3268', '3322', '3251', '3268', '3271', '3325', '3265', '3249', '3323', '3249', '3265', '3266', '3237', '3266', '3265', '3268', '3366', '3239', '3265', '3325', '3324', '3266', '3268', '3265', '3249', '3268', '3270', '3249', '3360', '3269', '3271', '3260', '3267', '3266', '3260', '3361', '3265', '3249', '3264', '3260', '3268', '3325', '3269', '3237', '3352', '3249', '3237'};
set<string> DarebinC=new Set<string>{'3078', '3083', '3058', '3078', '3073', '3083', '3085', '3070', '3078', '3072', '3073', '3071'};
set<string> FrankstonC=new Set<string>{'3201', '3199', '3200', '3199', '3910', '3911', '3977', '3198'};
set<string> GannawarraS=new Set<string>{'3579', '3677', '3579', '3568', '3540', '3579', '3568', '3579', '3568', '3537', '3567', '3581', '3568', '3580', '3581', '3542', '3567', '3579', '3568', '3585', '3579', '3568', '3540', '3579', '3542', '3527', '3579', '3568', '3579'};
set<string> GlenEiraC=new Set<string>{'3204', '3165', '3187', '3163', '3162', '3145', '3161', '3162', '3165', '3185', '3163', '3204', '3163', '3183'};

for(Account myAccount: Trigger.new){
     if(myAccount.BillingPostalCode !=NULL){
         String s = myAccount.BillingPostalCode;
                if(AlpineS.contains(s)){
                 myAccount.LGA__c = 'Alpine S';
                }
                else if(EastGippslandS.contains(s)){
                 myAccount.LGA__c = 'East Gippsland S';
                }
                else if(AraratRC.contains(s)){
                 myAccount.LGA__c = 'Ararat RC';
                }
                else if(BallaratC.contains(s)){
                 myAccount.LGA__c = 'Ballarat C';
                }
                else if(BanyuleC.contains(s)){
                 myAccount.LGA__c = 'Banyule C';
                }
                else if(BassCoastS.contains(s)){
                 myAccount.LGA__c = 'Bass Coast S';
                }
                else if(BawBawS.contains(s)){
                 myAccount.LGA__c = 'Baw Baw S';
                }
                else if(BaysideC.contains(s)){
                 myAccount.LGA__c = 'Bayside C';
                }
               
                else if(BenallaRC.contains(s)){
                 myAccount.LGA__c = 'Benalla RC';
                }
                else if(BrimbankC.contains(s)){
                 myAccount.LGA__c = 'Brimbank C';
                }
                else if(CampaspeS.contains(s)){
                 myAccount.LGA__c = 'Campaspe S';
                }
                else if(CardiniaS.contains(s)){
                 myAccount.LGA__c = 'Cardinia S';
                }
                else if(CaseyC.contains(s)){
                 myAccount.LGA__c = 'Casey C';
                }
                else if(CentralGoldfieldsS.contains(s)){
                 myAccount.LGA__c = 'Central Goldfields S';
                }
                else if(ColacOtwayS.contains(s)){
                 myAccount.LGA__c = 'Colac Otway S';
                }
                else if(CorangamiteS.contains(s)){
                 myAccount.LGA__c = 'Corangamite S';
                }
                else if(DarebinC.contains(s)){
                 myAccount.LGA__c = 'Darebin C';
                }
                else if(FrankstonC.contains(s)){
                 myAccount.LGA__c = 'Frankston C';
                }
                else if(GannawarraS.contains(s)){
                 myAccount.LGA__c = 'Gannawarra S';
                }
                else if(GlenEiraC.contains(s)){
                 myAccount.LGA__c = 'GlenEira C';
                }
                else
                {
                    //myAccount.addError('This area not belong to hume!');
                    myAccount.LGA__c = 'Not a Valid PostCode';
                }
        } // end main if
//update myAccount;

     }// end for
  
  }
  • April 28, 2014
  • Like
  • 0