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
karthikarthi 

help me to increase the code coverage,now i'm getting 81%

my apex class is:

public class guideddata
{
    public ID id;
    public GE_PW_User_Sales_Hierarchy_Association__c g;
    public ID urluser{get;set;}
    public User manager{get;set;}
    public user mgr{get;set;}
    public user usr{get;set;}
    public string own{get;set;}
    public List<SelectOption> locationlist{get;set;}
    public string loc{get;set;}
    public List<selectoption> sel{get;set;}
    public string flag;
    public Boolean shouldRender{get;set;}
    public list<GE_PW_User_Sales_Hierarchy_Association__c> Managerlocationid = new List<GE_PW_User_Sales_Hierarchy_Association__c>();
    public list<GE_PW_User_Sales_Hierarchy_Association__c> Userlocationid = new List<GE_PW_User_Sales_Hierarchy_Association__c>();
    public list<GE_PW_User_Sales_Hierarchy_Association__c> loclist= new list<GE_PW_User_Sales_Hierarchy_Association__c>();
    public GE_PW_User_Sales_Hierarchy_Association__c sec = new GE_PW_User_Sales_Hierarchy_Association__c();
    public GE_PW_User_Sales_Hierarchy_Association__c assignuser = new GE_PW_User_Sales_Hierarchy_Association__c();
    public GE_PW_User_Sales_Hierarchy_Association__c pcklst = new GE_PW_User_Sales_Hierarchy_Association__c();
    public list<GE_PW_User_Sales_Hierarchy_Association__c> lst = new list<GE_PW_User_Sales_Hierarchy_Association__c>();
    public GE_PW_User_Sales_Hierarchy_Association__c Parentleveltype = new GE_PW_User_Sales_Hierarchy_Association__c();
    public GE_PW_User_Sales_Hierarchy_Association__c fields = new GE_PW_User_Sales_Hierarchy_Association__c();
    public list<GE_PW_User_Sales_Hierarchy_Association__c> locid = new list<GE_PW_User_Sales_Hierarchy_Association__c>();
    public list<GE_PW_User_Sales_Hierarchy_Association__c> seclocationid = new list<GE_PW_User_Sales_Hierarchy_Association__c>();
   
   

    public id locsfid;

