• mickpea
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 8
    Replies

Hello All,

 

I have a new issue where I am trying to add a SaveandReturn function to my visualforce page. So that when you click Save it brings you to the original page you started on prior to clicking New Child Record. I believe I have the functionality of this request. Now I am trying to create a test method for it. I feel I am very close.

 

public with sharing class SaveAndReturnController{

    // Field_Service__c fieldservice;
    private ApexPages.StandardController controller;
    public SaveAndReturnController(ApexPages.StandardController controller) {
    this.controller = controller;
    }

    public PageReference SaveAndReturn(){
        controller.save();
        PageReference returnPage = controller.cancel();
        returnPage.setRedirect(true);
        return returnPage;
    }
    
    static testmethod void testSaveAndReturnController(){

    Field_Service__c fieldService = new Field_Service__c();
    insert fieldService;
    ApexPages.StandardController controller = new ApexPages.standardController(fieldService);
  
    SaveAndReturnController testSARC = 
      new SaveAndReturnController(controller);
  
    system.assertEquals(testSARC.SaveAndReturn(), returnPage);
  }


}

 I am receiving an issue that "Variable does not exist: returnPage".

 

I attempted to resolve this by editing the code to this below:

public with sharing class SaveAndReturnController{

    // Field_Service__c fieldservice;
    private ApexPages.StandardController controller;
    public SaveAndReturnController(ApexPages.StandardController controller) {
    this.controller = controller;
    }

    public PageReference SaveAndReturn(){
        controller.save();
        PageReference returnPage = controller.cancel();
        returnPage.setRedirect(true);
        return returnPage;
    }
    
    static testmethod void testSaveAndReturnController(){

    Field_Service__c fieldService = new Field_Service__c();
    insert fieldService;
    ApexPages.StandardController controller = new ApexPages.standardController(fieldService);
  
    SaveAndReturnController testSARC = 
      new SaveAndReturnController(controller);
  
    system.assertEquals(controller.cancel().getURL(), testSARC.SaveAndReturn().getURL());
  }


}

 However, when I run the test it fails and gives 0% test coverage. Can anyone kindly explain what it is I am doing wrong? This is my first controller extension so any help is appreciated.

Hello there!

 

This is my first post and I am incredibly new at creating VisualForce pages so please bear with me!

I have been searching the forums and reading up on a few different resources to accomplish my needs and I am comfortable creating the main content in my VisualForce page.

 

I created a custom button on my Case Detail page that navigates me to my VF page when a New Field Service needs to be created. All is working well (for the most part, still trying to figure out how to reliably fill in two look-up fields).

 

The problem I have is I want the "Save" button on the VF page to take me back to the original object and fill in a custom field on the Case Detail page with the service record created. I believe I have to do this with a Controller but I am getting confused as to how to implement this controller (as I am new to this). Also, is there a way to just link the VF custom button to the Case Detail page without a Controller?

 

The code for my VisualForce page is as follows:

 

