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
RadmhyaRadmhya 

Add "Edit Layout" functionality to a Visualforce Page

Hello, 

I would like to add the Standard "Edit Layout" functionality that is available on a Salesforce record on a Visualforce page so that the Admin can drag and drop fields on to the Visualforce page instead of adding the new fields in the code. Is this possible? If so, please suggest how to proceed. 

Thanks,
Krish
Himanshu ParasharHimanshu Parashar
Hi Krish,

You can create Edit layout type functionality for your visualforce page. I can't write whole code for you because it is very much time consuming but I can guide you how you can achieve this functionality. You can follow below steps to do that

1. Get all fields using describe methods
SObjectType accountType = Schema.getGlobalDescribe().get('Account'); 
​Map<String,Schema.SObjectField> mfields = accountType.getDescribe().fields.getMap();

2. Use Jquery to create Drag/Drop type region such as (http://jqueryui.com/droppable/#photo-manager) and add all above fields in drag section
3. Capture droppable fields from jquery and save them in any custom object for display on page.
4. While displaying on page you can use following code:

Apex Class
public with sharing class view_controller{
    public list<String> fieldlist{get;private set;}
    public list<Sobject> objSobject{get;private set;}
    public  view_controller()
    {
        fieldlist = new List<String>([select fields__c from Customobject__c where objectname='Account']);
    
        objSobject= database.query('select ' + String.join(fieldlist, ',') + ' from Account limit 1');

    }

}

Apex Page:
 
<apex:page controller="view_controller">
  <apex:pageblock>
    <apex:repeat var="fieldname" value="{!fieldlist}"> 
                <apex:pageBlockTable var="objSobject" value="{!objSobject}">
                       <apex:column headervalue=" Name" >
                          <apex:outputText value="{!objSobject[fieldname]}"/>
                        </apex:column>
                 </apex:pageBlockTable>
       </apex:repeat>
  </apex:pageblock>
  
</apex:page>


Does it makes any sense ?


Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant

P.S. If my answer helps you to solve your problem please mark it as best answer.
 
RadmhyaRadmhya
Thanks, Himanshu! I will go with this approach.
Himanshu ParasharHimanshu Parashar
Hi Krish,

That is great. it will be interesting if we can achieve that functionality. you can put your progress here.



Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant

P.S. If my answer helps you to solve your problem please mark it as best answer so that other can get benefit.