    public guideddata(ApexPages.StandardController controller)
    {
       .currentPageReference().getParameters().get('userid');

        manager=[select managerid from user where id=:id];
        if(manager.managerId!=null)
        {
            mgr=[Select Name from User where id=:manager.managerId];
            String s=mgr.Name;
        }
        usr=[select name from User where id=:id];
        string l=usr.name;
        locsfid=System.currentPageReference().getParameters().get('locsfid');

        //Parentleveltype=[select GE_PW_Location_Level_Name__c from GE_PW_User_Sales_Hierarchy_Association__c where GE_PW_User_ID__c=:manager.managerid and GE_PW_Primary_OwnerShip_Flag__c= 'YES' limit 1];
        Managerlocationid=[Select GE_PW_Location_ID__c from GE_PW_User_Sales_Hierarchy_Association__c where GE_PW_User_ID__c=:manager.managerid and GE_PW_Primary_OwnerShip_Flag__c= 'YES'];
        Userlocationid=[select id,GE_PW_Location_ID__c from GE_PW_User_Sales_Hierarchy_Association__c where GE_PW_User_ID__c=:id and GE_PW_Primary_OwnerShip_Flag__c= 'YES'];
       
        locationlist = new List<SelectOption>();

        for(GE_PW_User_Sales_Hierarchy_Association__c m:Managerlocationid)
        {
            loclist.add(m);
        }
        for(GE_PW_User_Sales_Hierarchy_Association__c u:Userlocationid)
        {
            loclist.add(u);
        }

        for(GE_PW_User_Sales_Hierarchy_Association__c h:loclist)
        {
            if(h.GE_PW_Location_ID__c!=null)
            {
                locationlist.add(new selectoption(h.id,h.GE_PW_Location_ID__c));
            }
        }
       
        sel=new List<SelectOption>();
        sel.add(new SelectOption('', '--None--'));
        sel.add(new SelectOption('Ownership', 'Ownership'));
        sel.add(new SelectOption('Visibility', 'Visibility'));
       
       
        this.g = (GE_PW_User_Sales_Hierarchy_Association__c)controller.getRecord();
        this.g.GE_PW_Location_Level_Name__c = ApexPages.currentpage().getParameters().get('SapIDType');
        this.g.GE_PW_Location_ID__c = ApexPages.currentpage().getParameters().get('SapID');
        loc= ApexPages.currentpage().getParameters().get('owner');
    }

public void doDisable() {
  if (loc == 'Visibility') {
    shouldRender = false;
  } else if(loc == 'Ownership'){
    shouldRender = true;
  }
}

public PageReference back()
{
PageReference NewPage=new PageReference('/apex/ManageLocationid?id='+id);
 NewPage.setRedirect(true);
   return NewPage;
}     
 
public PageReference save()
{
    lst=[select GE_PW_Parent_Location_ID__c from GE_PW_User_Sales_Hierarchy_Association__c where GE_PW_User_ID__c=:id and GE_PW_Primary_OwnerShip_Flag__c='YES' limit 1];
    locid=[select id from GE_PW_User_Sales_Hierarchy_Association__c where GE_PW_Location_ID__c=:g.GE_PW_Location_ID__c and GE_PW_Primary_Ownership_Flag__c='YES'];
    if(locid.size()>0)
    {
        fields=[select GE_PW_Parent_Location_ID__c,GE_PW_Parent_Location_Level_Name__c from GE_PW_User_Sales_Hierarchy_Association__c where id=:locid limit 1];
    }
    if(shouldRender==true && own!=null)
    {
        pcklst=[select GE_PW_Location_ID__c,GE_PW_Location_Level_Name__c from GE_PW_User_Sales_Hierarchy_Association__c where id=:own];
    }
    if(loc=='Ownership')
    {
        flag='YES';
    }
    else if(loc=='Visibility')
    {
        flag='NO';
    }          
    system.debug('tes:'+loc);    
    if(g.GE_PW_Location_Level_Name__c!=null && g.GE_PW_Location_ID__c!=null && loc!=null )
     {system.debug('tes1:'+loc);

        if(locsfid!=null)
        {
            sec=[select GE_PW_Location_Level_Name__c,GE_PW_Location_ID__c,GE_PW_Primary_OwnerShip_Flag__c,GE_PW_Parent_Location_ID__c,GE_PW_Parent_Location_Level_Name__c from GE_PW_User_Sales_Hierarchy_Association__c where id=:locsfid ];
            sec.GE_PW_Location_Level_Name__c = g.GE_PW_Location_Level_Name__c;
            sec.GE_PW_Location_ID__c = g.GE_PW_Location_ID__c;
            sec.GE_PW_Primary_OwnerShip_Flag__c = flag;
            system.debug('len:'+shouldRender);
            if(shouldRender==true && own!=null)
            {
                sec.GE_PW_Parent_Location_ID__c = pcklst.GE_PW_Location_ID__c;
                sec.GE_PW_Parent_Location_Level_Name__c=pcklst.GE_PW_Location_Level_Name__c;
            }
            else if(shouldRender==false)
            {system.debug('inside');
                //sec.GE_PW_Parent_Location_ID__c = lst[0].GE_PW_Parent_Location_ID__c;
                //system.debug('Parent:'+lst[0].GE_PW_Parent_Location_ID__c  );
                //sec.GE_PW_Parent_Location_Level_Name__c=Parentleveltype.GE_PW_Location_Level_Name__c;
                if(locid.size()>0)
                {
                    sec.GE_PW_Parent_Location_ID__c = fields.GE_PW_Parent_Location_ID__c;
                    sec.GE_PW_Parent_Location_Level_Name__c=fields.GE_PW_Parent_Location_Level_Name__c;
                }
                else
                {
                    sec.GE_PW_Parent_Location_ID__c = 'NO';
                    sec.GE_PW_Parent_Location_Level_Name__c='NO';
                }
                       
           
            }
            update sec;
        }
        else
        {
            assignuser.GE_PW_Location_Level_Name__c= g.GE_PW_Location_Level_Name__c;
            assignuser.GE_PW_Location_ID__c = g.GE_PW_Location_ID__c;
            assignuser.GE_PW_Primary_OwnerShip_Flag__c = flag;
            assignuser.GE_PW_User_ID__c=id;
            if(shouldRender==true && own!=null)
            {
                assignuser.GE_PW_Parent_Location_ID__c=pcklst.GE_PW_Location_ID__c;
                assignuser.GE_PW_Parent_Location_Level_Name__c=pcklst.GE_PW_Location_Level_Name__c;
            }
            else if(shouldRender==false)
            {
                //assignuser.GE_PW_Parent_Location_ID__c=lst[0].GE_PW_Parent_Location_ID__c;
                //assignuser.GE_PW_Parent_Location_Level_Name__c=Parentleveltype.GE_PW_Location_Level_Name__c;
                if(locid.size()>0)
                {
                    assignuser.GE_PW_Parent_Location_ID__c=fields.GE_PW_Parent_Location_ID__c;
                    assignuser.GE_PW_Parent_Location_Level_Name__c=fields.GE_PW_Parent_Location_Level_Name__c;
                }
                else
                {
                    assignuser.GE_PW_Parent_Location_ID__c='NO';
                    assignuser.GE_PW_Parent_Location_Level_Name__c='NO';
                }
            }
            insert assignuser;
        }
    }
    else
    {
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter values for all fields.'));
        return null;
    }

    PageReference NewPage=new PageReference('/apex/ManageLocationid?id='+id);
    NewPage.setRedirect(true);
    return Newpage;

 

}
}

