I'm not sure disabling validation rule is the only way out for this particular scenario but you guys can chime-in ideas how to approach this particular issue.

I have the following validation rules on my custom__c object

if(Attachment__c == FALSE && URL == null, true, false)

and a Trigger on before insert and after delete on the same custom__c object

  Attachment__c = false;
  update mycustomobject;

when I try to delete the row I'm getting this error:

execution of AfterDelete

caused by: System.DmlException: Update failed. First exception on row 0 with id xxxxx; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Attachment is unchecked and URL is empty: []

I know exactly why I'm getting this error because its firing the validation-rule that i have place in but I'm not sure what is best practice to deal with this type of situation?


  • 1
    It looks like you posted a bunch of questions in regard to the same issue salesforce.stackexchange.com/questions/121087/…
    – o-lexi
    May 9, 2016 at 20:33
  • i have had two question regards to the formula and both are different
    – Nick
    May 9, 2016 at 20:35
  • 2
    they look for me very similar and you are asking here how to bypass the validation. Validation rules are used to prevent any type of changes you don't want to occur, so I belive you'd want to have validation rule adjusted rather than allowing incorrect data
    – o-lexi
    May 9, 2016 at 20:46

1 Answer 1


If your code is the only thing that can set Attachment__c to false, you should be able to change your validation rule in include criteria for


From your last post, it would become

AND(Attachment__c == false,
NOT(BEGINS(URL__c, "https://")),
NOT(BEGINS(URL__c, "http://")))

This would allow your code to set Attachment to false but would not let anyone else edit the record after until the URL field met your requirements.

Otherwise this blog walks through a more generic way for solving this problem: http://bobbuzzard.blogspot.com/2011/11/bypass-validation-rules-from-apex.html

  • Thanks for the link and its dated back to 2011 and I guess nothing much improved since then... I will go first with your approach because its very simple and only minor change but I could not able to work and my validation rules is like this if(Attachment__c == FALSE && URL == null, true, false) and try to add ISCHANGED but does not work.
    – Nick
    May 9, 2016 at 22:41
  • AND(Attachment__c == false, NOT(ISCHANGED(Attachment__c)), ISBLANK(URL__c)) try that
    – Jimmy Jay
    May 10, 2016 at 14:39

You must log in to answer this question.

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