0

I created a customfield at the standardobject Contact (PID) and I created a new customobject Contract which have also a field with the name PID. The contract should connected to the contact in order to archieve this I compare the PID. A contact can have more than one contract.

If the contact already exist the contact should connect to the contract. If the contact does'nt exist the contact should be created and than connected to the contract.

For this case I created an autolunched flow which runs if a contract is created or updated. I tried often to upload the data to realize what is going wrong.

For example:

  1. I have two contracts which have been updated with the same ID - the flow created two new contacts (WRONG)
  2. I have two contracts one have been updated and one have been created with the same ID - the flow created just one new contract (CORRECT)

it is not easy to explain, if you need further information please just ask.

1
  • It would help if you could provide the flow logic so the community can see what you've done and perhaps help spot where the problem lies. Screen shots may be the best way to provide this.
    – Phil W
    Jan 22 at 21:39
1

Because of how Flows are bulkified, there's no inherent way for various parallel interviews to detect that the same record is already created within the same transaction. You would need an Upsert function, which are not available for Flows at this time. This is a situation that calls for a trigger to deduplicate the record creation beforehand via a Map structure, or a custom InvocableMethod action that can do this part of the Flow (again, using a Map structure).

2
  • Ok, i think the bulkification is my problem. you gave me an example of behing the problem, but how do i do it?
    – peXeq
    Jan 23 at 20:22
  • @peXeq To fix it, use either an Apex action (InvocableMethod), or ditch the idea entirely and go with a normal Apex Trigger instead.
    – sfdcfox
    Jan 23 at 20:37
0

Assuming the PID is a unique ID you are using on the Contact object here is a solution:

  • You said you created an auto-launched flow that triggers when the contract is updated or created. I will assume you created a record-triggered flow, I think that is what you mean.
  • You will need to make sure your record-triggered flow is an after-save flow.
  • Assuming your contract has the PID information, you can get the contact with the same PID value if it exists. If it exists get the ContactID and associate the records.
  • If you cannot find a contact create one and associate the two records.

That should work, please build and test.

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.