karthikarthi

my test class is:

@isTest 
private class Test_guideddata
{
//**this testmethod tests the guideddata

public static testmethod void testguideddata()
{
try
{    List<GE_PW_User_Sales_Hierarchy_Association__c> newTeamMembers;
        User thisUser = [ select Id from User where Id = :UserInfo.getUserId() ];
            System.runAs ( thisUser )
            {

                   //**** Get Profile record
                Profile p = [select id from profile where Name = 'GE_PW WCMS Sales' limit 1];
               
                //**** Get Role record
            Userrole urAcc = [Select Id from UserRole where name like  'Water CMS Sales - Account Manager' limit 1];
            Userrole urArea = [Select Id from UserRole where name like  'Water CMS Sales - Area Manager' limit 1];     
            Userrole urDist = [Select Id from UserRole where name like 'Water CMS Sales - Growth Ldr' limit 1];
            Userrole urReg = [Select Id from UserRole where name like 'Water CMS Sales - Region Manager' limit 1]; 
            Userrole urPole = [Select Id from UserRole where name =  'Water CMS Sales - Pole Leader' limit 1];  
 
                List<Userrole> urList = new List<Userrole>();
                urList.Add(urAcc);
                urList.Add(urArea);
                urList.Add(urDist);
                urList.Add(urReg);
                urList.Add(urPole);
                                                               
                //**** Insert test user records
                List<User> lstUser =  new List<User>();
                for(Integer i = 0;i < 5 ;i++ )
                {
                    User TestUser = new User(alias = 'standt', email = String.valueof(i)+'test@9876.com',
                    emailencodingkey = 'UTF-8', FirstName = 'TestFirstName' , lastname = 'TestLasName', languagelocalekey = 'en_US',
                    localesidkey = 'en_US', profileid = p.id ,UserRoleId = urList[i].Id,
                    timezonesidkey = 'America/Los_Angeles', username = String.valueof(i)+'test@9876.com');
                    //**** Add to user list
                    lstUser.add(TestUser);
                }   
   
                //**** insert User List
                 insert lstUser;   
           
               //**** update Manager field
                //List<User> lstMgrUser =  new List<User>();           
                for(Integer j = 0; j < 4; j++)
                {
                    lstUser[j].ManagerId = lstUser[j+1].Id;
   
                }    
                 update lstUser;
           
       
                       
                //**** Create Account
                Account acc = new Account(Name = 'TestAccountName');           
                //**** Insert the object virtually
                insert acc;
                          
                //**** Create TeamMember Records
                newTeamMembers = new List<GE_PW_User_Sales_Hierarchy_Association__c>();
                GE_PW_User_Sales_Hierarchy_Association__c AccTeam = new GE_PW_User_Sales_Hierarchy_Association__c();
                AccTeam.GE_PW_User_Id__c=lstUser[4].Id;
                AccTeam.GE_PW_Location_Id__c='B39';      
                AccTeam.GE_PW_Parent_Location_Id__c='B56';  
                Accteam.GE_PW_Location_Level_Name__c='Region';      
                AccTeam.GE_PW_Parent_Location_Level_Name__c='Region';           
                AccTeam.GE_PW_Primary_Ownership_Flag__c = 'YES';         
                newTeamMembers.add(AccTeam);   
               
                AccTeam = new GE_PW_User_Sales_Hierarchy_Association__c();
                AccTeam.GE_PW_User_Id__c=lstUser[3].Id;  
                AccTeam.GE_PW_Location_Id__c='B49';      
                AccTeam.GE_PW_Parent_Location_Id__c='B46';  
                Accteam.GE_PW_Location_Level_Name__c='Region';      
                AccTeam.GE_PW_Parent_Location_Level_Name__c='Region';      
                AccTeam.GE_PW_Primary_Ownership_Flag__c = 'NO'; 
                newTeamMembers.add(AccTeam); 
               
                AccTeam = new GE_PW_User_Sales_Hierarchy_Association__c();
                AccTeam.GE_PW_User_Id__c=lstUser[3].Id;  
                AccTeam.GE_PW_Location_Id__c='B56';      
                AccTeam.GE_PW_Parent_Location_Id__c='B46';  
                Accteam.GE_PW_Location_Level_Name__c='Region';      
                AccTeam.GE_PW_Parent_Location_Level_Name__c='Region';      
                AccTeam.GE_PW_Primary_Ownership_Flag__c = 'YES'; 
                newTeamMembers.add(AccTeam);
               
                insert newTeamMembers;     
                                 
                                                
                  User u = lstUser[0];   
                          
                  ApexPages.currentPage().getParameters().put('userid',lstuser[4].Id);     
                  ApexPages.currentPage().getParameters().put('locsfid',newTeamMembers[0].Id);
                  ApexPages.currentPage().getParameters().put('SapIDType',newTeamMembers[0].GE_PW_Location_Level_Name__c);
                  ApexPages.currentPage().getParameters().put('SapID',newTeamMembers[0].GE_PW_Location_Id__c);
                                           
                  ApexPages.StandardController sc1 = new ApexPages.standardController(newTeammembers[0]);
          Test.Starttest();
                  //**Create a new instance of class      
                guideddata gd1=new guideddata(sc1);  
                gd1.loc='Ownership';
                gd1.own=newTeamMembers[2].Id;
                gd1.doDisable(); 
                gd1.back();  
                gd1.save();          
           
                guideddata gd2=new guideddata(sc1);  
                gd2.loc='Visibility';
                gd2.own=newTeamMembers[2].Id;
                gd2.doDisable(); 
                gd2.back();  
                gd2.save();
                      
          Test.stoptest();                  
         }}

                                                       
                
        catch(Exception e)
        {
            system.debug('Error Message:::: '+ e.getmessage());
            system.assert(false,e.getmessage());
        }
    }
}

