• karthi
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 17
    Questions
  • 20
    Replies

Hi , i'm having a boolean flag in visualforce page.. Depends on the flag value in class, i want to give the javascript alert box in the page. Please suggest me how to do?

  • January 17, 2013
  • Like
  • 0

Hi, i want to send a email notification when approval process is recalled. that email should include the comments in the approval page. The mail should go the current step approvers ie., the step at which the approval process is recalled. can somebody suggest how to achieve it??/ it is urgent..

  • November 06, 2012
  • Like
  • 0

I'm having a custom object called record. i have to get the fields of that in the page block table. My code is below:

 

Controller:

 

Public record__c record {get;set;}

 

VF page:

<apex:pageblock>

<apex:pageblocktable value="{!record}" var="ct">
                   <apex:column headerValue="Year" style="width:102px;" headerClass="centertext">
                            <apex:inputField value="{!ct.Year__c}" >
                            </apex:inputField>
                        </apex:column>
                  <apex:column headerValue="Amount" style="width:102px;" headerClass="centertext">
                            <apex:inputField value="{!ct.Amount__c}" style="width:180px;">
                            </apex:inputField>
                        </apex:column>
                                    </apex:pageblocktable>
               
            </apex:pageBlock>

 

 

But in the pageblock table i'm getting only the header , but not the input fields. Please let me know what i have to do??/

  • September 19, 2012
  • Like
  • 0

can we get the output(in extract) in the form of XML by using Command line interface?

  • February 02, 2012
  • Like
  • 0

can we extract the chatting history in the chatter?

  • January 18, 2012
  • Like
  • 0

can someone tell me what are ways to store the URL in SFDC?

  • January 18, 2012
  • Like
  • 0

hi can somebody post the example codes for getting the mouse tip event in bar chart...

HI all

 

i'm planning to do sfdc dev401 exam by next week. please give me some useful sites to prepare

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;

 

}
}

  • April 29, 2011
  • Like
  • 0

public Boolean shouldRender{get;set;}

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

  • April 29, 2011
  • Like
  • 0

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)
{
id=System.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';
}
if(g.GE_PW_Location_Level_Name__c!=null && g.GE_PW_Location_ID__c!=null && loc!=null )
 
{
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;

 

}
}

  • April 28, 2011
  • Like
  • 0

my if else part is:

if (Acc.size() > 0)
        {
            for(GE_PW_User_Sales_Hierarchy_Association__c c : Acc) {
            system.debug('parent:'+c.GE_PW_Parent_Location_ID__c);

               if(Locationid.size()>0)
               {
                   for(GE_PW_User_sales_Hierarchy_Association__c l : Locationid)
                   {
                      if(l.GE_PW_Location_ID__c==c.GE_PW_Parent_Location_ID__c)
                       {   status='Valid';
                            break;
                               //intcount++;
                       }   
                       else  
                       {  
                       for(GE_PW_User_Sales_Hierarchy_Association__c a : Acc) {
                        if(c.GE_PW_Parent_Location_ID__c==a.GE_PW_Location_ID__c)
                         {
                         status='Valid';
                         break;
                         }
                        else
                         {          
                          status='Invalid';
                            //intcount++;
                         }
                        }
                       }
                    }
              }
         pls help me to write the test class to cover it      

  • April 28, 2011
  • Like
  • 0

this is my apex class:

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)
{
id=System.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';
}
if(g.GE_PW_Location_Level_Name__c!=null && g.GE_PW_Location_ID__c!=null && loc!=null )
 
{
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;

 

}
}

 

  • April 28, 2011
  • Like
  • 0

i'm not aware of writing test classes. i tried my level here. i think i have to include some hard coded values to get the coverage. i'm not sure what to do. plz help me in this.

hi here is my apex class: 

public class removerecord{
    public ID userid;
    public string UserList{get;set;}
    public string SelId;
    Public List<String> priID_SecIDStr = new List<String>();
      Public List<ID> IdSel = new List<ID>();
    public GE_PW_User_Sales_Hierarchy_Association__c pri = new GE_PW_User_Sales_Hierarchy_Association__c();
    public List<GE_PW_User_Sales_Hierarchy_Association__c> sec = new List<GE_PW_User_Sales_Hierarchy_Association__c>();

    public removerecord()
    {
        UserList = ApexPages.currentpage().getParameters().get('id');
        SelId = System.currentPageReference().getParameters().get('loc'); 
 
   }
  
