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
lingannalinganna 

select all fieds from account in apex controller class

Hi

 

how to get all fields from account  using query? else is ther another way.

 

thanks

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

Hi,

Try the below code snippet as reference:

----------- vf page-----------

<apex:repeat value="{!acc}" var="a">

 

{!a.name}  <!-- You can add whatever field you needed -->

{!a.phone}

{!a.fax}

</apex:repeat>

 

</apex:page>

 

--------------- apex-------- controller------------------------

public class testimg_cls

{

public string query{get;set;}

public Account acc{get;set;}

public testimg_cls()

{

 

 Map<string,Schema.SObjectField> mpConField=Account.getSObjectType().getDescribe().fields.getMap();

        Set<string> originalvalues = new Set<String>();

        originalvalues = mpConField.keySet();

        query='select ';

        for(string f : originalvalues)

        {

            Schema.DescribeFieldResult fldResult=mpConField.get(f).getDescribe();

           if(query=='select ')

           {

           query=query+string.valueof(fldResult.getName());

           }

           else

           {

           query=query+','+string.valueof(fldResult.getName());

           }

          

        }

         query=query+' from Account limit 1';

         acc=Database.query(query);

  }

}

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

 

All Answers

Navatar_DbSupNavatar_DbSup

Hi,

Try the below code snippet as reference:

----------- vf page-----------

<apex:repeat value="{!acc}" var="a">

 

{!a.name}  <!-- You can add whatever field you needed -->

{!a.phone}

{!a.fax}

</apex:repeat>

 

</apex:page>

 

--------------- apex-------- controller------------------------

public class testimg_cls

{

public string query{get;set;}

public Account acc{get;set;}

public testimg_cls()

{

 

 Map<string,Schema.SObjectField> mpConField=Account.getSObjectType().getDescribe().fields.getMap();

        Set<string> originalvalues = new Set<String>();

        originalvalues = mpConField.keySet();

        query='select ';

        for(string f : originalvalues)

        {

            Schema.DescribeFieldResult fldResult=mpConField.get(f).getDescribe();

           if(query=='select ')

           {

           query=query+string.valueof(fldResult.getName());

           }

           else

           {

           query=query+','+string.valueof(fldResult.getName());

           }

          

        }

         query=query+' from Account limit 1';

         acc=Database.query(query);

  }

}

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

 

This was selected as the best answer
lingannalinganna

happy  great job.

 

thanks.