function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SandeepbvSandeepbv 

auto-update 5 fields when a picklist value is selected

Hi Team!

I'm working on apex code to auto-update 5 fields when a picklist value is selected. I had the code with no errors and wrote a test class with no errors. But the test class is not having 75% code coverage.

The test class only covers the first if statment and the last else statment. Even though the test code is written for other criteria it won't cover that. Need help. Refer the below code for more info.
 
trigger Addressupdate on Sales_Summary__c (before insert, before update) {
    
    List<Sales_Summary__c> address = trigger.new;
    for(Sales_Summary__c sls: address){
        if(sls.Location__c=='Brooks'){
            sls.Street__c = '31 1st St W';
            sls.Country__c = 'canada';
            sls.City__c = 'Brooks';
            sls.Postal_Code__c ='T1R 2B6';
            sls.State__c = 'AB';
                      
        }
         if(sls.Location__c=='Camrose'){
            sls.Street__c = '6800 48th Ave';
            sls.Country__c = 'canada';
            sls.City__c = 'Camrose';
            sls.Postal_Code__c ='T4V 4T1';
            sls.State__c = 'AB';
                      
        }
        else if(sls.Location__c=='Canmore'){
            sls.Street__c = '802 Bow Valley Tr';
            sls.Country__c = 'canada';
            sls.City__c = 'Canmore';
            sls.Postal_Code__c ='T1W 1N6';
            sls.State__c = 'AB';
                      
        }
        else if(sls.Location__c=='Chestermere'){
            sls.Street__c = '#303 - 100 Marina Dr.';
            sls.Country__c = 'canada';
            sls.City__c = 'Chestermere';
            sls.Postal_Code__c ='T1X 0A9';
            sls.State__c = 'AB';
                      
        }
        else if(sls.Location__c=='Dawson Creek'){
            sls.Street__c = '11000 8th St';
            sls.Country__c = 'canada';
            sls.City__c = 'Dawson Creek';
            sls.Postal_Code__c ='V1G 3L8';
            sls.State__c = 'BC';
                      
        }
         else if(sls.Location__c=='Cranbrook'){
            sls.Street__c = '1500 Cranbrook St N';
            sls.Country__c = 'canada';
            sls.City__c = 'Cranbrook';
            sls.Postal_Code__c ='V1C 358';
            sls.State__c = 'BC ';
                      
        }
         else if(sls.Location__c=='High River'){
            sls.Street__c = '1225 1 St SE Unit E';
            sls.Country__c = 'canada';
            sls.City__c = 'High River';
            sls.Postal_Code__c ='T1V 0J5';
            sls.State__c = 'AB';
                      
        }
         else if(sls.Location__c=='Prince Rupert'){
            sls.Street__c = '500 2nd Ave W';
            sls.Country__c = 'canada';
            sls.City__c = 'Prince Rupert';
            sls.Postal_Code__c ='V8J 3T6';
            sls.State__c = 'BC ';
                      
        }
         else if(sls.Location__c=='Terrace'){
            sls.Street__c = '4761 Lakelse Ave Ste 104';
            sls.Country__c = 'canada';
            sls.City__c = 'Terrace';
            sls.Postal_Code__c ='V8G 4R9';
            sls.State__c = 'BC';
                      
        }
         else if(sls.Location__c=='Strathmore'){
            sls.Street__c = '500 Ranch Market';
            sls.Country__c = 'canada';
            sls.City__c = 'Strathmore';
            sls.Postal_Code__c ='T1P 0A8';
            sls.State__c = 'AB';
                      
        }
        else {
            sls.Street__c = '44 Maple Valley Rd';
            sls.Country__c = 'canada';
            sls.City__c = ' Corner Brook';
            sls.Postal_Code__c ='A2H 6J3';
            sls.State__c = 'NL';
        }
    }

}

---------------------------------------------------------------

