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
jon85943jon85943 

Creating an Edit Page using Visualforce

Hi All,

 

I am having trouble creating an edit page using Visualforce.  We created a visualforce page for a custom object and have assigned this visualforce page for the custom object page layout.  We want to create a visualforce page for the edit function as well but I am having issues creating this.  I think we may need to create a controller extension but I am not sure. Here is the sample code we have for our page layout. All we want is to allow this page layout to be edited using a visualforce page.

 

 

 

<apex:page standardController="Sharing_ES__c">
	<apex:sectionHeader title="{!$ObjectType.Sharing_ES__c.label}" subtitle="{!Sharing_ES__c.name}"/>
	<apex:pageBlock title="{!$ObjectType.Sharing_ES__c.label} Detail">
		<apex:pageBlockButtons >
		<apex:form >
			<apex:commandButton action="{!edit}" value="Edit"/>
			<apex:commandButton action="{!delete}" value="Delete"/>
			<apex:commandButton action="{!URLFOR($Action.Sharing_ES__c.Clone,Sharing_ES__c.id)}" value="Clone"/>
		</apex:form>
		</apex:pageBlockButtons>
		<apex:pageBlockSection showHeader="false" columns="2">
			<apex:outputField value="{!Sharing_ES__c.Name}"/>
			<apex:pageBlockSectionItem >
				<apex:outputLabel value="Custom Sharing Owner"/>
				<apex:outputPanel >
					<apex:outputField value="{!Sharing_ES__c.OwnerId}"/>&nbsp;
					<apex:outputLink value="{!URLFOR($Action.Sharing_ES__c.ChangeOwner,Sharing_ES__c.id)}">[Change]</apex:outputLink>
				</apex:outputPanel>
			</apex:pageBlockSectionItem>
			<apex:outputField value="{!Sharing_ES__c.Sharing_Type__c}"/>
			<apex:outputField value="{!Sharing_ES__c.Account__c}"/>
			<apex:outputField value="{!Sharing_ES__c.Record_Type__c}"/>
			<apex:outputField value="{!Sharing_ES__c.isActive__c}"/>
			<apex:outputField value="{!Sharing_ES__c.Access_Type__c}"/>
			<apex:outputField value="{!Sharing_ES__c.Description__c}"/>
			<apex:outputField value="{!Sharing_ES__c.User__c}"/>
			<apex:pageBlockSectionItem />
			<apex:outputField value="{!Sharing_ES__c.Group__c}"/>
			<apex:pageBlockSectionItem />
		</apex:pageBlockSection>
		<apex:pageBlockSection showHeader="false" columns="2">
			<apex:outputField value="{!Sharing_ES__c.CreatedById}"/>
			<apex:outputField value="{!Sharing_ES__c.LastModifiedById}"/>
		</apex:pageBlockSection>
		<apex:pageBlockSection showHeader="true" title="Custom Links" columns="3">
		</apex:pageBlockSection>
	</apex:pageBlock>
</apex:page>
			

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Kent ManningKent Manning

If I understand you question properly, there are three things I see that may be causing you problems.  First the <apex:form> tag needs to encompass the entire code.   Second, all of your <apex:outputField/> tags need to change to <apex:inputField/> tags, and third you need to have the mode set to edit.   See red text below.

 

Hope this gets you going again.

 

 

<apex:page standardController="Sharing_ES__c">
	<apex:sectionHeader title="{!$ObjectType.Sharing_ES__c.label}" subtitle="{!Sharing_ES__c.name}"/>
	<apex:pageBlock title="{!$ObjectType.Sharing_ES__c.label} Detail" mode="edit">
		<apex:pageBlockButtons >
		<apex:form >
			<apex:commandButton action="{!edit}" value="Edit"/>
			<apex:commandButton action="{!delete}" value="Delete"/> apex:commandButtonaction{!URLFOR($Action.Sharing_ES__c.Clone,Sharing_ES__c.id)}" value="Clone"/>
		</apex:form>
		</apex:pageBlockButtons>
		<apex:pageBlockSection showHeader="false" columns="2">
			<apex:outputField inputField value="{!Sharing_ES__c.Name}"/>
			<apex:pageBlockSectionItem >
				<apex:outputLabel value="Custom Sharing Owner"/>
				<apex:outputPanel >
					<apex:outputField value="{!Sharing_ES__c.OwnerId}"/>&nbsp;
					<apex:outputLink value="{!URLFOR($Action.Sharing_ES__c.ChangeOwner,Sharing_ES__c.id)}">[Change]</apex:outputLink>
				</apex:outputPanel>
			</apex:pageBlockSectionItem>
			<apex:outputField value="{!Sharing_ES__c.Sharing_Type__c}"/>
			<apex:outputField value="{!Sharing_ES__c.Account__c}"/>
			<apex:outputField value="{!Sharing_ES__c.Record_Type__c}"/>
			<apex:outputField value="{!Sharing_ES__c.isActive__c}"/>
			<apex:outputField value="{!Sharing_ES__c.Access_Type__c}"/>
			<apex:outputField value="{!Sharing_ES__c.Description__c}"/>
			<apex:outputField value="{!Sharing_ES__c.User__c}"/>
			<apex:pageBlockSectionItem />
			<apex:outputField value="{!Sharing_ES__c.Group__c}"/>
			<apex:pageBlockSectionItem />
		</apex:pageBlockSection>
		<apex:pageBlockSection showHeader="false" columns="2">
			<apex:outputField value="{!Sharing_ES__c.CreatedById}"/>
			<apex:outputField value="{!Sharing_ES__c.LastModifiedById}"/>
		</apex:pageBlockSection>
		<apex:pageBlockSection showHeader="true" title="Custom Links" columns="3"> 
     </apex:pageBlockSection>
   </apex:form> 
   </apex:pageBlock>
 </apex:page>

 

 

 