   Public pageReference RemoveLocationIDs()
   {
      
       //**** Check for the split size
         if(SelId.split(',').size() == 1)
          {
          ID LocID = SelId;
          pri=[Select ID,GE_PW_Location_ID__c,GE_PW_Location_Level_Name__c,GE_PW_Parent_Location_ID__c,GE_PW_Parent_Location_Level_Name__c,GE_PW_Primary_OwnerShip_Flag__c from GE_PW_User_Sales_Hierarchy_Association__c where id =:LocID];
          Delete pri;   
          }  
         else 
          {
          priID_SecIDStr = SelId.split(',');
                 for(String s : priID_SecIDstr )
            {
           ID spliID = s;
           IdSel.add(spliID);
           sec=[Select ID,GE_PW_Location_ID__c,GE_PW_Location_Level_Name__c,GE_PW_Parent_Location_ID__c,GE_PW_Parent_Location_Level_Name__c,GE_PW_Primary_OwnerShip_Flag__c from GE_PW_User_Sales_Hierarchy_Association__c where id IN:IdSel];    
           Delete sec;
            }
          }
       PageReference NewPage=new PageReference('/apex/ManageLocationid?id='+UserList);
       NewPage.setRedirect(true);
       return NewPage;
           
     }
}     

 

 

test class which i have wrote is:

@isTest
private class Test_RemoveRecord{
    static testmethod void testRemoveRecord(){
    try 
    {
      Test.startTest();

        removerecord obj = new removerecord();       
        obj.RemoveLocationIDs();    
           
        Test.StopTest();       
      } 
    catch(Exception e)
        {
            system.debug('Error Message:::: '+ e.getmessage());
            system.assert(false,e.getmessage());
        }

    }
}

  • April 27, 2011
  • Like
  • 0

this is the apex class:

public class LocationWrapperClass
{
public Boolean checked{ get; set; }
public GE_PW_User_Sales_Hierarchy_Association__c cat { get; set;}
public string s {get;set;}
 
    public LocationWrapperClass(){
        cat = new GE_PW_User_Sales_Hierarchy_Association__c();
       ;
        s = '';
    }
 
    public LocationWrapperClass(GE_PW_User_Sales_Hierarchy_Association__c c, String status){
        cat = c;
       ;
        s = status;
    }
}

 

 

 

 

this is the test method which i wrote for above controller class:  i'm getting 63% coverage only. help me to get good coverage

@isTest
private class Test_LocationWrapperClass
{       
    //**** This testMethod tests CategoryWrapper
    public static testmethod void testLocationWrapperClass()
    {
        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 'GE Water CMS Acct Mgr%' limit 1];
                Userrole urArea = [Select Id from UserRole where name like 'GE Water CMS Area Mgr%' limit 1];
                Userrole urDist = [Select Id from UserRole where name like 'GE Water CMS District Mgr%' limit 1];
                Userrole urReg = [Select Id from UserRole where name like 'GE Water CMS Region Manager%' limit 1];
                Userrole urPole = [Select Id from UserRole where name like 'GE Water CMS 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
                RollupValues.IsNoTrigger = true;
                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;
   
                }   
                RollupValues.IsNoTrigger = true;
                update lstUser;
               
                //**** Create Account
                Account acc = new Account(Name = 'TestAccountName');           
                //**** Insert the object virtually
                insert acc;
                          
                //**** Create AccountTeamMember 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); 
               
                insert newTeamMembers;                      
             
                                        
            //**** Start Test
            Test.startTest();

            LocationWrapperClass cw = new LocationWrapperClass();
            System.assertEquals(cw.checked,false);      
     
                  
            //**** Stop Test
            Test.stopTest();                       
        }}
         catch(Exception e)
        {
            system.debug('Error Message:::: '+ e.getmessage());
            system.assert(false,e.getmessage());
        }
    }
}

  • April 26, 2011
  • Like
  • 0

if anybody knows any of the best link for test class, post me

  • April 26, 2011
  • Like
  • 0

i'm posting the code of my apex class. can somebody guide me how to write test class for the following.

public class UserSearchResultsController{

    private String txtFirstName;
    private String txtLastName;
    private String queryStr;
    private Id userid;
    public List<User> users;
    public boolean Isrendered {get;Set;}   
    public ID seluser{get;set;}
    public PageReference init(){
        txtFirstName = ApexPages.currentPage().getParameters().get('userfirstname');
        txtLastName = ApexPages.currentPage().getParameters().get('userlastname');
        seluser=ApexPages.currentPage().getParameters().get('id');

        userid = Userinfo.getUserId();
        queryStr = '';
        Isrendered = true;
        return null;
    }
   
