I have created one process builder to check the criteria for Opportunity creation if Owner.UserRole.DeveloperName is something then PricebookID need to be updated. Hence it is working fine when created Opportunity from Opportunity tab.

But When I created one Button on a custom object (Target) 'convert to opportunity' VF page attach to it having action="{!doConvert} and in controller I am creating the opportunity.

//Opportunity Creation
newOpp = new Opportunity();

newOpp.OwnerId = target.OwnerID;
newOpp.Name = target.Name;
newOpp.Accountid = target.Target_Account__c;
newOpp.Amount = target.Target_Potential_Opportunity_Amount__c;
newOpp.CloseDate = date.today()+90;
newOpp.CampaignID = target.Target_Campaign__c;
newOpp.Opportunity_Target__c = target.Id;
newOpp.StageName = '1 - Prospecting';

insert newOpp;

return returnToOpportunity();

But when I click on this button, it shows blank screen and debug log shows error:

The flow failed to access the value for myVariable_current.Owner.UserRole.DeveloperName because it hasn't been set or assigned.

  • Does the user you are clicking the button using have a Role assigned to them? – Alex Tennant Feb 2 '16 at 15:59
  • Yes he has, it is working fine with the same user while creating opportunity from Opportunity object. – sfdc rowdy Feb 2 '16 at 16:06
  • Do a system debug and print both newOpp.OwnerId and target.OwnerID before inserting the opp in your code just to rule out errors on that side of things. Also just to check : this is a process builder and not a flow you are launching ? – user28379 Feb 2 '16 at 16:34
  • Yes I am using Process builder only not the visualflow... let me check with the system debug – sfdc rowdy Feb 2 '16 at 16:37
  • I have checked OwnerID before inserting opp and it is having correct values. Moreover my question is why we need to declare this variable in the code, when it is fetching the value through process builder. – sfdc rowdy Feb 2 '16 at 17:31

Process builder has a few flaws when referencing fields in criteria. It is is appalling at handling lookup fields that are null.

A simple way around it is to create a formula field on the opportunity that looks up the role name. Formulas don't mind if they resolve to null.

Then use that formula in the process builder criteria.

It's a bit of a painful extra step, but it will stop flow errors. I don't think flow errors are ok from a user's perspective, so worth it

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.