All Answers

bob_buzzardbob_buzzard

Have you created an edit button override for the object?  That's all you should need to do I believe.  Then the standard controller edit should end up on that page.

jon85943jon85943

When I click Edit for the Edit button override and assign the VF page I am trying to create the Edit page for, on the sample record when I click edit it just brings back the same record layout as if I didnt click edit.  There are no editable options available.  Do I need to create a new VF Page with any specific edit function on each of the fields?

Kent ManningKent Manning

If I understand you question properly, there are three things I see that may be causing you problems.  First the <apex:form> tag needs to encompass the entire code.   Second, all of your <apex:outputField/> tags need to change to <apex:inputField/> tags, and third you need to have the mode set to edit.   See red text below.

 

Hope this gets you going again.

 

 

<apex:page standardController="Sharing_ES__c">
	<apex:sectionHeader title="{!$ObjectType.Sharing_ES__c.label}" subtitle="{!Sharing_ES__c.name}"/>
	<apex:pageBlock title="{!$ObjectType.Sharing_ES__c.label} Detail" mode="edit">
		<apex:pageBlockButtons >
		<apex:form >
			<apex:commandButton action="{!edit}" value="Edit"/>
			<apex:commandButton action="{!delete}" value="Delete"/> apex:commandButtonaction{!URLFOR($Action.Sharing_ES__c.Clone,Sharing_ES__c.id)}" value="Clone"/>
		</apex:form>
		</apex:pageBlockButtons>
		<apex:pageBlockSection showHeader="false" columns="2">
			<apex:outputField inputField value="{!Sharing_ES__c.Name}"/>
			<apex:pageBlockSectionItem >
				<apex:outputLabel value="Custom Sharing Owner"/>
				<apex:outputPanel >
					<apex:outputField value="{!Sharing_ES__c.OwnerId}"/>&nbsp;
					<apex:outputLink value="{!URLFOR($Action.Sharing_ES__c.ChangeOwner,Sharing_ES__c.id)}">[Change]</apex:outputLink>
				</apex:outputPanel>
			</apex:pageBlockSectionItem>
			<apex:outputField value="{!Sharing_ES__c.Sharing_Type__c}"/>
			<apex:outputField value="{!Sharing_ES__c.Account__c}"/>
			<apex:outputField value="{!Sharing_ES__c.Record_Type__c}"/>
			<apex:outputField value="{!Sharing_ES__c.isActive__c}"/>
			<apex:outputField value="{!Sharing_ES__c.Access_Type__c}"/>
			<apex:outputField value="{!Sharing_ES__c.Description__c}"/>
			<apex:outputField value="{!Sharing_ES__c.User__c}"/>
			<apex:pageBlockSectionItem />
			<apex:outputField value="{!Sharing_ES__c.Group__c}"/>
			<apex:pageBlockSectionItem />
		</apex:pageBlockSection>
		<apex:pageBlockSection showHeader="false" columns="2">
			<apex:outputField value="{!Sharing_ES__c.CreatedById}"/>
			<apex:outputField value="{!Sharing_ES__c.LastModifiedById}"/>
		</apex:pageBlockSection>
		<apex:pageBlockSection showHeader="true" title="Custom Links" columns="3"> 
     </apex:pageBlockSection>
   </apex:form> 
   </apex:pageBlock>
 </apex:page>

 

 

 

This was selected as the best answer
jon85943jon85943

Thanks so much! it works now

vandana.midha@ivanik.comvandana.midha@ivanik.com

Hello ,

 

am also facing same problem.. will you post code of your controller here. or if u r using extension then post that...... 

actually i need edit button code...... pls reply its really urgent....

 

 

Thanks In Advance.

Saurabh DhobleSaurabh Dhoble

BioScienceMan's solution would work. You can refer to this blog post to get an idea on how to create visualforce pages for custom objects. In particular, there are some issues around how the object images needs to be displayed, any javascript that needs to be implemented etc., those are also addressed in the blog post.