I am at a loss. I've scoured this forum and others, but haven't figured out why this is happening. I'm re-querying and everything, yet the COUNT rollup is coming out as zero (expected is 1).

Field Name: OppsWithUsers__c enter image description here


Id standardPricebookId = Test.getStandardPricebookId();

Opportunity testOpp1 = TestOpportunityFactory.createOpportunities(1, testAccount.Id)[0];
testOpp1.StageName = 'Prospecting';
testOpp1.Type = 'New';
testOpp1.Pricebook2Id = standardPricebookId;
testOpp1.OwnerId = salesUser.Id;
testOpp1.Contract_Start_Date__c = Date.today().addDays(-1);
testOpp1.Where_Are_Users__c = 'This Account Only';
testOpp1.Contract_Status_for_Rollup__c = 'Active';

insert testObjects2;

testOpp1 = [SELECT Contract_Status_for_Rollup__c, Where_Are_Users__c, AccountId
            FROM Opportunity WHERE Id = :testOpp1.Id];
Account updatedAcct = [SELECT OppsWithUsers__c FROM Account WHERE Id = :testOpp1.AccountId];

System.debug('status for rollup: '+testOpp1.Contract_Status_for_Rollup__c+' // where users: '+testOpp1.Where_Are_Users__c);
System.debug('updated OppsWithUsers: '+updatedAcct.OppsWithUsers__c);

Debug log:

11:38:39.73 (2870681429)|USER_DEBUG|[83]|DEBUG|status for rollup: Active // where users: This Account Only

11:49:18.65 (3188530801)|USER_DEBUG|[85]|DEBUG|updated OppsWithUsers: 0

  • Are you actually setting testOpp1.AccountId? – Adrian Larson Apr 7 '18 at 19:35
  • @AdrianLarson Yes, just didn't paste that part. I also realized I didn't paste the correct debug statement on the second System.debug, which I've since updated. That one would have errored if no Account was returned. – Mike Apr 7 '18 at 19:39
  • I have seen almost similar issues being discussed here or elsewhere, and some mentioned it worked while most of them not able to achieve as you have mentioned here. I wonder if this piece from the documentation has something to do with it - “Calculating roll-up summary field values can take up to 30 minutes...”. – Jayant Das Apr 8 '18 at 5:04
  • What if you surround the insert with startTest() / stopTest() ? – David Cheng Apr 10 '18 at 21:02
  • @DavidCheng Didn't change anything :( – Mike Apr 11 '18 at 18:48

As it turns out, the issue was the API Name of the picklist field value. For some reason, the API Name had underscores. Thus, it wasn't satisfying the Roll-up Summary filter criteria.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.