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
PalakPalak 

Creating the list of fields of contact added to particular layout.

Hi,

 

I have to create the list of custom as well as some standard fields of contact, which are added to a layout.

I also need to discard standard fields such as createdID etc. and formula fields.

Currently I am using describeSobject and able to retreive all the fields on contacts.

 

Please help me, it is urgent.

 

With Regards

Palak Agarwal

Devendra@SFDCDevendra@SFDC

Hi Palak,

 

The below is an example from VF Developer Guide : Chapter "Dynamic Visualforce Bindings"

 

public class DynamicAccountFieldsLister {
public DynamicAccountFieldsLister(ApexPages.StandardController controller) {
      controller.addFields(editableFields);
}
public List<String> editableFields {
get {
if (editableFields == null) {
editableFields = new List<String>();
editableFields.add('Industry');
editableFields.add('AnnualRevenue');
editableFields.add('BillingCity');
}
return editableFields ;
}
private set;
}
}

 

<apex:page standardController="Account"
extensions="DynamicAccountFieldsLister">
<apex:pageMessages /><br/>
<apex:form>
<apex:pageBlock title="Edit Account" mode="edit">
<apex:pageBlockSection columns="1">
<apex:inputField value="{!Account.Name}"/>
<apex:repeat value="{!editableFields}" var="f">
<apex:inputField value="{!Account[f]}"/>
</apex:repeat>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Thanks,

Devendra

 

Navatar_DbSupNavatar_DbSup

Hi,


You can create a list of string (I.e. fields) which will contain only those fields which you want to show on the VFpage. You have to simply make the condition inside the controller.

 

Please go through the link below:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_fields_describe.htm

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

palak agarwalpalak agarwal

Thanks S Jain for your reply. The problem I am facing is I am able to retrieve the list of fields through the link you send but I want the list of those fields which are there in a particular layout not all the fields.

 

I have created a pagelayout for contacts and added few fields on this layout. Now I want the list of only these fields which are present in this layout. Is it possible?

bob_buzzardbob_buzzard

You can't get at that type of information, as Apex doesn't provide access to the metadata API.

 

This sounds like a case for field sets - you'll have to maintain the list of fields in particular page layout in a separate place, but it does allow changes without writing code.

 

Here's a blog post of mine that gives an example of using them:

 

http://bobbuzzard.blogspot.com/2011/02/visualforce-field-sets.html