sfdcfoxsfdcfox

Can you highlight the bits and pieces that are not getting covered? It would make it easier for us to take a look at.

karthikarthi

hi here i have highlighted the parts which is not covered:

my apex class is:

public class guideddata
{
    public ID id;
    public GE_PW_User_Sales_Hierarchy_Association__c g;
    public ID urluser{get;set;}
    public User manager{get;set;}
    public user mgr{get;set;}
    public user usr{get;set;}
    public string own{get;set;}
    public List<SelectOption> locationlist{get;set;}
    public string loc{get;set;}
    public List<selectoption> sel{get;set;}
    public string flag;
    public Boolean shouldRender{get;set;}
    public list<GE_PW_User_Sales_Hierarchy_Association__c> Managerlocationid = new List<GE_PW_User_Sales_Hierarchy_Association__c>();
    public list<GE_PW_User_Sales_Hierarchy_Association__c> Userlocationid = new List<GE_PW_User_Sales_Hierarchy_Association__c>();
    public list<GE_PW_User_Sales_Hierarchy_Association__c> loclist= new list<GE_PW_User_Sales_Hierarchy_Association__c>();
    public GE_PW_User_Sales_Hierarchy_Association__c sec = new GE_PW_User_Sales_Hierarchy_Association__c();
    public GE_PW_User_Sales_Hierarchy_Association__c assignuser = new GE_PW_User_Sales_Hierarchy_Association__c();
    public GE_PW_User_Sales_Hierarchy_Association__c pcklst = new GE_PW_User_Sales_Hierarchy_Association__c();
    public list<GE_PW_User_Sales_Hierarchy_Association__c> lst = new list<GE_PW_User_Sales_Hierarchy_Association__c>();
    public GE_PW_User_Sales_Hierarchy_Association__c Parentleveltype = new GE_PW_User_Sales_Hierarchy_Association__c();
    public GE_PW_User_Sales_Hierarchy_Association__c fields = new GE_PW_User_Sales_Hierarchy_Association__c();
    public list<GE_PW_User_Sales_Hierarchy_Association__c> locid = new list<GE_PW_User_Sales_Hierarchy_Association__c>();
    public list<GE_PW_User_Sales_Hierarchy_Association__c> seclocationid = new list<GE_PW_User_Sales_Hierarchy_Association__c>();
   
   

