+ Start a Discussion
Koustubh KulkarniKoustubh Kulkarni 

How to stop insertion of record based on a criteria?

Hi i am new to salesforce. i have to implement one functionality in salesforce.I am creating Employee leave system. Scenario is
If u have taken leave on certain date(e.g. 1st may) and it got approved and then again if you try to apply for another leave on the same date(1st may) then your application will not be submitted.How to do that?
please Help.
shashi lad 4shashi lad 4

In the trigger code, you will check whether this date is already submitted, than
you need to pass "Trigger.addError"  which will stop the trigger to fire and stop the insertion. Please read more information about addError and it will be easy to solve. Showing you a path...:)


Amit Chaudhary 8Amit Chaudhary 8
Please try below trigger. I guess that will help u
trigger ContactTrigger on Contact(before insert)
for(Contact cont : trigger.new)
	if(cont.lastName == 'Test')
      cont.addError('Please enter valid LastName');
Please let us know if this will help you

Amit Chaudhary