How can I do something similar to id.addError without preventing dml operations?

Long story short, I have a screen flow that updates a Case record and I want to be able to tell users that the information they added to the record was unable to find a match to a Contact record while still adding the information to the record.

For example, the agent types in a customer's phone number; I still want to save that phone number, I just also want to tell the agent in some way that no Contact record was found.

  • 1
    this is already a screen flow? Can you not display a message on a "next" screen after the DML operation to let the user know the information versus doing this in apex? Dec 29 '20 at 20:42
  • Yeah, I'm really unfamiliar with Flows and had been thinking through the process from the wrong angle. This is how I'm going to do it, thanks for putting me on the right path.
    – Zach
    Dec 30 '20 at 18:47

It sounds like a partial success database operation may be what you're looking for. If saving that phone number is part of a DML operation that includes other records that may fail, you can try insert(recordsToInsert, allOrNone) with allOrNone set to False. All the DML operation types support this extra parameter. You can have multiple objects in the DML operation as long as they are not part of the no-mixing list for some setup objects

So in your case, it sounds like we may be updating a Case and a Contact, so we can put these operations in a single database method with allOrNone set to False.

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.