    public id locsfid;

    public guideddata(ApexPages.StandardController controller)
    {
       .currentPageReference().getParameters().get​('userid');

        manager=[select managerid from user where id=:id];
        if(manager.managerId!=null)
        {
            mgr=[Select Name from User where id=:manager.managerId];
            String s=mgr.Name;
        }
        usr=[select name from User where id=:id];
        string l=usr.name;
        locsfid=System.currentPageReference().getParameter​s().get('locsfid');

        //Parentleveltype=[select GE_PW_Location_Level_Name__c from GE_PW_User_Sales_Hierarchy_Association__c where GE_PW_User_ID__c=:manager.managerid and GE_PW_Primary_OwnerShip_Flag__c= 'YES' limit 1];
        Managerlocationid=[Select GE_PW_Location_ID__c from GE_PW_User_Sales_Hierarchy_Association__c where GE_PW_User_ID__c=:manager.managerid and GE_PW_Primary_OwnerShip_Flag__c= 'YES'];
        Userlocationid=[select id,GE_PW_Location_ID__c from GE_PW_User_Sales_Hierarchy_Association__c where GE_PW_User_ID__c=:id and GE_PW_Primary_OwnerShip_Flag__c= 'YES'];
       
        locationlist = new List<SelectOption>();

        for(GE_PW_User_Sales_Hierarchy_Association__c m:Managerlocationid)
        {
            loclist.add(m);
        }
        for(GE_PW_User_Sales_Hierarchy_Association__c u:Userlocationid)
        {
            loclist.add(u);
        }

        for(GE_PW_User_Sales_Hierarchy_Association__c h:loclist)
        {
            if(h.GE_PW_Location_ID__c!=null)
            {
                locationlist.add(new selectoption(h.id,h.GE_PW_Location_ID__c));
            }
        }
       
        sel=new List<SelectOption>();
        sel.add(new SelectOption('', '--None--'));
        sel.add(new SelectOption('Ownership', 'Ownership'));
        sel.add(new SelectOption('Visibility', 'Visibility'));
       
       
        this.g = (GE_PW_User_Sales_Hierarchy_Association__c)control​ler.getRecord();
        this.g.GE_PW_Location_Level_Name__c = ApexPages.currentpage().getParameters().get('SapID​Type');
        this.g.GE_PW_Location_ID__c = ApexPages.currentpage().getParameters().get('SapID​');
        loc= ApexPages.currentpage().getParameters().get('owner​');
    }

public void doDisable() {
  if (loc == 'Visibility') {
    shouldRender = false;
  } else if(loc == 'Ownership'){
    shouldRender = true;
  }
}

public PageReference back()
{
PageReference NewPage=new PageReference('/apex/ManageLocationid?id='+id);
 NewPage.setRedirect(true);
   return NewPage;
}     
 
public PageReference save()
{
    lst=[select GE_PW_Parent_Location_ID__c from GE_PW_User_Sales_Hierarchy_Association__c where GE_PW_User_ID__c=:id and GE_PW_Primary_OwnerShip_Flag__c='YES' limit 1];
    locid=[select id from GE_PW_User_Sales_Hierarchy_Association__c where GE_PW_Location_ID__c=:g.GE_PW_Location_ID__c and GE_PW_Primary_Ownership_Flag__c='YES'];
    if(locid.size()>0)
    {
        fields=[select GE_PW_Parent_Location_ID__c,GE_PW_Parent_Location_​Level_Name__c from GE_PW_User_Sales_Hierarchy_Association__c where id=:locid limit 1];
    }
    if(shouldRender==true && own!=null)
    {
        pcklst=[select GE_PW_Location_ID__c,GE_PW_Location_Level_Name__c from GE_PW_User_Sales_Hierarchy_Association__c where id=:own];
    }
    if(loc=='Ownership')
    {
        flag='YES';
    }
    else if(loc=='Visibility')
    {
        flag='NO';
    }          
    system.debug('tes:'+loc);    
    if(g.GE_PW_Location_Level_Name__c!=null && g.GE_PW_Location_ID__c!=null && loc!=null )
     {system.debug('tes1:'+loc);

        if(locsfid!=null)
        {
            sec=[select GE_PW_Location_Level_Name__c,GE_PW_Location_ID__c,​GE_PW_Primary_OwnerShip_Flag__c,GE_PW_Parent_Locat​ion_ID__c,GE_PW_Parent_Location_Level_Name__c from GE_PW_User_Sales_Hierarchy_Association__c where id=:locsfid ];
            sec.GE_PW_Location_Level_Name__c = g.GE_PW_Location_Level_Name__c;
            sec.GE_PW_Location_ID__c = g.GE_PW_Location_ID__c;
            sec.GE_PW_Primary_OwnerShip_Flag__c = flag;
            system.debug('len:'+shouldRender);
            if(shouldRender==true && own!=null)
            {
                sec.GE_PW_Parent_Location_ID__c = pcklst.GE_PW_Location_ID__c;
                sec.GE_PW_Parent_Location_Level_Name__c=pcklst.GE_​PW_Location_Level_Name__c;
            }
            else if(shouldRender==false)
            {system.debug('inside');
                //sec.GE_PW_Parent_Location_ID__c = lst[0].GE_PW_Parent_Location_ID__c;
                //system.debug('Parent:'+lst[0].GE_PW_Parent_Locat​ion_ID__c  );
                //sec.GE_PW_Parent_Location_Level_Name__c=Parentle​veltype.GE_PW_Location_Level_Name__c;
                if(locid.size()>0)
                {
                    sec.GE_PW_Parent_Location_ID__c = fields.GE_PW_Parent_Location_ID__c;
                    sec.GE_PW_Parent_Location_Level_Name__c=fields.GE_​PW_Parent_Location_Level_Name__c;
                }
                else
                {
                    sec.GE_PW_Parent_Location_ID__c = 'NO';
                    sec.GE_PW_Parent_Location_Level_Name__c='NO';
                }
                       
           
            }
            update sec;
        }
        else
        {
            assignuser.GE_PW_Location_Level_Name__c= g.GE_PW_Location_Level_Name__c;
            assignuser.GE_PW_Location_ID__c = g.GE_PW_Location_ID__c;
            assignuser.GE_PW_Primary_OwnerShip_Flag__c = flag;
            assignuser.GE_PW_User_ID__c=id;
            if(shouldRender==true && own!=null)
            {
                assignuser.GE_PW_Parent_Location_ID__c=pcklst.GE_P​W_Location_ID__c;
                assignuser.GE_PW_Parent_Location_Level_Name__c=pck​lst.GE_PW_Location_Level_Name__c;
            }
            else if(shouldRender==false)
            {
                //assignuser.GE_PW_Parent_Location_ID__c=lst[0].GE​_PW_Parent_Location_ID__c;
                //assignuser.GE_PW_Parent_Location_Level_Name__c=P​arentleveltype.GE_PW_Location_Level_Name__c;
                if(locid.size()>0)
                {
                    assignuser.GE_PW_Parent_Location_ID__c=fields.GE_P​W_Parent_Location_ID__c;
                    assignuser.GE_PW_Parent_Location_Level_Name__c=fie​lds.GE_PW_Parent_Location_Level_Name__c;
                }
                else
                {
                    assignuser.GE_PW_Parent_Location_ID__c='NO';
                    assignuser.GE_PW_Parent_Location_Level_Name__c='NO​';
                }
            }
            insert assignuser;
        }
    }
    else
    {
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter values for all fields.'));
        return null
;
    }

    PageReference NewPage=new PageReference('/apex/ManageLocationid?id='+id);
    NewPage.setRedirect(true);
    return Newpage;

 

}
}

