• Jenifer Alonzo 23
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
I'm working on a VF form that will allow users to quickly enter information, save, and return to a blank form. I have everything working but I can't figure out how to get test coverage on the controller extension. Many thanks for the help. 

Here's the class:
public  class saveAndNew{

     ApexPages.StandardController sController;
    public saveAndNew(ApexPages.StandardController controller) {
        sController = controller;
    }

    public PageReference save() {
        sController.save(); 
        PageReference pg = new PageReference('/apex/Workforce_Contact_Quick_Entry');
        pg.setRedirect(true);
        return pg;
    }
}

Here's the test:
@isTest
    private class saveAndNewTest {
        static testMethod void testQuickContact() 
        
        {
                        Contact myContact = new Contact ();
                	myContact.lastname 	='Test';   
                	myContact.ownerId 	= UserInfo.getUserId();
                   
                    
                
                    insert myContact;
        
       Test.StartTest(); 
  ApexPages.StandardController sc = new ApexPages.StandardController(myContact);
  saveAndNew testQuickContact = new saveAndNew(sc);

            
         PageReference pg = Page.Workforce_Contact_Quick_Entry;
         Pg.getparameters.put();
         test.setCurrentPage(pg);

               
        Test.setCurrentPage(pg);
        
           sc.save();
            
           
        }   
        
    }

 
I am new to both Salesforce and coding. My users want their flows to end at the records that the flows create. I am trying to implement Code Friar's reuseable solution to ending flows on the record just created using Visualforce (https://codefriar.com/2014/04/18/a-reusable-redirect-controller-for-visualflows/)  The istructions say that I  need to create a flow with a decision element called "RedirectFlow" to launch the procss, but I have no idea how I am supposed to configure the decision element within the flow. I suspect I also need to plug more info into the VP page?  I appreciate any help and Many Thanks.

Here's the VF page:
<apex:page Controller="FlowRedirectController">
	<flow:interview name="RedirectFlow" interview="{!redirectTo}" finishLocation="{!finishLocation}" >
		<!-- This Parameter is *required!* -->
		<apex:param name="StartFlow" value="Convert_case_to_Contact" />
		<!-- 
		Any Params you need to pass into your flow.
		<apex:param name="CaseId" value="{!CaseId}"/> 
		-->
	</flow:interview>
</apex:page>
Here's the controller:
Public class FlowRedirectController{
	Public Flow.Interview.RedirectFlow redirectTo {get; set;}

	public FlowRedirectController() {
	    Map<String, Object> forTestingPurposes = new Map<String, Object>();
	    forTestingPurposes.put('newEnrollment','https://louisvilleurbanleague--workforce.lightning.force.com/');
	    redirectTo = new Flow.Interview.RedirectFlow(forTestingPurposes);
	}

	Public PageReference getFinishLocation(){
	  	String finishLocation;
		if(redirectTo != null) {
			finishLocation = (string) redirectTo.getVariableValue('vFinishLocation');
		}
		PageReference send = new PageReference('/' + finishLocation);
		send.setRedirect(true);
		return send;
	}
}

 
I'm working on a VF form that will allow users to quickly enter information, save, and return to a blank form. I have everything working but I can't figure out how to get test coverage on the controller extension. Many thanks for the help. 

Here's the class:
public  class saveAndNew{

     ApexPages.StandardController sController;
    public saveAndNew(ApexPages.StandardController controller) {
        sController = controller;
    }

    public PageReference save() {
        sController.save(); 
        PageReference pg = new PageReference('/apex/Workforce_Contact_Quick_Entry');
        pg.setRedirect(true);
        return pg;
    }
}

Here's the test:
@isTest
    private class saveAndNewTest {
        static testMethod void testQuickContact() 
        
        {
                        Contact myContact = new Contact ();
                	myContact.lastname 	='Test';   
                	myContact.ownerId 	= UserInfo.getUserId();
                   
                    
                
                    insert myContact;
        
       Test.StartTest(); 
  ApexPages.StandardController sc = new ApexPages.StandardController(myContact);
  saveAndNew testQuickContact = new saveAndNew(sc);

            
         PageReference pg = Page.Workforce_Contact_Quick_Entry;
         Pg.getparameters.put();
         test.setCurrentPage(pg);

               
        Test.setCurrentPage(pg);
        
           sc.save();
            
           
        }   
        
    }