You need to sign in to do that
Don't have an account?

Batch Apex not passing custom formula field value on Campaign Member?
I am experiancing something very strange. I created a batch apex class, part of the query returns a custom field (Nurturing_Grade_Points__c , Formula Number field ) and the sobjects in the execute method all have that custom field set to 0.00. Even though I know for a fact none of them are equal to zero.
My query is:
Select c.Nurturing_Grade_Points__c, c.Id From CampaignMember c Where c.HasResponded = True and c.Nurturing_Grade_Points__c > 0 and c.FirstRespondedDate > 2008/1/1 and ContactID != NULL Order By c.ContactId
Using system.debug in the execute method i am printing out each CampaignMember. All of them have have Nurturing_Grade_Points__c equal to 0.00. Example:
CampaignMember:{Nurturing_Grade_Points__c=0.00, Id=XXXXXXX}
If I go look at that capaign member I can clearly see that the Nurturing_Grade_Points__c field is set to a number higher than zero. Something seems to be happening between the query and execute methods where my custom field is getting set to zero. This is driving me batty anyone have any ideas why this is happening? Can you not use custom formula fields in batch apex?
When is the class fired? Is it in a before update trigger? The only thing that comes to mind is that HasResponded is set to true between the before and after trigger.
If you're using an after update trigger or firing from some other method, this isn't the problem.
I haven't dealt w/ querying formula fields before so I'm not much help otherwise.
Hi Cmarz_1,
We have had the same problem. We have contacted Salesforce support and they have confirmed this is a known issue. The problem seems to be with nested formula fields. If the field Nurturing_Grade_Points__c references other fields or other formula fields you will need to include those in your select statement. If you do you should then see the correct values in Nurturing_Grade_Points__c.
HTH
Paul
This is standard database functionality. I would fully expect any database to not ever return values for fields I did not specifically request. The prior posters are correct; you do need to query the value to obtain a meaningful number. The same is true for Oracle, MySQL, PostgreSQL, and any other database system you'll find out there. I am actually more surprised that you did not get a "field was used without being requested" error, which would definitely be a bug.Edit: Scratch that. I obviously can not read clearly at this hour in the morning. However, it would be wise to keep that in mind. I've been working with Salesforce in some capacity for years, and I know that Salesforce never offers information you don't ask for (I've often referred to it as a "lazy" database, although most databases act in the same manner). Whenever you run into this type of issue, you should always make sure you're querying all the data you need, and never assume that Salesforce will grab a piece of related data that you didn't request.
You can use custom object in Apex batch. Try to hard code the query in your class. I was facing the same issue and SalesForce suggest this solution for time being.