<apex:page standardController="Field_Service__c">
  <apex:form >
    <apex:pageBlock title="New Field Service" mode="edit" id="thePageBlock">
      
      <apex:pageBlockButtons >
        <apex:commandButton action="retURL=/{!Field_Service__c.Case__c}+CF00NC0000005NROt={!Field_Service__c.Name}" value="Save"/>
        <apex:commandButton action="{!cancel}" value="Cancel"/>
      </apex:pageBlockButtons>
      
      <apex:pageBlockSection title="Information" columns="2">
        <apex:inputField value="{!Field_Service__c.Name}"/>
        <apex:inputField value="{!Field_Service__c.Store_Detail__c}"/>
        <apex:inputField value="{!Field_Service__c.Date_of_Service__c}"/>
        <apex:inputField value="{!Field_Service__c.Case__c}"/>
        <apex:inputField value="{!Field_Service__c.Field_Service_Name__c}"/>
        <apex:inputCheckbox value="{!Field_Service__c.Parts_Used__c}">
            <apex:actionSupport event="onchange"
                                rerender="thePageBlock"
                                status="status"/>
        </apex:inputCheckbox>
        <apex:inputField value="{!Field_Service__c.Field_Service_Description__c}" style="width: 98%; height: 40px"/>
        <apex:inputCheckbox value="{!Field_Service__c.Equipment_Rented__c}">
            <apex:actionSupport event="onchange"
                                rerender="thePageBlock"
                                status="status"/>
        </apex:inputCheckbox>
        <apex:pageBlockSectionItem ></apex:pageBlockSectionItem>
        <apex:actionStatus startText="Updating..." id="status"/>


      </apex:pageBlockSection>
      <apex:pageBlockSection title="Parts"  
      columns="2">
          <apex:inputField value="{!Field_Service__c.Service_Performed_By__c}">
              <apex:actionSupport event="onchange"
                                  rerender="thePageBlock"
                                  status="status"/>
          </apex:inputField>
          <apex:pageBlockSectionItem ></apex:pageBlockSectionItem>
          <apex:inputField value="{!Field_Service__c.Agilence_Technician__c}"
              rendered="{!Field_Service__c.Service_Performed_By__c='Agilence Customer Support' || Field_Service__c.Service_Performed_By__c='Both'}"/>
          <apex:inputField value="{!Field_Service__c.Contractor__c}"
              rendered="{!Field_Service__c.Service_Performed_By__c='External Contractor' || Field_Service__c.Service_Performed_By__c='Both'}"/>
      </apex:pageBlockSection>
      
      <apex:pageBlockSection title="Parts"  
      columns="1" 
      rendered="{!Field_Service__c.Parts_Used__c=true}">
       
        <apex:dataTable value="{!Field_Service__c}" var="part" 
        border="1" 
        cellspacing="4" 
        cellpadding="4" 
        align="center" 
        style="text-align: center; width: 80%"> 
             <apex:column headerValue="Quantity" style="width: 10%">
                  <apex:inputField value="{!Field_Service__c.Part_1_Quantity__c}" style="width: 99%"/>
                  <apex:inputField value="{!Field_Service__c.Part_2_Quantity__c}" style="width: 99%"/>
                  <apex:inputField value="{!Field_Service__c.Part_3_Quantity__c}" style="width: 99%"/>
                  <apex:inputField value="{!Field_Service__c.Part_4_Quantity__c}" style="width: 99%"/>
             </apex:column>
             <apex:column headerValue="Part Name" style="width: 20%">
                  <apex:inputField value="{!Field_Service__c.Part_1__c}" style="width: 99%"/>
                  <apex:inputField value="{!Field_Service__c.Part_2__c}" style="width: 99%"/>
                  <apex:inputField value="{!Field_Service__c.Part_3__c}" style="width: 99%"/>
                  <apex:inputField value="{!Field_Service__c.Part_4__c}" style="width: 99%"/>
             </apex:column>
              <apex:column headerValue="Model Number" style="width: 20%">
                  <apex:inputField value="{!Field_Service__c.Part_1_Model_Number__c}" style="width: 99%"/>
                  <apex:inputField value="{!Field_Service__c.Part_2_Model_Number__c}" style="width: 99%"/>
                  <apex:inputField value="{!Field_Service__c.Part_3_Model_Number__c}" style="width: 99%"/>
                  <apex:inputField value="{!Field_Service__c.Part_4_Model_Number__c}" style="width: 99%"/>
             </apex:column>
         <apex:column headerValue="Serial Number" style="width: 20%">
          <apex:inputField value="{!Field_Service__c.Part_1_Serial_Number__c}" style="width: 99%"/>
          <apex:inputField value="{!Field_Service__c.Part_2_Serial_Number__c}" style="width: 99%"/>
          <apex:inputField value="{!Field_Service__c.Part_3_Serial_Number__c}" style="width: 99%"/>
          <apex:inputField value="{!Field_Service__c.Part_4_Serial_Number__c}" style="width: 99%"/>
         </apex:column>
         <apex:column headerValue="Cost" style="width: 10%">
          <apex:inputField value="{!Field_Service__c.Part_1_Cost__c}" style="width: 99%"/>
          <apex:inputField value="{!Field_Service__c.Part_2_Cost__c}" style="width: 99%"/>
          <apex:inputField value="{!Field_Service__c.Part_3_Cost__c}" style="width: 99%"/>
          <apex:inputField value="{!Field_Service__c.Part_4_Cost__c}" style="width: 99%"/>
         </apex:column>
        </apex:dataTable>
      </apex:pageBlockSection>
      <apex:pageBlockSection title="Equipment"  
      columns="2" 
      rendered="{!Field_Service__c.Equipment_Rented__c=true}">
          <apex:inputField value="{!Field_Service__c.List_Equipment_Rented__c}" style="width: 99%"/>
          <apex:inputField value="{!Field_Service__c.Equipment_Rental_Cost__c}" style="width: 25%"/>
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

 I know there are many improvements to be made to my code. I just want to nail down basic functionality first before I begin to refine it.

 

