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
Prema -Prema - 

soql+= ' select ' + String.join(fields, ','); soql+= ' from Integration_Transaction__c where id=:integrationtransactionid'; Please help why we have concatenated ? Why we haven't written the general soql query when should we go for this?

Best Answer chosen by Prema -
Khan AnasKhan Anas (Salesforce Developers) 
Hi Prema,

Greetings to you!

It is dynamic SOQL. Dynamic SOQL refers to the creation of a SOQL string at runtime with Apex code. Dynamic SOQL enables you to create more flexible applications.

With the help of dynamic apex, you can able to retrieve all the fields and form a dynamic SOQL query and display the field in visualforce and able to export it into CSV or PDF file. In future, if the user adds any new field in the object, you don't have to modify your apex code or visualforce page to display. SObject and field describe will get the fields dynamically from the mentioned object.

Please refer to the below links which might help you further.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_soql.htm

https://webkul.com/blog/execute-a-dynamically-created-query-in-apex/

http://www.sfdcpoint.com/salesforce/dynamic-soql-query-fetch-fields-object-salesforce/

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas