+ Start a Discussion
inbox outbox 7inbox outbox 7 

Callout to an external system, response data fails the validation rule, How do I go about saving the record?

Please tell me different approaches of dealing with this issue. 

If the callout is from UI (button) or a flow (external service), the response data is invalid and there is a valdation rule on that field (response data), same transaction and user is expecting to see the result on UI.
I can have custom object which stores the failed data, but how about saving the record in this instance since validation rule doesn't let us?

I am looking for approaches to save the record when we have a validation rule instead of using code.

I can think of two ways to save the record: 
1. In the validation rule: which lets the record to be saved if the field is blank. For example having CONTAINS OR BEGINS functions in the formula. 
2. Instead of a validation rule, no code, we can do the callout from apex and have the validation there, if there is invalid or failed validation, to manipulate the data to allow the record to be saved. 



 
Darshit Pathak 10Darshit Pathak 10

Here I am assuming, the context user would be some API user or Integration user, and not the actual person.

You can by pass the validation rule for that particular user by adding condition of that user's username, profile , name , Id etc. in the validation rule formula.
for example : AND( $User.X18_digit_user_ID__c  != <18_DIGIT_ID_OF_USER> , ISBLANK(field1__c))

this validation rule won't throw an error for this particular user even if field1__c is blank.

If it helps, please mark this as Best Answer!