Any suggestions are greatly appreciated!

Hello All,

 

I have a new issue where I am trying to add a SaveandReturn function to my visualforce page. So that when you click Save it brings you to the original page you started on prior to clicking New Child Record. I believe I have the functionality of this request. Now I am trying to create a test method for it. I feel I am very close.

 

public with sharing class SaveAndReturnController{

    // Field_Service__c fieldservice;
    private ApexPages.StandardController controller;
    public SaveAndReturnController(ApexPages.StandardController controller) {
    this.controller = controller;
    }

    public PageReference SaveAndReturn(){
        controller.save();
        PageReference returnPage = controller.cancel();
        returnPage.setRedirect(true);
        return returnPage;
    }
    
    static testmethod void testSaveAndReturnController(){

    Field_Service__c fieldService = new Field_Service__c();
    insert fieldService;
    ApexPages.StandardController controller = new ApexPages.standardController(fieldService);
  
    SaveAndReturnController testSARC = 
      new SaveAndReturnController(controller);
  
    system.assertEquals(testSARC.SaveAndReturn(), returnPage);
  }


}

 I am receiving an issue that "Variable does not exist: returnPage".

 

I attempted to resolve this by editing the code to this below:

public with sharing class SaveAndReturnController{

    // Field_Service__c fieldservice;
    private ApexPages.StandardController controller;
    public SaveAndReturnController(ApexPages.StandardController controller) {
    this.controller = controller;
    }

    public PageReference SaveAndReturn(){
        controller.save();
        PageReference returnPage = controller.cancel();
        returnPage.setRedirect(true);
        return returnPage;
    }
    
    static testmethod void testSaveAndReturnController(){

    Field_Service__c fieldService = new Field_Service__c();
    insert fieldService;
    ApexPages.StandardController controller = new ApexPages.standardController(fieldService);
  
    SaveAndReturnController testSARC = 
      new SaveAndReturnController(controller);
  
    system.assertEquals(controller.cancel().getURL(), testSARC.SaveAndReturn().getURL());
  }


}

 However, when I run the test it fails and gives 0% test coverage. Can anyone kindly explain what it is I am doing wrong? This is my first controller extension so any help is appreciated.

Hello there!

 

This is my first post and I am incredibly new at creating VisualForce pages so please bear with me!

I have been searching the forums and reading up on a few different resources to accomplish my needs and I am comfortable creating the main content in my VisualForce page.

 

I created a custom button on my Case Detail page that navigates me to my VF page when a New Field Service needs to be created. All is working well (for the most part, still trying to figure out how to reliably fill in two look-up fields).

 

The problem I have is I want the "Save" button on the VF page to take me back to the original object and fill in a custom field on the Case Detail page with the service record created. I believe I have to do this with a Controller but I am getting confused as to how to implement this controller (as I am new to this). Also, is there a way to just link the VF custom button to the Case Detail page without a Controller?

 

The code for my VisualForce page is as follows:

 

