Inline editing in visualforce page can be done by two ways provided by Salesforce :
1. The <apex:detail> component has an attribute that activates inline editing.
2. The <apex:inlineEditSupport>component provides inline editing functionality to several container components.
Only Visualforce pages version 21.0 and above support inline editing.
1. Inline editing using <apex:detail>:
<apex:page standardController="Account">
<apex:detail subject="{!account.Id}" relatedList="false" inlineEdit="true"/>
</apex:page>
</apex:page>
Move your mouse cursor on the field which you want to edit, you will notice that pencil icon which allows to you edit their content without clicking on Edit button. Non-editable cells display a lock icon. Just double click on the editable field, modify the content of the field and click on Save button which commits your record in the Salesforce database.
Keep in mind while executing above vf page, for this page to display account data, the ID of a valid account record must be added as a query parameter in the URL for the page.
For example: in my case United Oil & Gas, Singapore account have id = 001i000000eJLL4.
So my URL become :
For example: in my case United Oil & Gas, Singapore account have id = 001i000000eJLL4.
So my URL become :
2. Inline editing using <apex:inlineEditSupport>:
You can use <apex:inlineEditSupport> provides inline editing support to <apex:outputField>.
If you want to use <apex:inlineEditSupport> then this component must be in <apex:form> tag.
This support for <apex:dataList>, <apex:dataTable>, <apex:outputField>, <apex:repeat> within <apex:inlineEditSupport> tags.
Below is the example of <apex:inlineEditSupport>
Create Visual force page: Copy below code and save it. Click on preview button and you will be able to test inline editing.
<apex:page standardController="Account" recordSetVar="records" id="thePage">
<apex:form id="theForm">
<apex:pageBlock id="thePageBlock">
<apex:pageBlockTable value="{!records}" var="record" id="thePageBlockTable">
<apex:column >
<apex:outputField value="{!record.Name}" id="AccountNameDOM" />
<apex:facet name="header">Name</apex:facet>
</apex:column>
<apex:column >
<apex:outputField value="{!record.Type}" id="AccountTypeDOM" />
<apex:facet name="header">Type</apex:facet>
</apex:column>
<apex:column >
<apex:outputField value="{!record.Industry}" id="AccountIndustryDOM" />
<apex:facet name="header">Industry</apex:facet>
</apex:column>
<apex:inlineEditSupport event="ondblClick"
showOnEdit="saveButton,cancelButton" hideOnEdit="editButton" />
</apex:pageBlockTable>
<apex:pageBlockButtons >
<apex:commandButton value="Edit" action="{!save}" id="editButton" />
<apex:commandButton value="Save" action="{!save}" id="saveButton" />
<apex:commandButton value="Cancel" action="{!cancel}" id="cancelButton" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
If you want to execute above visualforce page, then you have a to add parameter to the Visualforce page with a valid Account record in the URL.
For example, if 001i000000eJLL4 is the Account ID, the resulting URL should be:
https://Salesforce_instance/apex/myPage?id=001i000000eJLL4
Check out the Visualforce Developer's Guide Quick Start Tutorial of Salesforce for more information.
Below are some cases which does not support the inline editing:
- If you do not have Field level security or FLS on field i.e. you have read only access but inline editing allow you to edit that field. When you try to save that record, salesforce throw an error like Insufficient privilege error message. For ex. Account have field Phone and you have read only access through Field level security. You can edit this field but after clicking on save button Insufficient privilege error message displayed by Salesforce.
- Standard rich text area (RTA) fields are not supported by inline editing feature.
- Some standard objects does not support an inline editing.
- All fields on Task object except subject field does not support inline editing.
- All fields on Event object except subject field and Description field does not support inline editing.
- Inline editing is not supported in Dashboards and Setup pages.
- Do not mix inline edit-enabled fields with regular input fields from the same dependency group. For example, do not mix a standard input field for a controlling field with an inline edit-enabled dependent field.
Enjoy! If you have any questions, comments, please feel free to let me know.
As always, please feel free to get in touch me as I would be more than happy to assist you with any of your Salesforce development needs.Next post: How To Get Total Amount Of Records Processed In Batch Job In 10 Minutes And Still Look Your Best
I have some dynamic fields for a custom object through which i save the data into the model how can i provide inline edit to the fields in vf page which i sue to save the data .....
ReplyDeleteHi Sai,
ReplyDeleteYou can use Second way to fulfill your requirement. (2. Inline editing using :)
Nice information thank you,if you want more information please visit our link salesforce admin certification
ReplyDelete