[SalesForce] Populate Lookup field with Process Builder upon record creation

Is it possible to populate a lookup field with Process builder when it is creating a record?

A NPR record must be created by the process builder if the Contract status changes to a certain value.

The process should be like this:

The Contract status changes -> an NPR record is created (the NPR is linked to a Project record). I want to populate the Project Lookup on the NPR with a value coming from Contact-> Opportunity -> Project.

I tried using the record id field, Project Name, a custom text field on the Project that contains the id from the project … but I keep getting an error:

"You encountered some errors when trying to save this record
We can't save this record because the “NPR – create new NPR based on Contract Status” process failed. Give your Salesforce admin these details. This error occurred when the flow tried to create records: FIELD_INTEGRITY_EXCEPTION: Project Name: id value of incorrect type: a0H2a0000042BkgEAE. You can look up ExceptionCode values in the SOAP API Developer Guide. Error ID: 1360218809-19989 (688504257)"

Did I do something wrong?

Best Answer

From the hierarchy mentioned in your question, it seems Process builder alone will not be enough to fetch the Project lookup for you, since you will need to go back to Contact --> Opportunity --> Project to get that which will require querying the data (as mentioned in the comments by @cropredy)

A typical flow (algorithm) would be

  1. trigger the Process Builder upon contact update, as you are already doing, and leave the Project lookup blank.
  2. Add another action flow and create an autolaunch flow
  3. set input variables in the flow, which will be the contact Id coming from Process builder and NPR variable also from Process builder.
  4. Query related records (honestly, I am not able to clearly understand the hierarchy here) and fetch desired `ProjectId'
  5. Set Project lookup with the Id fetched from above step to NPR variable
  6. Update NPR