Coder Social home page Coder Social logo

layoutdescriberhelper's Introduction

LayoutDescriberHelper

Salesforce.com apex class to describe page layouts.

Install

Deploy to Salesforce Button
Deploy to Salesforce
Manual

Download this repo and use eclipse or jenkins to deploy the src folder's content.

Remote Site Settings entry

After you install, you must make sure the salesforce instance server where you are login is included in the remote site settings.

  1. Go to setup
  2. Then in the left menu, click on "Security Controls" -> "Remote Site Settings" option
  3. If you dont have an entry of your salesforce instance, click "New Remote Site" button
  4. Put a name name to that entry in the "Remote Site Name" field, could be something like "salesforce sandbox" or "salesforce prod"
  5. In the "Remote Site URl" type in the correct url of the salesforce instance you are loggin, mine looks like "https://na17.salesforce.com" without quotes
  6. Finally make sure the "Active" checkbox is checked and save the record.
  7. Navigate to Setup -> Session Settings -> Ensure "Lock sessions to the IP address from which they originated" is turned off.
  8. If 7, was deselected, you will need to log out and log in again for this change to take effect.

Demo

demo

Usage

Just do the following in your visualforce page controller

public class EditAccountController {
//expose public property, this property will be listing each layout section
	public List < LayoutDescriberHelper.LayoutSection > layoutSections {
		get;
		set;
	}
	//...... more members of your controller class.......

public EditAccountController(ApexPages.StandardController controller) {

// Create list of fields to add to controller for object 
            
            
	/* dynamically get all fields for the Account object and add them to the controller */
    List<String> fieldList = new List<String>(Schema.getGlobalDescribe().get('Account').getDescribe().fields.getMap().keyset());		

// Add fields to controller. This is to avoid the SOQL error in visualforce page
controller.addFields(fieldList);

sObject obj = controller.getRecord();

//.... more code to do things



/************************************************************************/
 //getting the default record type
//if we want an specific layout we must provide the appropriate record type id
id theRecordTypeIdToDescribe = LayoutDescriberHelper.getDefaultRecordType(obj);
        
//get the layout section items
layoutSections = LayoutDescriberHelper.describeSectionWithFields(theRecordTypeIdToDescribe, 'Account');

/***************************************************************************/

}

}

Where layoutSections is a public property in your controller and 'Account' is your sobject type. Make sure you select the fields of the object before referencing them otherwise you'll get an annoying sfdc standard error.

See the following visualforce page example which will generate an edit form for the Account object:

<apex:page standardController='Account' extensions="EditAccountController" >
    
    <apex:form>
    <apex:pageblock >
        <apex:pageBlockButtons >
            <apex:commandButton action="{!save}" value="save"/>
            <apex:commandButton action="{!cancel}" value="cancel"/>
        </apex:pageBlockButtons>
         
        <!-- Iterate the layoutSections, which is a list of sections -->
        <apex:repeat value="{!layoutSections}" var="layoutSection">
                <apex:pageBlockSection title="{!layoutSection.Name}" collapsible="{!layoutSection.allowCollapse}" columns="{!layoutSection.columns}">
                    
                    <!--Each section has layoutFields, let's iterate them as well-->
                    <apex:repeat value="{!layoutSection.layoutFields}" var="layoutField">
                        <apex:inputField value="{!Account[layoutField.ApiName]}" rendered="{!not(layoutField.isPlaceHOlder)}" required="{!layoutField.required}"  />
                        <apex:pageblocksectionitem rendered="{!layoutField.isPlaceHolder}" >
                        </apex:pageblocksectionitem>
                    </apex:repeat>
                    
                </apex:pageBlockSection>
            </apex:repeat>  
    </apex:pageblock>
        </apex:form>
</apex:page>

### Override Standard Buttons (optional)

If you want, you can override the standard action/button in salesforce classic mode by going to your object and then go to the "Buttons, Links, and Actions" section, there you edit the edit or new action to replace the standard with your custom visualforce page.

layoutdescriberhelper's People

Contributors

anyei avatar paustint avatar timbarsotti avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.