Skip to main content
pooja biswas a posé une question dans #Apex
Hi

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
4 réponses
  1. 10 mai 2016, 05:25
    Hello Pooja,

    You just need to include columns for custom fields too.

    Like shown in below code :

     

    <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:column value="{!acc.Account_Status__c}"/>

    <apex:column value="{!acc.Active__c}"/>

    </apex:pageBlockTable>

    </apex:pageBlockSection>

    </apex:pageBlock>

    </apex:form>

    </apex:page>

    Hope that helps!

    Mark this as solution if this helps in resolving issue.
0/9000