<apex:page standardController="Field_Service__c">
  <apex:form >
    <apex:pageBlock title="New Field Service" mode="edit" id="thePageBlock">
      
      <apex:pageBlockButtons >
        <apex:commandButton action="retURL=/{!Field_Service__c.Case__c}+CF00NC0000005NROt={!Field_Service__c.Name}" value="Save"/>
        <apex:commandButton action="{!cancel}" value="Cancel"/>
      </apex:pageBlockButtons>
      
      <apex:pageBlockSection title="Information" columns="2">
        <apex:inputField value="{!Field_Service__c.Name}"/>
        <apex:inputField value="{!Field_Service__c.Store_Detail__c}"/>
        <apex:inputField value="{!Field_Service__c.Date_of_Service__c}"/>
        <apex:inputField value="{!Field_Service__c.Case__c}"/>
        <apex:inputField value="{!Field_Service__c.Field_Service_Name__c}"/>
        <apex:inputCheckbox value="{!Field_Service__c.Parts_Used__c}">
            <apex:actionSupport event="onchange"
                                rerender="thePageBlock"
                                status="status"/>
        </apex:inputCheckbox>
        <apex:inputField value="{!Field_Service__c.Field_Service_Description__c}" style="width: 98%; height: 40px"/>
        <apex:inputCheckbox value="{!Field_Service__c.Equipment_Rented__c}">
            <apex:actionSupport event="onchange"
                                rerender="thePageBlock"
                                status="status"/>
        </apex:inputCheckbox>
        <apex:pageBlockSectionItem ></apex:pageBlockSectionItem>
        <apex:actionStatus startText="Updating..." id="status"/>


      </apex:pageBlockSection>
      <apex:pageBlockSection title="Parts"  
      columns="2">
          <apex:inputField value="{!Field_Service__c.Service_Performed_By__c}">
              <apex:actionSupport event="onchange"
                                  rerender="thePageBlock"
                                  status="status"/>
          </apex:inputField>
          <apex:pageBlockSectionItem ></apex:pageBlockSectionItem>
          <apex:inputField value="{!Field_Service__c.Agilence_Technician__c}"
              rendered="{!Field_Service__c.Service_Performed_By__c='Agilence Customer Support' || Field_Service__c.Service_Performed_By__c='Both'}"/>
          <apex:inputField value="{!Field_Service__c.Contractor__c}"
              rendered="{!Field_Service__c.Service_Performed_By__c='External Contractor' || Field_Service__c.Service_Performed_By__c='Both'}"/>
      </apex:pageBlockSection>
      
      <apex:pageBlockSection title="Parts"  
      columns="1" 
      rendered="{!Field_Service__c.Parts_Used__c=true}">
       
        <apex:dataTable value="{!Field_Service__c}" var="part" 
        border="1" 
        cellspacing="4" 
        cellpadding="4" 
        align="center" 
        style="text-align: center; width: 80%"> 
             <apex:column headerValue="Quantity" style="width: 10%">
                  <apex:inputField value="{!Field_Service__c.Part_1_Quantity__c}" style="width: 99%"/>
                  <apex:inputField value="{!Field_Service__c.Part_2_Quantity__c}" style="width: 99%"/>
                  <apex:inputField value="{!Field_Service__c.Part_3_Quantity__c}" style="width: 99%"/>
                  <apex:inputField value="{!Field_Service__c.Part_4_Quantity__c}" style="width: 99%"/>
             </apex:column>
             <apex:column headerValue="Part Name" style="width: 20%">
                  <apex:inputField value="{!Field_Service__c.Part_1__c}" style="width: 99%"/>
                  <apex:inputField value="{!Field_Service__c.Part_2__c}" style="width: 99%"/>
                  <apex:inputField value="{!Field_Service__c.Part_3__c}" style="width: 99%"/>
                  <apex:inputField value="{!Field_Service__c.Part_4__c}" style="width: 99%"/>
             </apex:column>
              <apex:column headerValue="Model Number" style="width: 20%">
                  <apex:inputField value="{!Field_Service__c.Part_1_Model_Number__c}" style="width: 99%"/>
                  <apex:inputField value="{!Field_Service__c.Part_2_Model_Number__c}" style="width: 99%"/>
                  <apex:inputField value="{!Field_Service__c.Part_3_Model_Number__c}" style="width: 99%"/>
                  <apex:inputField value="{!Field_Service__c.Part_4_Model_Number__c}" style="width: 99%"/>
             </apex:column>
         <apex:column headerValue="Serial Number" style="width: 20%">
          <apex:inputField value="{!Field_Service__c.Part_1_Serial_Number__c}" style="width: 99%"/>
          <apex:inputField value="{!Field_Service__c.Part_2_Serial_Number__c}" style="width: 99%"/>
          <apex:inputField value="{!Field_Service__c.Part_3_Serial_Number__c}" style="width: 99%"/>
          <apex:inputField value="{!Field_Service__c.Part_4_Serial_Number__c}" style="width: 99%"/>
         </apex:column>
         <apex:column headerValue="Cost" style="width: 10%">
          <apex:inputField value="{!Field_Service__c.Part_1_Cost__c}" style="width: 99%"/>
          <apex:inputField value="{!Field_Service__c.Part_2_Cost__c}" style="width: 99%"/>
          <apex:inputField value="{!Field_Service__c.Part_3_Cost__c}" style="width: 99%"/>
          <apex:inputField value="{!Field_Service__c.Part_4_Cost__c}" style="width: 99%"/>
         </apex:column>
        </apex:dataTable>
      </apex:pageBlockSection>
      <apex:pageBlockSection title="Equipment"  
      columns="2" 
      rendered="{!Field_Service__c.Equipment_Rented__c=true}">
          <apex:inputField value="{!Field_Service__c.List_Equipment_Rented__c}" style="width: 99%"/>
          <apex:inputField value="{!Field_Service__c.Equipment_Rental_Cost__c}" style="width: 25%"/>
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

 I know there are many improvements to be made to my code. I just want to nail down basic functionality first before I begin to refine it.

 

Any suggestions are greatly appreciated!