function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Achilles21Achilles21 

Extension to override New button

Hi ,

 

I've built the following extension to override new buttong for my Return Object.

<apex:page standardController="Return_Claim__c" extensions="returnExtension">

<apex:pageblock title="Return Claim Edit">

<apex:pageBlockButtons >
 <apex:form >
    <apex:commandButton value="Save" action="{!save}"/>
    <apex:commandButton value="Cancel" action="{!cancel}"/>
 </apex:form>   
</apex:pageBlockButtons>




<apex:pageBlockSection title="Return Details" collapsible="false">

    <apex:pageBlockSectionItem >
        <label><b><font face="arial" color="gray">Return Type</font></b></label> 
        <apex:form > <apex:inputField required="true" value="{!Return_Claim__c.Return_Type__c}"/> </apex:form>
    </apex:pageBlockSectionItem>
     
    <apex:pageBlockSectionItem >
         <label><b><font face="arial" color="gray">Serial Number</font></b></label>
         <apex:form > <apex:inputField required="true" value="{!Return_Claim__c.Serial_Number__c}"/> </apex:form> 
    </apex:pageBlockSectionItem>
     
   </apex:pageBlockSection>
</apex:pageblock>
</apex:page>

 The extension is :

 

public class returnExtension {

    public ApexPages.StandardController con;
    public return_claim__c retn;
    public List<return_claim__c> result;


   
   public returnExtension(ApexPages.StandardController controller) {
        
       con = controller;   
       retn=(return_claim__c)controller.getRecord();
     
    }
    
    public PageReference save()
    {
        con.save();
  //      insert retn;
        return null;
    }


    
   
}

 Everything's working okay in the VF Page.

 

PROBLEM -- when I click on the save button; a record gets created but the values in the corrosponding fields do not get inserted.

 

PLEASE HELP ME OUT. I have tried almost all the dicussions board topics similar to this. nothing's helping.

Best Answer chosen by Admin (Salesforce Developers) 
harsha__charsha__c

Hey, the problem here is the too many form tags.

 

Each form data is treated individual for any action.

 

So, remove all the form tags and use only one form for entire page.

 

Finally, You dont need any extension for this functionality.

 

Your code should be turned out as followed .

 

<apex:page standardController="Return_Claim__c">
<apex:form >
<apex:pageblock title="Return Claim Edit">

<apex:pageBlockButtons >
    <apex:commandButton value="Save" action="{!save}"/>
    <apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>




<apex:pageBlockSection title="Return Details" collapsible="false">

   <apex:pageBlockSectionItem >
        <label><b><font face="arial" color="gray">Return Type</font></b></label> 
        <apex:inputField required="true" value="{!Return_Claim__c.Return_Type__c}"/> 
    </apex:pageBlockSectionItem>
     
    <apex:pageBlockSectionItem >
         <label><b><font face="arial" color="gray">Serial Number</font></b></label>
         <apex:inputField required="true" value="{!Return_Claim__c.Serial_Number__c}"/>  
    </apex:pageBlockSectionItem>
      
   </apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>

 

All Answers

harsha__charsha__c

As you are using StandardController for the page, no need to specify the "Save" method in the controller part.

 

keep the entire logic same but remove the save method from the controller and try running the page.

 

You get the expected result.

Achilles21Achilles21

Hi,

 

Thank for your respose.

 

I tried removing the SAVE method. No improvement ... still record's getting created but no data getting inserted

Thiyagarajan SelvarajThiyagarajan Selvaraj

Your Apex code will be

 

public class returnExtension {

    public ApexPages.StandardController con                {get; set;}
 
   
   public returnExtension(ApexPages.StandardController controller) {
        
       con = controller;   
     
    }
    
    public PageReference save()
    {
      return_claim__c retn = (return_claim__c)con.getRecord();
      insert retn;
      PageReference pageRef = new PageReference('/'+retn.Id);
      pageRef.setRedirect(true);
      return pageRef;
    }
}

harsha__charsha__c

Hey, the problem here is the too many form tags.

 

Each form data is treated individual for any action.

 

So, remove all the form tags and use only one form for entire page.

 

Finally, You dont need any extension for this functionality.

 

Your code should be turned out as followed .

 

<apex:page standardController="Return_Claim__c">
<apex:form >
<apex:pageblock title="Return Claim Edit">

<apex:pageBlockButtons >
    <apex:commandButton value="Save" action="{!save}"/>
    <apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>




<apex:pageBlockSection title="Return Details" collapsible="false">

   <apex:pageBlockSectionItem >
        <label><b><font face="arial" color="gray">Return Type</font></b></label> 
        <apex:inputField required="true" value="{!Return_Claim__c.Return_Type__c}"/> 
    </apex:pageBlockSectionItem>
     
    <apex:pageBlockSectionItem >
         <label><b><font face="arial" color="gray">Serial Number</font></b></label>
         <apex:inputField required="true" value="{!Return_Claim__c.Serial_Number__c}"/>  
    </apex:pageBlockSectionItem>
      
   </apex:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>

 

This was selected as the best answer
Achilles21Achilles21

@Thiyagarajan

Still nothing ....

 

Achilles21Achilles21

@Harsha,

 

Thanks a lot man .. that was great !! it works !!