    public PageReference doSearch(){
       
        txtFirstName = this.userfirstname;
        txtLastName = this.userlastname;
        system.debug('FirstName:'+txtFirstName);
        userid = Userinfo.getUserId();
        queryStr = '';
        Isrendered = true;
        //**** We can't include % in the URL
        if(txtFirstName.contains('%'))
        {      
        txtFirstName=txtFirstName.replace('%','');
        }
        if(txtLastName.contains('%'))
        {      
        txtLastName=txtLastName.replace('%','');
        }
 
        PageReference Newpage = new PageReference('/apex/SearchWaterCMSUsers?userfirstname=' + txtFirstName + '&userlastname=' + txtLastName);
        Newpage.setRedirect(true);
        return Newpage;
       
    }
 public PageReference Search(){
 
        txtFirstName = this.userfirstname;
        txtLastName = this.userlastname;
        system.debug('FirstName:'+txtFirstName);
        userid = Userinfo.getUserId();
        queryStr = '';
        Isrendered = true;
        //**** We can't include % in the URL
        if(txtFirstName.contains('%'))
        {      
        txtFirstName=txtFirstName.replace('%','');
        }
        if(txtLastName.contains('%'))
        {      
        txtLastName=txtLastName.replace('%','');
        }
 
        PageReference Newpage = new PageReference('/apex/changemanager?userfirstname=' + txtFirstName + '&userlastname=' + txtLastName+'&id='+seluser);
        Newpage.setRedirect(true);
        return Newpage;
       
    }

 
   
    public String userfirstname{
        get{return txtFirstName;}
        set{this.txtFirstName = value;}
    }
   
    public String userlastname{
        get{return this.txtLastName;}
        set{this.txtLastName = value;}
    }
   
 
  
    public List<User> getalluserssvisible(){
        String q = this.getqueryStringUser();
      //system.debug('Length:'+q.length());
        if(q != ''){          
            users = database.query(q);
            return users;   
        } else {
            return null;
        }
    }
   
    private String getqueryStringUser(){
        try
        {
        if(txtFirstName !=null){
            queryStr = 'select id, name,firstname,lastname,email from User u where u.Profile.Name = \'GE_PW WCMS Sales\'';
                   if(txtFirstName.length() > 0) queryStr = queryStr + ' and firstname like \''+txtFirstName+'%\'';
                   if(txtLastName.length() > 0) queryStr = queryStr + ' and lastname like \''+txtLastName+'%\'';
            queryStr = queryStr + ' order by firstname';
            queryStr = queryStr + ' limit 25';
            system.debug('Query String:'+queryStr);}
         else
         { queryStr=''; }
         return queryStr;
        }
        catch (Exception e)
        {
                   return null;
        }   
    }
 
}

  • April 26, 2011
  • Like
  • 0

hi can somebody post the example codes for getting the mouse tip event in bar chart...

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;

 

}
}

  • April 29, 2011
  • Like
  • 0

public Boolean shouldRender{get;set;}

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

  • April 29, 2011
  • Like
  • 0

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)
{
id=System.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';
}
if(g.GE_PW_Location_Level_Name__c!=null && g.GE_PW_Location_ID__c!=null && loc!=null )
 
{
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;

 

}
}

  • April 28, 2011
  • Like
  • 0

this is my apex class:

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)
{
id=System.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';
}
if(g.GE_PW_Location_Level_Name__c!=null && g.GE_PW_Location_ID__c!=null && loc!=null )
 
{
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;

 

}
}

 

  • April 28, 2011
  • Like
  • 0

i'm not aware of writing test classes. i tried my level here. i think i have to include some hard coded values to get the coverage. i'm not sure what to do. plz help me in this.

hi here is my apex class: 

public class removerecord{
    public ID userid;
    public string UserList{get;set;}
    public string SelId;
    Public List<String> priID_SecIDStr = new List<String>();
      Public List<ID> IdSel = new List<ID>();
    public GE_PW_User_Sales_Hierarchy_Association__c pri = new GE_PW_User_Sales_Hierarchy_Association__c();
    public List<GE_PW_User_Sales_Hierarchy_Association__c> sec = new List<GE_PW_User_Sales_Hierarchy_Association__c>();

