You need to sign in to do that
Don't have an account?

get custom fields
Hi
I am understading the basics of metadata of fetching account info.
below is the code
Pls help me in tweeking my code.
pooja
I am understading the basics of metadata of fetching account info.
below is the code
public class selectAllSOQLExampleController { String SobjectApiName = 'Account'; List<Account> accList=new List<Account>(); public String query{get;set;} public List<Account> getAccList() { Map<String,Schema.SObjectType> schemaMap=Schema.getGlobalDescribe(); Map<String, Schema.SObjectField> fieldMap = schemaMap.get(SobjectApiName).getDescribe().fields.getMap(); String commaSeparatedFields = ''; for(String fieldName : fieldMap.keyset()) { if(commaSeparatedFields == null || commaSeparatedFields == '') { commaSeparatedFields = fieldName; } else { commaSeparatedFields = commaSeparatedFields + ', ' + fieldName; } } query = 'select ' + commaSeparatedFields + ' from ' + SobjectApiName + ' Limit 10 '; accList = Database.query(query); return accList; } } <apex:page controller="selectAllSOQLExampleController"> <apex:form> <apex:pageBlock> <apex:pageBlockSection title="Account table" columns="1" collapsible="false"> <apex:pageBlockTable value="{!accList}" var="acc"> <apex:column value="{!acc.name}"/> <apex:column value="{!acc.phone}"/> <apex:column value="{!acc.rating}"/> <apex:column value="{!acc.industry}"/> <apex:column value="{!acc.accountnumber}"/> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>My requirement is I want to display custom fields also.
Pls help me in tweeking my code.
pooja
You just need to include columns for custom fields too.
Like shown in below code :
Hope that helps!
Mark this as solution if this helps in resolving issue.
All Answers
You just need to include columns for custom fields too.
Like shown in below code :
Hope that helps!
Mark this as solution if this helps in resolving issue.
You did correct in apex controller. You are calling fields custome/standar in your query. But when you are show the records on the Visualforce page, You have added few standard fields in apexpageblocktable as column. Please add custome fields in
eg:
<apex:column value="{!acc.Custome_Fields__c}" />
Hi pooja biswas
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('NumberofLocations__c'); // here you have to specify custome fields
}
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>