Wednesday, November 30, 2011

Dynamic Visualforce Page In Apex Salesforce

Hi Guys ,
We can create Visualforce Pages dynamically . Just need to write the script in Apex Class and avoiding on Visualforce Page.

Here I am just creating a  list of string with the Account Object Fields with their API name and passing this on Visualforce page .

Controller : =======
public class DynamicPage{

    public DynamicPage(ApexPages.StandardController controller) {
  
    }
  
    public Account acc {get;set;}
    public List<String> threeFieldList {
    get {
        if (threeFieldList == null) {
            threeFieldList = new List<String>();
            threeFieldList.add('Industry');
            threeFieldList.add('AnnualRevenue');
            threeFieldList.add('BillingCity')
        }
        return threeFieldList;
        }
        private set;
    }
 }
Page Code : =======
<apex:page standardController="Account" extensions="DynamicPage">

<apex:form >
    <apex:pageBlock title="Binding Input Field Dynamically" mode="edit">
        <apex:pageBlockSection columns="1">
                <apex:inputField value="{!Account.Name}" />
                    <apex:repeat value="{!threeFieldList}" var="afield" >
                        <apex:inputField value="{!acc[afield]}" />
                    </apex:repeat>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>

</apex:page>

So when we need to add another field just need to add that field API Name in threeFieldList which passing in  repeater.

11 comments:

  1. Hello Vijay,

    Thanks for the sharing of code,
    you can use SalesForce Schema to make it more independent and dynamic so by applying that you will not have to add anything in your code after changing the Object Structure. All the work will get done dynamically.

    I have written my blog for the same purpose but as my blog is on initial level, so kindly have a look and give me your valuable feedbacks.
    http://www.amitgoyal09.blogspot.com

    ReplyDelete
  2. Hi Amit ,
    Thanks for sharing your views but I dint understand can you please share the code so that I have better understanding .
    Thanks in advance.

    ReplyDelete
  3. Salesforce Admin Online Training - 21st Century Software ...
    www.21cssindia.com/courses/salesforce-admin-online-training-143.html
    Salesforce admin online training by 21cssindia the largest institute in providing online trainings in all technologies. Salesforce admin training, salesforce ...
    salesforce developer online training| salesforce developer ...
    www.21cssindia.com/.../salesforce-developer-online-training-144.html
    21cssindia provides Salesforce developer online training by real time Experts. Call us +91 9000444287 for online training and demo. Online Salesforce ...
    salesforce crm online training| salesforce crm training| call ...
    www.21cssindia.com/courses/salesforce-crm-online-training-212.html
    21cssindia provides Salesforce crm online training by real time Experts. Call us +91 9000444287 for online training and demo. Online Salesforce crm training ...

    ReplyDelete
  4. Briltus Technologies offer the most effective real time practical oriented Salesforce Training . Our sessions help your group to quickly procure the power they need. Gain from Affirmed specialists as they show building applications regulated and apply what you understand with hands-on activities.
    Visit: http://www.briiltus.com

    ReplyDelete
  5. Learn Salesforce.com developer courses online/classroom in Delhi from top training institutes and get Salesforcedeveloper certification. Get details on course fees @91-931OO96831!!

    ReplyDelete
  6. Thanks for sharing valuable information and it is useful for onlineitguru provides the best salesforce Online course Hyderabad

    ReplyDelete
  7. This is one awesome blog article. Much thanks again salesforce Online Course

    ReplyDelete
  8. Thank you for sharing such great information very useful to us.
    Salesforce Training in Delhi

    ReplyDelete