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
cmarz_1cmarz_1 

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 This formula references multiple objects) 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?

jkucerajkucera

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.

cmarz_1cmarz_1
Right now I'm just testing the batch class by executing it anonymously through the system log
PaulATPimptastiPaulATPimptasti

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 

sfdcfoxsfdcfox

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.

Message Edited by sfdcfox on 11-10-2009 03:14 AM
NaishadhNaishadh

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.

 

Message Edited by Naishadh on 11-10-2009 02:12 AM
cmarz_1cmarz_1
I did in fact report this to Salesforce and yesterday they confirmed it as an issue.  Although the fix they suggested (which is the same as they one you have) does not work in my case.  I included the field that Nurturing_Grade_Points__c in calculated from and it still did not fix the issue.  A Senior Developer Support Engineer at Salesforce was able to replicate the problem and has escalate the issue to Tier 3 support.  I'll be sure to update this issue with any of their findings.