3

I have a before update trigger on Opportunity that uses this query to get values ->

List<Opportunity> opportunities = [SELECT Id, StageName, Probability, Project_Manager__c, Opportunity_Line_of_Business__c, RecordType.Name,(SELECT Id FROM OpportunityContactRoles) FROM Opportunity WHERE Id IN : Trigger.newMap.keySet()];  

The value for Project_Manager__c is returned correctly if the trigger fires from doing an edit on the Opportunity, but when a new product is added to the Opportunity and the trigger fires the Project_Manager__c field is null. All other fields in the query seem to be returned correctly but the Project_Manager__c field. The Project_Manager__c is just a custom field on the Opportunity just like the Opportunity_Line_of_Business__c field is so why would it not be returned in the trigger when a new product is added to the Opportunity?

  • 1
    It shouldn't be. I suspect that your question is related to a NPE (Null Pointer Exception) that happened downstream, and you've incorrectly identified the problem as the field. It could be a missing entry in a map, a number you're trying to do math on, etc. Could you please post the exact line where you are getting the exception? – sfdcfox Jul 26 '13 at 21:21
  • An exception is not returned. In the trigger we are checking to make sure the custom project manager pick list field is populated if the probability of the opportunity is greater than 49 percent and a product description on the opportunity contains criteria. When a product is added to the opportunity and the trigger fires the Project_Manager__c field is always null even if the field is populated. – Hugh Jul 29 '13 at 13:21
  • 1
    We still need more information. The database should be returning a value, especially in a query, even from a related object (e.g. the children records). We're going to need to see more code. The problem is almost certainly elsewhere. – sfdcfox Jul 29 '13 at 13:54
  • 1
    So I presume that for some reason you're observing that your if statement is executing unexpectedly? – sfdcfox Jul 29 '13 at 14:58
  • 1
    The problem is the value return by the statement NewPrjMgr = Trigger.newMap.get(opportunity.Id).Project_Manager__c and tested in the if statement is null when it is really not null in the database. Therefore, the trigger cannot work as expected. – Hugh Jul 29 '13 at 15:56
2

Found the problem. There was an unfinished workflow rule on the Opportunity Product entered by a previous administrator that updated the Opportunity: Project_Manager__c field to nothing. The workflow rule was firing before the trigger when a product was added to the opportunity so it was setting it to null.

| improve this answer | |

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.