+ Start a Discussion
chinnichinni 

how to select all fields from sobject.

please give me a query for this statement:

 

1)how to retrivew the field in a custom table by using soql query?

BondicloudBondicloud

Hi  ,

  i am giving some of examples bellow , i think thsese are helpfull for u.

SELECT field1, field2, field3

FROM an object

WHERE filter statement(s) and (optionally) order the results

 

 

SELECT ID, Name,customfield__c from Lead WHERE email = 'john.doe@somecompany.com'

SELECT COUNT() from Lead WHERE email = 'john.doe@somecompany.com'

SELECT Id, Name from Lead WHERE email  LIKE '%somecomp%'

SELECT ProductCode FROM PricebookEntry WHERE CurrencyIsoCode = 'USD' or CurrencyIsoCode = 'GBP'

SELECT ProductCode,UnitPrice FROM PricebookEntry WHERE (UnitPrice >= 10 and CurrencyIsoCode='USD') OR (UnitPrice >= 5.47 and CurrencyIsoCode='EUR')






BondicloudBondicloud

I think through soql we cant select  all by using *, we have to select all by separated ,  like

  select name,customfield__c........from demo___c;

skodisanaskodisana

Hi,

 

Using Eclipse IDE and Salesforce schema you can select object that you want to query, it selects all fields automatically.

Copy that query and use it.

 

Thanks,

Srikanth. K

AasifAasif

During runtime if you want to select all fields then  you first need to make a describesobject call. From this retrieve the complete list of fields and then form the query.

After this, pass the query to database.query(queryString) call to run the query.

b-Forceb-Force

To select all fields dynamically from any object you need to use Metadata API

you can use describe metadata API so you can choose all fields from that object.

 

Thanks,

bForce

AmitSahuAmitSahu

This could be helpfull :

 

Map<String, Schema.SObjectField> M = Schema.SObjectType.Expense__c.fields.getMap();
System.Debug('@ > '+ M);
String strQ;
for(String strF:m.Keyset())
{
System.Debug('@@'+strF);

if(strQ == null)
strQ=strF;
else
strQ= strQ + ','+strF;
}
strQ='Select '+strQ+' from Expense__c limit2';
System.Debug('@Query >'+strQ);