Process Builder issue

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.

Answer

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

Attribution
Source : Link , Question Author : sfdc rowdy , Answer Author : Daniel Howell

Leave a Comment