I have a zoo__c object. On Zoo__c , I have a field called firstName__c. I want to prevent insertion/updating of records if firstName__c has any of these characters at the end - "op" , "gp" , "kp". If any of these characters are at the end of the firstName__c value then ignore them and do not insert. What is the best way to achieve this. I have a lot of zoo__c records in xls sheet which I will be uploading using Dataloader. I do not have option to remove the records that are not needed before inserting them.

What I think:

a. I thought, I can write a Validation rule to prevent the insertion of the record whose name ends with "op" , "gp" , "kp" but I do not see a formula which can check only the last two characters of a text in formula.

b. Should I go with a trigger and check in before insert using string methods. Throw an error if the last two characters match with the text.

Any suggestions on the options for this?

2 Answers 2


You can indeed use validation rule:


A trigger is also possible, but not necessary.

  • Can you please Explain what is 1=Case Aug 30, 2017 at 7:01
  • 1
    @cloudZigZag Case returns a value based on the input (the first parameter). 1= simply means we're comparing the case's return value to the number 1. So if the last two characters is "op", case returns 1, and the formula evaluates to 1=1, which is true (the validation triggers). If the last two characters are "nz", it does not match any value, so case returns the last parameter, and the formula evaluates to 1=0, which is false (the validation does not trigger).
    – sfdcfox
    Aug 30, 2017 at 11:59

@sfdcfox Awesome!! I just tried like this though.

    CONTAINS(LOWER(RIGHT(firstName__c,2)), "op"),
    CONTAINS(LOWER(RIGHT(firstName__c,2)), "gp"),
    CONTAINS(LOWER(RIGHT(firstName__c,2)), "kp")
  • Both means same. the first answer is one liner and has less repetitive texts. That's all.
    – SfdcBat
    Aug 30, 2017 at 1:15

You must log in to answer this question.

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