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
Arshadulla ShariffArshadulla Shariff 

Having Edit and save functionality in same Vf page

Hi there,
I have created Multiple Page Blocks for Edit page which consists of Input Fields of custom Object and few pageblocks for Viewable i.e.,output Field.
Am not sure whethere its a good practice.

Please suggest some standard Edit and view Functionality for custom object Vf page
Best Answer chosen by Arshadulla Shariff
Gaurav KheterpalGaurav Kheterpal
You could use the URL parameters to check if you want to open the page in View mode or Edit mode. Something like this
 
View: /apex/MyPage?id=0067000000AH3ME&sfdc.override=1
Edit: /apex/MyPage?id=0067000000AH3ME&retURL=%2F006%3Ffcf%3D00B70000005pFQv%26rolodexIndex%3D-1%26page%3D1&sfdc.override=1
Then in your controller you can handle the URL params like this
 
public MyExtension(ApexPages.StandardController ctrl){
    Id i = ctrl.getId();
    Map<String,String> parameters = ApexPages.currentPage().parameters();
    if(i == null){
        System.debug('new');
    } else if(parameters.contains('retUrl')){
        System.debug('edit');
    } else {
        System.debug('view');
    }
}
I hope this helps.

If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others and improve the overall quality of Discussion Forums.

Gaurav Kheterpal
Certified Force.com Developer| Salesforce Mobile Evangelist| Developer Forums Moderator| Dreamforce Speaker