You need to sign in to do that
Don't have an account?

Preventing the completion of the action in a Before Trigger
Hi all,
I'm in the process of evaluating Apex for the implementation fo some workflow.
I'm fairly new to Salesforce in general and I could'nt find a clear answer to that question yet.
Let's say you have a Before Trigger set to the creation fo some record.
Is it possible in your event handling to prevent the record from being created and send back an error to the user?
I understand it would be possible to do on the UI level, when someone clicks on a button but I would prefer to stay away from UI level customization as much as possible. And the way I understand it, if you place a before trigger on the creation of a record, it is triggered regardless of the way the record gets created (UI, API, ...). That's waht I would need, as opposed to a trigger on a specific UI button.
I'm in the process of evaluating Apex for the implementation fo some workflow.
I'm fairly new to Salesforce in general and I could'nt find a clear answer to that question yet.
Let's say you have a Before Trigger set to the creation fo some record.
Is it possible in your event handling to prevent the record from being created and send back an error to the user?
I understand it would be possible to do on the UI level, when someone clicks on a button but I would prefer to stay away from UI level customization as much as possible. And the way I understand it, if you place a before trigger on the creation of a record, it is triggered regardless of the way the record gets created (UI, API, ...). That's waht I would need, as opposed to a trigger on a specific UI button.
Its help you as per your need.
trigger testTemp on temp__c (before insert) {
if(Trigger.isInsert){
for(temp__c t : Trigger.new){
if(t.Name == 'Temp'){
t.addError('You can\'t add record name as \'Temp\'' );
}
}
}
}
More info and example of trigger validations can be found in the link http://www.cloudforce4u.com/2013/07/salesforce-validation-in-trigger.html