1

I have a before insert flow which is not working correctly. The flow works as follows:

The flow should prevent the creation of a record from custom object AreaInteres__c if there is already a record created with the same values for two fields (Interes__c and Lead__c). This way a Lead shouldn't have a duplicate interest. I am going to attach a screenshot of the test that I prepared.

enter image description here

I also tried setting another condition in the decision element, the id of the record you obtained is not the same as $Record.Id, but as you can see in the interview the record has no Id. I guess the record returned is the one you are trying to create, as I have made the same query via inspector and no records are returned.

Thanks for your help.

1
  • I recently worked on a similar requirement and was able to make it work in an after save flow. Try making it after save and using the condition 'id of the record you obtained is not the same as $Record.Id'. Let me know if this works? Commented May 7 at 3:12

1 Answer 1

0

Your assumption is right with regards to the "Get Element". It retrieves the record that you are about to create. The problem with a before save flow is that a recordId hasn't been assigned to the record that will be created, so you cannot exclude it from the "Get Element".

You can change your approach in determining if there are duplicate records. I used the Lead Object for demonstration purposes:

  1. Get all Lead records with the same values for LastName and LeadSource
  2. Count the total records retrieved
  3. Use a decision element to check if the count is greater than 1
  4. Show error message if count is greater than 1

I checked the logic and it seems to work as expected:

enter image description here

Or when you have a unique Lead being created, then the flow lets the creation of the record continue:

enter image description here

Good luck!

2
  • Hi! Thanks for your solution, it nearly worked. I have created a test and it works correctly, if there is a second record created the decision elements is routed to the error. However, when testing in the real environment, it is returning an error when you try to create a third record, not a second. Commented May 7 at 7:31
  • I changed the condition to greater or equal to 1 and now it works as expected, if you try to create a second record with the same values it returns the error message. It's a bit counter intuitive but is finally it wortks. Thanks for your help, if you have an explanation for this behaviour that would be great. I am checking this answer as useful. Commented May 7 at 7:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .