You need to sign in to do that
Don't have an account?
Ravi sastri
Visualforce page to replace standard new and edit buttons
Hello Developerss,
I have a requirement where I need to replace standard new and edit buttons on record page with VF page. Below is the code which I have got so far.
Everything works fine here. I have replaced this vf page with standard New button and it works fine.
1) But, I do not know how to bind edit button with this page as it has to pre populate values which were entered while creating new record.
2) Save and Cancel buttons are working fine here. Can anyone help me with Save&New functionality with custom apex code.
3) In the above code, there is a field called "Target Sectors". It is enclosed under <apex:actionregion> tag. The name of this field is not populating on the page(Please test this code in your DE for better understanding).
Can anyone help me with above queries as I'm running out of time. Bieng a newbie, I couldnot able to catch what is the better solution for this.
Thanks in advance
RS
I have a requirement where I need to replace standard new and edit buttons on record page with VF page. Below is the code which I have got so far.
<apex:page standardcontroller="Lead" tabstyle="Lead" extensions="ExtensionClass"> <apex:form> <apex:sectionheader title="Lead Edit" subtitle="{!if(Lead.Id==null,'New Lead',Lead.Name)}"></apex:sectionheader> <apex:pageblock mode="edit" id="leadPB" title="Lead Edit"> <apex:pageblockbuttons> <apex:commandbutton action="{!save}" value="Save"></apex:commandbutton> <apex:commandbutton action="{!cancel}" value="Cancel"></apex:commandbutton> </apex:pageblockbuttons> <apex:pagemessages></apex:pagemessages> <!-- displays all message generated by the component --> <apex:pageblocksection id="LeadInformationPBS" title="Lead Information"> <apex:inputField value="{!Lead.OwnerId}"/> <apex:inputfield value="{!Lead.Phone}"></apex:inputfield> <apex:pageblocksectionitem> <apex:outputlabel value="{!$ObjectType.Lead.Fields.FirstName.label}"></apex:outputlabel> <apex:outputpanel> <apex:inputfield value="{!Lead.Salutation}"></apex:inputfield> <apex:inputfield value="{!Lead.FirstName}"></apex:inputfield> </apex:outputpanel> </apex:pageblocksectionitem> <apex:inputfield value="{!Lead.MobilePhone}"></apex:inputfield> <apex:inputfield value="{!Lead.LastName}"></apex:inputfield> <apex:inputfield value="{!Lead.Fax}"></apex:inputfield> <apex:inputField value="{!Lead.Company}" /> <apex:inputfield value="{!Lead.Email}" required="true"></apex:inputfield> <apex:inputfield value="{!Lead.Title}"></apex:inputfield> <apex:inputfield value="{!Lead.Website}"></apex:inputfield> <apex:inputfield value="{!Lead.Leadsource}"></apex:inputfield> <apex:inputfield value="{!Lead.Status}"></apex:inputfield> <apex:inputfield value="{!Lead.Rating}"></apex:inputfield> <apex:inputfield value="{!Lead.Industry}"></apex:inputfield> <apex:inputfield value="{!Lead.NumberOfEmployees}"></apex:inputfield> <apex:actionRegion > Target Sectors: <apex:inputfield value="{!Lead.Target_Sectors__c}"> <apex:actionSupport event="onchange" rerender="TargetSector,theMessage"/> </apex:inputfield> </apex:actionRegion> <apex:outputPanel id="TargetSector"> <apex:pageBlockSection id="ProdFamily" rendered="{!IF(Lead.Target_Sectors__c == 'Other', true, false)}"> <apex:inputfield value="{!Lead.Please_specify_the_Other_reason__c}"/> </apex:pageBlockSection> </apex:outputPanel> </apex:pageblocksection> <apex:pageblocksection id="AddressInformationPBS" title="Address Information" columns="2"> <apex:inputfield value="{!Lead.Street}"></apex:inputfield> <apex:outputtext value=""></apex:outputtext> <apex:inputfield value="{!Lead.Website}"></apex:inputfield> <apex:outputtext value=""></apex:outputtext> <apex:inputfield value="{!Lead.City}"></apex:inputfield> <apex:outputtext value=""></apex:outputtext> <apex:inputfield value="{!Lead.State}"></apex:inputfield> <apex:outputtext value=""></apex:outputtext> <apex:inputfield value="{!Lead.PostalCode}"></apex:inputfield> <apex:outputtext value=""></apex:outputtext> <apex:inputfield value="{!Lead.Country}"></apex:inputfield> <apex:outputtext value=""></apex:outputtext> </apex:pageblocksection> <apex:pageblocksection id="AdditionalInformationPBS" title="Additional Information"> <apex:inputfield value="{!Lead.ProductInterest__c}"></apex:inputfield> <apex:inputfield value="{!Lead.CurrentGenerators__c}"></apex:inputfield> <apex:inputfield value="{!Lead.SICCode__c}"></apex:inputfield> <apex:inputfield value="{!Lead.Primary__c}"></apex:inputfield> <apex:inputfield value="{!Lead.NumberofLocations__c}"></apex:inputfield> </apex:pageblocksection> <apex:pageblocksection id="DescriptionInformationPBS" title="DescriptionInformation"> <apex:inputfield value="{!Lead.Description}"></apex:inputfield> </apex:pageblocksection> <apex:pageblocksection id="OptionPBS" title="Lead Information"> <!-- If you want to have a checkbox to implement whether to use Active Assignment rules you will need to create your own using a custom Apex Extension and method --> </apex:pageblocksection> </apex:pageblock> </apex:form> </apex:page>
Everything works fine here. I have replaced this vf page with standard New button and it works fine.
1) But, I do not know how to bind edit button with this page as it has to pre populate values which were entered while creating new record.
2) Save and Cancel buttons are working fine here. Can anyone help me with Save&New functionality with custom apex code.
3) In the above code, there is a field called "Target Sectors". It is enclosed under <apex:actionregion> tag. The name of this field is not populating on the page(Please test this code in your DE for better understanding).
Can anyone help me with above queries as I'm running out of time. Bieng a newbie, I couldnot able to catch what is the better solution for this.
Thanks in advance
RS
You can write logic for save&new as mentioned above.
BUT , You cannot override custom Save&New button, but when you click save&new , your new and save button code will work behind that.
If you override the new and save button then the functionality of save&new also changes.
Thanks for your concern. When I put the code and add the extension name for my vf page, it is showing the following error
"Unknown constructor 'Extension.Extension(ApexPages.StandardController controller)'"
Can you help me with this..?
Thank you in advance
RS
I've modified the code w.r.t your solution and even then, the error keeps repeating. Below is the code that you suggested along with my vf page.
Vf page:
Extension Class: The error is "Unknown constructor 'MyControllerExtension.MyControllerExtension(ApexPages.StandardController controller)'"
Can yu suggest me which part is to be edited/modified inorder to remove the error.
Thanks in advance
RS
It's wrong, change it to StandardController
We use StandardSetController for standard pagination
I've modified the code and when I hit the save and new button, the following error is showing up
"
Error is in expression '{!saveNew}' in component <apex:commandButton> in page LeadForm: Class.MyControllerExtension.saveNew: line 12, column 1"
Can you help me with this?
Thanks in advance
RK