@isTest
public class Addressupdate_test {
@isTest
    static void testAddressupdate(){
        Sales_Summary__c ss = new Sales_Summary__c();
        ss.Location__c = 'Brooks';
        ss.Street__c = '31 1st St W';
        ss.Country__c = 'canada';
        ss.City__c = 'Brooks';
        ss.Postal_Code__c ='T1R 2B6';
        ss.State__c = 'AB';  
        ss.Date__c = date.today();
        ss.New_add__c = 1;
        ss.Online_Sales__c = 1;
        ss.Green_members__c = 941;
        ss.Yellow_members__c = 93;
        ss.Frozen_Members__c = 68;
        ss.Total_Walk_ins__c = 3;
        ss.Total_Revenue_End_of_the_day__c = 416.84;
        ss.Ask_family_member_before_signing_up__c = 1;
        ss.Total_number_of_missed_walk_ins__c = 1;
        ss.Asking_for_drop_in__c = 0;
        ss.going_to_checkout_other_gyms_in_town_fir__c = 0;
        ss.Lack_of_classes__c = 0;
        ss.too_expensive__c = 0;
        ss.bi_weekly__c = 3;
             insert ss;
         Sales_Summary__c s1 =[select id, Location__c, Street__c, City__c, Postal_Code__c, State__c, Country__c from Sales_Summary__c where id=:ss.Id];
       system.assertEquals(s1.Location__c, 'Brooks');
        
        Sales_Summary__c sA = new Sales_Summary__c();
        sA.Location__c = 'Camrose';
        sA.Street__c = '6800 48th Ave';
        sA.Country__c = 'canada';
        sA.City__c = 'Camrose';
        sA.Postal_Code__c ='T4V 4T1';
        sA.State__c = 'AB';  
        sA.Date__c = date.today();
        sA.New_add__c = 1;
        sA.Online_Sales__c = 1;
        sA.Green_members__c = 941;
        sA.Yellow_members__c = 93;
        sA.Frozen_Members__c = 68;
        sA.Total_Walk_ins__c = 3;
        sA.Total_Revenue_End_of_the_day__c = 416.84;
        sA.Ask_family_member_before_signing_up__c = 1;
        sA.Total_number_of_missed_walk_ins__c = 1;
        sA.Asking_for_drop_in__c = 0;
        sA.going_to_checkout_other_gyms_in_town_fir__c = 0;
        sA.Lack_of_classes__c = 0;
        sA.too_expensive__c = 0;
        sA.bi_weekly__c = 3;
            insert sA;
                Sales_Summary__c s2 =[select id, Location__c, Street__c, City__c, Postal_Code__c, State__c, Country__c from Sales_Summary__c where id=:sA.Id];
       system.assertEquals(s2.Location__c, 'Camrose');
        
        Sales_Summary__c sB = new Sales_Summary__c();
        sB.Location__c = 'Canmore';
        sB.Street__c = '802 Bow Valley Tr';
        sB.Country__c = 'canada';
        sB.City__c = 'Canmore';
        sB.Postal_Code__c ='T1W 1N6';
        sB.State__c = 'AB';  
        sB.Date__c = date.today();
        sB.New_add__c = 1;
        sB.Online_Sales__c = 1;
        sB.Green_members__c = 941;
        sB.Yellow_members__c = 93;
        sB.Frozen_Members__c = 68;
        sB.Total_Walk_ins__c = 3;
        sB.Total_Revenue_End_of_the_day__c = 416.84;
        sB.Ask_family_member_before_signing_up__c = 1;
        sB.Total_number_of_missed_walk_ins__c = 1;
        sB.Asking_for_drop_in__c = 0;
        sB.going_to_checkout_other_gyms_in_town_fir__c = 0;
        sB.Lack_of_classes__c = 0;
        sB.too_expensive__c = 0;
        sB.bi_weekly__c = 3;
            insert sB;
                Sales_Summary__c s3 =[select id, Location__c, Street__c, City__c, Postal_Code__c, State__c, Country__c from Sales_Summary__c where id=:sB.Id];
       system.assertEquals(s3.Location__c, 'Canmore');
        
         Sales_Summary__c sC = new Sales_Summary__c();
        sC.Location__c = 'Chestermere';
        sC.Street__c = '#303 - 100 Marina Dr.';
        sC.Country__c = 'canada';
        sC.City__c = 'Chestermere';
        sC.Postal_Code__c ='T1X 0A9';
        sC.State__c = 'AB';  
        sC.Date__c = date.today();
        sC.New_add__c = 1;
        sC.Online_Sales__c = 1;
        sC.Green_members__c = 941;
        sC.Yellow_members__c = 93;
        sC.Frozen_Members__c = 68;
        sC.Total_Walk_ins__c = 3;
        sC.Total_Revenue_End_of_the_day__c = 416.84;
        sC.Ask_family_member_before_signing_up__c = 1;
        sC.Total_number_of_missed_walk_ins__c = 1;
        sC.Asking_for_drop_in__c = 0;
        sC.going_to_checkout_other_gyms_in_town_fir__c = 0;
        sC.Lack_of_classes__c = 0;
        sC.too_expensive__c = 0;
        sC.bi_weekly__c = 3;
            insert sC;
                Sales_Summary__c s4 =[select id, Location__c, Street__c, City__c, Postal_Code__c, State__c, Country__c from Sales_Summary__c where id=:sC.Id];
       system.assertEquals(s4.Location__c, 'Chestermere');
    }