+ Start a Discussion
davidesidavidesi 

Get Whole object through its id

I want to get all the fields of an object.

Is there any way to get the whole object? Or I need to write the full query? My object has more than 200 fields (I can write them copying and pasting, but if exists another way ...

 

 

Thanks

 

 

Best Answer chosen by Admin (Salesforce Developers) 
souvik9086souvik9086

There is no select * here. So I'm afraid you have to write all those if you want in static query.
If you are prepared to use dynamic query then, you can fetch all the fields of the particular object by using Sobject methods and perform a string of those and then use them in the dynamic soql query.

 

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

All Answers

Satish_SFDCSatish_SFDC
Do you want to get the data in the fields or a query to get the names of the fields.

In the first case you would have to write the names each of the field. However, please note there is a limit to the number of characters of a query.

If you would like to get the names of the fields in the object you could use Describe calls.

Hope this helps.

Regards,
Satish Kumar
davidesidavidesi
I want to load an entire object.
Something like that:
Opportunity op = (Opportunity) ApexPages.StandardController stdController.getRecord();

Then, is it impossible?

Should I query all the fields which I want to obtain?

Opportunity op = [SELECT ANEG__c, Account_State__c, Activity_Performed_in_Port__c, Administrative_Contact_Email__c, Administrative_Contact_Last_Name__c, Administrative_Contact_Phone__c, Administrative_Contact_First_Name__c, Accesed_Airports__c, Commercial_Adjust__c, Technical_Adjust__c, Ampliaci_n__c, Extension__c, Anulaci_n_por_impago__c, Surname__c, Current_Insurer__c, Assistance__c, FiscalYear, Business_Contact_Email__c, Business_Contact_Last_Name__c, Business_Contact_Phone__c, Account_TIN__c, Existing__c, Campa_a_hasta__c, Campo_usuario_Lanzadera__c, Campo_usuario_URL__c, Channel__c, TotalOpportunityQuantity, Production_N_Amount__c, Portfolio_Amount__c, Principal__c, Maximum_Principal__c, Minium_Principal__c, Position__c, ForecastCategory, ForecastCategoryName, IsClosed, Cif_Cuenta_Padre__c, City__c, Ciudad__c, Codigo_ANEG_Cuenta__c, Codigo_ANEG_Filial__c, [...] FROM Opportunity


Thanks,

David Herrero
This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.
souvik9086souvik9086

There is no select * here. So I'm afraid you have to write all those if you want in static query.
If you are prepared to use dynamic query then, you can fetch all the fields of the particular object by using Sobject methods and perform a string of those and then use them in the dynamic soql query.

 

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

This was selected as the best answer
davidesidavidesi

Thank you for your help

Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

Hi,

 

This can be achieved by creating Fieldsets for that object.

 

You are having 200 fields. So, create a Fieldset for that object and drag the fields you want to query.

Now querying all those 200 fields becomes easier.

 

To create a field set follow the steps below,

  • Goto Setup>Create>Object.
  • Click on your Object name.
  • Goto Fieldset and Click on New.
  • Give name and next Drag Drop the fields you want and save.
  • Save it.

For your reference, please a take a look on the following link,

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_fieldsets_describe.htm

 

Dont forget to give kudos and mark this answer as a solution, if this answer works out..