    public removerecord()
    {
        UserList = ApexPages.currentpage().getParameters().get('id');
        SelId = System.currentPageReference().getParameters().get('loc'); 
 
   }
  
   Public pageReference RemoveLocationIDs()
   {
      
       //**** Check for the split size
         if(SelId.split(',').size() == 1)
          {
          ID LocID = SelId;
          pri=[Select ID,GE_PW_Location_ID__c,GE_PW_Location_Level_Name__c,GE_PW_Parent_Location_ID__c,GE_PW_Parent_Location_Level_Name__c,GE_PW_Primary_OwnerShip_Flag__c from GE_PW_User_Sales_Hierarchy_Association__c where id =:LocID];
          Delete pri;   
          }  
         else 
          {
          priID_SecIDStr = SelId.split(',');
                 for(String s : priID_SecIDstr )
            {
           ID spliID = s;
           IdSel.add(spliID);
           sec=[Select ID,GE_PW_Location_ID__c,GE_PW_Location_Level_Name__c,GE_PW_Parent_Location_ID__c,GE_PW_Parent_Location_Level_Name__c,GE_PW_Primary_OwnerShip_Flag__c from GE_PW_User_Sales_Hierarchy_Association__c where id IN:IdSel];    
           Delete sec;
            }
          }
       PageReference NewPage=new PageReference('/apex/ManageLocationid?id='+UserList);
       NewPage.setRedirect(true);
       return NewPage;
           
     }
}     

 

 

test class which i have wrote is:

@isTest
private class Test_RemoveRecord{
    static testmethod void testRemoveRecord(){
    try 
    {
      Test.startTest();

        removerecord obj = new removerecord();       
        obj.RemoveLocationIDs();    
           
        Test.StopTest();       
      } 
    catch(Exception e)
        {
            system.debug('Error Message:::: '+ e.getmessage());
            system.assert(false,e.getmessage());
        }

    }
}

  • April 27, 2011
  • Like
  • 0

this is the apex class:

public class LocationWrapperClass
{
public Boolean checked{ get; set; }
public GE_PW_User_Sales_Hierarchy_Association__c cat { get; set;}
public string s {get;set;}
 
    public LocationWrapperClass(){
        cat = new GE_PW_User_Sales_Hierarchy_Association__c();
       ;
        s = '';
    }
 
    public LocationWrapperClass(GE_PW_User_Sales_Hierarchy_Association__c c, String status){
        cat = c;
       ;
        s = status;
    }
}

 

 

 

 

this is the test method which i wrote for above controller class:  i'm getting 63% coverage only. help me to get good coverage

@isTest
private class Test_LocationWrapperClass
{       
    //**** This testMethod tests CategoryWrapper
    public static testmethod void testLocationWrapperClass()
    {
        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 'GE Water CMS Acct Mgr%' limit 1];
                Userrole urArea = [Select Id from UserRole where name like 'GE Water CMS Area Mgr%' limit 1];
                Userrole urDist = [Select Id from UserRole where name like 'GE Water CMS District Mgr%' limit 1];
                Userrole urReg = [Select Id from UserRole where name like 'GE Water CMS Region Manager%' limit 1];
                Userrole urPole = [Select Id from UserRole where name like 'GE Water CMS 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
                RollupValues.IsNoTrigger = true;
                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;
   
                }   
                RollupValues.IsNoTrigger = true;
                update lstUser;
               
                //**** Create Account
                Account acc = new Account(Name = 'TestAccountName');           
                //**** Insert the object virtually
                insert acc;
                          
                //**** Create AccountTeamMember 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); 
               
                insert newTeamMembers;                      
             
                                        
            //**** Start Test
            Test.startTest();

            LocationWrapperClass cw = new LocationWrapperClass();
            System.assertEquals(cw.checked,false);      
     
                  
            //**** Stop Test
            Test.stopTest();                       
        }}
         catch(Exception e)
        {
            system.debug('Error Message:::: '+ e.getmessage());
            system.assert(false,e.getmessage());
        }
    }
}

  • April 26, 2011
  • Like
  • 0

i'm posting the code of my apex class. can somebody guide me how to write test class for the following.

public class UserSearchResultsController{