sfdcfoxsfdcfox

Some of your code is unreachable. Case in point in the save() function are these little bits here:

 

 

if(locid.size()>0) {
  if(locid.size()>0) {
    // NO NEED FOR IF, THIS ALWAYS HAPPENS!
  } else {
    // THIS WILL NEVER, EVER HAPPEN!!!
  }
}
else {
  // No other assignments or changes to locid
  if(locid.size()>0) {
     // THIS WILL NEVER, EVER HAPPEN!!!
  }
}

Other than that, all I can say, is that you need to force a scenario where there are no locids. The easiest way to do this is to delete all of the GE_PW_User_Sales_Hierarchy_Association__c records that match the criteria, then call the save() function again. This should trigger your other if branch. After that, it's just a matter of toggling shouldRender and calling save() a third time.

 

 

Examine your code's logic, make sure it actually makes sense. You have a lot of public variables that probably shouldn't be in your code at all, much less public. You have a lot of inefficient code going on here, too. Some of your public variables most certainly should be functions instead.

 

Your code is fundamentally broken in a couple of places, and I'd recommend that you go through and fix those before you worry about code coverage (all I can really see off the top of my head is the if/then/else stuff you have going on, but the code looks suspicious all-around).

 

On the other hand, you can ignore all this and deploy your code if you're in a time crunch. 81% is better than the required 75% minimum, unless you're a developer whose slave-driver employer requires a much higher percentage. Just make sure you test your code manually to make sure it's working the way you expect.