You need to sign in to do that
Don't have an account?
Amrut
Few apex questions Part - 1
1. Why @future methods has to be static ?
2. Difference between Database.query() and simply querying [query].
3. In batch apex if one record fails for some reason will the entire batch fail ?
4. How to fetch failed update records of a Batch Apex ?
2. Difference between Database.query() and simply querying [query].
3. In batch apex if one record fails for some reason will the entire batch fail ?
4. How to fetch failed update records of a Batch Apex ?
2. From this answer (https://salesforce.stackexchange.com/questions/70157/whats-the-difference-between-database-query-vs-query):
I'm creating a managed package and don't want to take an explicit dependency on a feature. E.g. List<sobject> revenueSchedules = Database.query('Select Id from OpportunityLineItemSchedule where OpportunityLineItemId in :oliIds'); If I did this in static SOQL all the installers of the managed package would need Product Schedules enabled.
I want to dynamically include an optional field or filter in the SOQL query. A custom setting may define the name of a field that should be used to populate something else. As it isn't know at "compile" time it needs to be dynamic.
Otherwise I'd generally use static SOQL to cut down on ceremony code.
As the other answers and comments point out, dynamic SOQL limits your binding options. You can do simple bindings, such as checking if an Id is in a Set. However, you can't do more complex bindings that traverse properties. Instead you will need to convert these to strings. See Salesforce Ideas: Dynamic SOQL binding expression support to match static SOQL
Note that you need to be more careful with dynamic SOQL that you don't open yourself up to SOQL Injection."
4. Inside of your batch class there is a biolderplate method that looks something like this: The second variable (In this example "records") is your list of records.