• Gstart
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 2
    Replies
Any one kinldy help me in writing test class for the below code
public class UserAccountsExtension {        
    //Variable Declaration
    boolean showReg=true;
    public UserAccount__c objAccount{get;set;} 
    public List<UserAccount__c> uAccount{get;set;} 
    public Employee_Detail__c addEmployee{get;set;}      
    public List<Employee_Detail__c> uEmployeeDetail{get;set;}    
    public blob userlogo{get;set;}
    public string userlogoname{get;set;}
    public String userlogourl{get;set;}
    public Attachment userimage{get;set;}
    public Attachment companyLogo{get;set;}
    public string objID{get;set;}
    
    public UserAccountsExtension(){                        
        this.uAccount = [select First_Name__c,Last_Name__c,Phone__c,Email__c,UserLogo__c,Role__c,Company_Name__c,Location__c from UserAccount__c where Id=''];        
        this.uEmployeeDetail = [select First_Name__c,Last_Name__c,Employee_ID__c from Employee_Detail__c where Id=''];        
		if (this.uEmployeeDetail.size() == 0)
        {
            addEmployee=new Employee_Detail__c();        	
        	this.uEmployeeDetail.add(addEmployee);
        }    
        if (this.uAccount.size() ==0)
        {
            objAccount=new UserAccount__c();        	
        	this.uAccount.add(objAccount);
        }    
    } 
    public PageReference checkStep1()
    {
        return null;
        If(uAccount[0].First_Name__c==null||uAccount[0].First_Name__c=='')
            {
                PageReference step1=new PageReference('/apex/RegisterStep1');
                return step1;
            }
        else
        {
        	return null;
        }        
    }
    public PageReference movetoStep1()
    {                
        PageReference nextPage=new PageReference('/apex/RegisterStep1');
        nextPage.setRedirect(false);
        return nextPage;
    }
    public PageReference movetoStep2()
    {
		/*if(userimage.name==''||userimage.name==null)        
        {           
			userimage.body = userlogo; 
			userimage.name = 'userlogo'; 			
			userimage.ContentType = 'application/jpg'; 
        }	*/	
        PageReference nextPage=new PageReference('/apex/SampleLogin');
        nextPage.setRedirect(false);
        return nextPage;
    }
    public PageReference movetoStep3()
    {                
        PageReference nextPage=new PageReference('/apex/RegisterStep3');
        nextPage.setRedirect(false);
        return nextPage;
    }
    public PageReference gotoConfirmation()
    {
    	PageReference nextPage=new PageReference('/apex/Confirmation');
        nextPage.setRedirect(false);
        return nextPage;
    }
	public PageReference mysave() { 
        insert uAccount;
        for(integer i=0;i<uEmployeeDetail.size();i++)
        {
        	uEmployeeDetail[i].UserAutoID__c=this.uAccount[0].id;
        }
        if (uEmployeeDetail.size()>0)
        {
            insert uEmployeeDetail;
        }        
        PageReference pv=new pageReference(ApexPages.currentPage().getURL());   
        if (!ApexPages.hasMessages())
        {showReg=false;}   
        else
        {pv.setRedirect(FALSE);}    	     
        return pv; 
    }
       
    public void addRow()
    {
        addEmployee=new Employee_Detail__c();       
        uEmployeeDetail.add(addEmployee);
    }    
        
    public boolean getShowRegistration()
    {     
        return showReg;
    }  

}

 
These are my current setup
- 1 custom controller
- 2 vf pages using the same custom controller
- 2 custom objects where page 1 uses object 1 and page 2 uses object 2(User inputs data for object 1 in page 1 and object 2 in page 2)

My requirement is, I should be able to move back and forth between page 1 and 2, and I should be able to hold the data entered by the user when moving between pages. Note: The user haven't saved the data yet when moving between pages. 
 
public class customController{

public Object1__c object1{get;set;}

public Object2__c object2{get;set;}

public customController()
{
       Id id = ApexPages.currentPage().getParameters().get('id');

       this.object1=(id == null) ? new Object1__c () :[select field1__c,field2__c from Object1__c where Id=:id ];

       //will this work and is it correct??
       this.object2=(id == null) ? new Object2__c () [select field3__c,field4__c from Object2__c where Id=:id ];
}


I have shared a sample of the logic I have written to retrieve the data in the constructor. Apparently, this seems to work and the data is still available when moving between pages, but is this correct?(I am using a single variable "id" to retrieve data from last page for both objects) And I am unable to write a test class, because it fails in the constructor
I have shared my custom controller class and I need some help on writing test class for the same. Kindly let me know how to proceed
public class UserAccountsExtension {        
    //Variable Declaration
    boolean showReg=true;
    public UserAccount__c uAccount{get;set;} 
    public Employee_Detail__c addEmployee{get;set;}  
    public List<Employee_Detail__c> uEmployeeDetail{get;set;}      
    
    public UserAccountsExtension(){                
        
        Id id = ApexPages.currentPage().getParameters().get('id'); 
        String pgName=ApexPages.currentPage().getUrl().substringAfter('/apex/').substringBefore('?');
        this.uAccount = (id == null) ? new UserAccount__c() :[select First_Name__c,Last_Name__c,Phone__c,Email__c,UserLogo__c,Role__c,Company_Name__c,Location__c from UserAccount__c where Id=: id];        
        this.uEmployeeDetail = (id == null) ? new List<Employee_Detail__c>() : [select First_Name__c,Last_Name__c,Employee_ID__c from Employee_Detail__c where Id=:id];        
        		if (this.uEmployeeDetail.size() ==0)
        {
            addEmployee=new Employee_Detail__c();        	
        	this.uEmployeeDetail.add(addEmployee);
        }       
    } 
    public PageReference checkStep1()
    {
        If(uAccount.First_Name__c==null||uAccount.First_Name__c=='')
            {
                PageReference step1=new PageReference('/apex/RegisterStep1');
                return step1;
            }
        else
        {
        	return null;
        }        
    }
    public PageReference movetoStep1()
    {                
        PageReference nextPage=new PageReference('/apex/RegisterStep1');
        nextPage.setRedirect(false);
        return nextPage;
    }
    public PageReference movetoStep2()
    {
		/*if(userimage.name==''||userimage.name==null)        
        {           
			userimage.body = userlogo; 
			userimage.name = 'userlogo'; 			
			userimage.ContentType = 'application/jpg'; 
        }	*/	
        PageReference nextPage=new PageReference('/apex/SampleLogin');
        nextPage.setRedirect(false);
        return nextPage;
    }
    public PageReference movetoStep3()
    {                
        PageReference nextPage=new PageReference('/apex/RegisterStep3');
        nextPage.setRedirect(false);
        return nextPage;
    }
    public PageReference gotoConfirmation()
    {
    	PageReference nextPage=new PageReference('/apex/Confirmation');
        nextPage.setRedirect(false);
        return nextPage;
    }
	public PageReference mysave() { 
        insert uAccount;
        for(integer i=0;i<uEmployeeDetail.size();i++)
        {
        	uEmployeeDetail[i].UserAutoID__c=this.uAccount.id;
        }
        insert uEmployeeDetail;
        PageReference pv=new pageReference(ApexPages.currentPage().getURL());   
        if (!ApexPages.hasMessages())
        {showReg=false;}   
        else
        {pv.setRedirect(FALSE);}    	     
        return pv; 
    }
       
    public void addRow()
    {
        addEmployee=new Employee_Detail__c();       
        uEmployeeDetail.add(addEmployee);
    }    
        
    public boolean getShowRegistration()
    {     
        return showReg;
    }
        
}

 
I have designed a page where I get the user to upload an image in >apex:inputFile>. Now, I should pass the selected image to the next page and only should save it after user clicks on the "Submit" button in the next page. How should I do this?
I have created a page where I am getting input data for a custom object and saving it. As of now, I can save one record but I want to expand it to multiple records. How do I achieve it? The requirements are
i) User will be shown input fieds for first record when opening the page
ii) He can choose to add more rows to a max count of 20(Add rows by clicking "Add" button)
iii) Save all data once "Save" button is clicked
<tr>
                    	<td>
                            <apex:outputText value="First Name" styleClass="col-form-label"/>
                        </td>
                        <td>
                            <apex:inputText value="{!uAccount.First_Name__c}" html-placeholder="First Name" />
                        </td>
                        <td>
                            <apex:outputText value="Last Name" styleClass="col-form-label" />
                        </td>
                        <td>
                            <apex:inputText value="{!uAccount.Last_Name__c}" html-placeholder="Last Name" />                                          
                        </td>
                     </tr>

This is a sample code I have created to get first name and last name. This should be modified so that user can enter mutliple names if he want and save everything to the object. I have modified the object as a list object in apex class but do not know how to implement it in visualforce page
I am new to development and trying to figure out the best way to pass data between pages. I have done the following right now
i) Created 2 custom objects
ii) Created 2 visualforce pages using one object each
iii) One controller class for both the pages
I get the input for 1st object in the first page and then pass them to the second page where I get the input for the 2nd object and then save both together in the second page.(No save happens in first page)

I created one custom class for both the pages but I have mentioned it as the extension class in the visualforce page.

When I navigate from Page1 to Page2, how do I pass all the data entered in the first page. I tried using ApexPages.StandardController in the constructor and then using sc.getRecord() but it throws an error because the object differs between pages. It works only when I use same object in both pages.





 
These are my current setup
- 1 custom controller
- 2 vf pages using the same custom controller
- 2 custom objects where page 1 uses object 1 and page 2 uses object 2(User inputs data for object 1 in page 1 and object 2 in page 2)

My requirement is, I should be able to move back and forth between page 1 and 2, and I should be able to hold the data entered by the user when moving between pages. Note: The user haven't saved the data yet when moving between pages. 
 
public class customController{

public Object1__c object1{get;set;}

public Object2__c object2{get;set;}

public customController()
{
       Id id = ApexPages.currentPage().getParameters().get('id');

       this.object1=(id == null) ? new Object1__c () :[select field1__c,field2__c from Object1__c where Id=:id ];

       //will this work and is it correct??
       this.object2=(id == null) ? new Object2__c () [select field3__c,field4__c from Object2__c where Id=:id ];
}


I have shared a sample of the logic I have written to retrieve the data in the constructor. Apparently, this seems to work and the data is still available when moving between pages, but is this correct?(I am using a single variable "id" to retrieve data from last page for both objects) And I am unable to write a test class, because it fails in the constructor
I am new to development and trying to figure out the best way to pass data between pages. I have done the following right now
i) Created 2 custom objects
ii) Created 2 visualforce pages using one object each
iii) One controller class for both the pages
I get the input for 1st object in the first page and then pass them to the second page where I get the input for the 2nd object and then save both together in the second page.(No save happens in first page)

I created one custom class for both the pages but I have mentioned it as the extension class in the visualforce page.

When I navigate from Page1 to Page2, how do I pass all the data entered in the first page. I tried using ApexPages.StandardController in the constructor and then using sc.getRecord() but it throws an error because the object differs between pages. It works only when I use same object in both pages.