    private String txtFirstName;
    private String txtLastName;
    private String queryStr;
    private Id userid;
    public List<User> users;
    public boolean Isrendered {get;Set;}   
    public ID seluser{get;set;}
    public PageReference init(){
        txtFirstName = ApexPages.currentPage().getParameters().get('userfirstname');
        txtLastName = ApexPages.currentPage().getParameters().get('userlastname');
        seluser=ApexPages.currentPage().getParameters().get('id');

        userid = Userinfo.getUserId();
        queryStr = '';
        Isrendered = true;
        return null;
    }
   
    public PageReference doSearch(){
       
        txtFirstName = this.userfirstname;
        txtLastName = this.userlastname;
        system.debug('FirstName:'+txtFirstName);
        userid = Userinfo.getUserId();
        queryStr = '';
        Isrendered = true;
        //**** We can't include % in the URL
        if(txtFirstName.contains('%'))
        {      
        txtFirstName=txtFirstName.replace('%','');
        }
        if(txtLastName.contains('%'))
        {      
        txtLastName=txtLastName.replace('%','');
        }
 
        PageReference Newpage = new PageReference('/apex/SearchWaterCMSUsers?userfirstname=' + txtFirstName + '&userlastname=' + txtLastName);
        Newpage.setRedirect(true);
        return Newpage;
       
    }
 public PageReference Search(){
 
        txtFirstName = this.userfirstname;
        txtLastName = this.userlastname;
        system.debug('FirstName:'+txtFirstName);
        userid = Userinfo.getUserId();
        queryStr = '';
        Isrendered = true;
        //**** We can't include % in the URL
        if(txtFirstName.contains('%'))
        {      
        txtFirstName=txtFirstName.replace('%','');
        }
        if(txtLastName.contains('%'))
        {      
        txtLastName=txtLastName.replace('%','');
        }
 
        PageReference Newpage = new PageReference('/apex/changemanager?userfirstname=' + txtFirstName + '&userlastname=' + txtLastName+'&id='+seluser);
        Newpage.setRedirect(true);
        return Newpage;
       
    }

 
   
    public String userfirstname{
        get{return txtFirstName;}
        set{this.txtFirstName = value;}
    }
   
    public String userlastname{
        get{return this.txtLastName;}
        set{this.txtLastName = value;}
    }
   
 
  
    public List<User> getalluserssvisible(){
        String q = this.getqueryStringUser();
      //system.debug('Length:'+q.length());
        if(q != ''){          
            users = database.query(q);
            return users;   
        } else {
            return null;
        }
    }
   
    private String getqueryStringUser(){
        try
        {
        if(txtFirstName !=null){
            queryStr = 'select id, name,firstname,lastname,email from User u where u.Profile.Name = \'GE_PW WCMS Sales\'';
                   if(txtFirstName.length() > 0) queryStr = queryStr + ' and firstname like \''+txtFirstName+'%\'';
                   if(txtLastName.length() > 0) queryStr = queryStr + ' and lastname like \''+txtLastName+'%\'';
            queryStr = queryStr + ' order by firstname';
            queryStr = queryStr + ' limit 25';
            system.debug('Query String:'+queryStr);}
         else
         { queryStr=''; }
         return queryStr;
        }
        catch (Exception e)
        {
                   return null;
        }   
    }
 
}

  • April 26, 2011
  • Like
  • 0

Hi all,

The following code is almost covered but I need some help with covering some of the code that I dont know how to right coverage for.  Below is the class and test class in the class there is reference to disablexxx = true; and xxxQuoteValue = true;  I need to cover these in my test class.  There is an attempt to cover in the test class but something is not written right.

 

Any help would be great.

 

Class:  disableAuto and such refers to items on my vf page.

 

        if(l.Consumer_Products__c == auto)
        {
            disableAuto = true;
            disableHome = true;
            disableUmbrella = true;
            disableBoat = true;
            disableDwellingFire = true;
            disableThirdParty = true;
            autoQuoteValue = true;
        }
        

 

 

test class:  note the "clc.autoQuoteValue = true;"  running test shows that it is not covered.

 

ApexPages.currentPage().getParameters().put('id', lead.Id);
            ApexPages.StandardController sc = new ApexPages.StandardController(lead);
            Test.startTest();
    
            ConvertLeadController clc = new ConvertLeadController(sc);
            clc.autoQuoteValue = true;
            clc.boatQuoteValue = true;
            clc.dwellingFireQuoteValue = true;
            clc.homeQuoteValue = true;
            clc.thirdPartyQuoteValue = true;
            clc.convertLead();
            

 Thanks in Advance,

Dwayne