You need to sign in to do that
Don't have an account?
Praveen raj
triggers on multiple objects
Hi i'm new to salesforce can any one help me. Can we write triggers on multiple objects if yes could you send me some sample code
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
Hi i'm new to salesforce can any one help me. Can we write triggers on multiple objects if yes could you send me some sample code
If your question was that if one trigger would work for multiple objects, the answer is no.
Apex triggers are object specific.
If you meant if you can have DML or code on multiple objects within a same trigger, yes you can do that.
All Answers
Hi,
Yes we can write a trigger on multiple objects. Triggers are written in Apex, and execute before or after an insert, update, delete or undelete event occurs on a sObject. The syntax that introduces a trigger definition will look a little familiar, and begins with the trigger keyword:
trigger myAccountTrigger on Account (before insert, before update)
{
if (Trigger.isInsert)
{
//
}
if (Trigger.isUpdate) {
for(Account a: Trigger.new)
if (a.name == 'bad')
a.name.addError('Bad name'); // prevent update
}
}
This example fires before any Account sObject is inserted or updated. The Trigger.new context variable provides access to the list of accounts being inserted or updated. Update and delete triggers can use Trigger.old to refer to the old versions of the objects being updated or deleted.
Triggers make full use of Apex, allowing you to continue using a familiar language for data manipulation. There are a few restrictions - for example it doesn't make sense to allow call outs to web services from within a trigger as that would unduly lengthen the transaction.
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
If your question was that if one trigger would work for multiple objects, the answer is no.
Apex triggers are object specific.
If you meant if you can have DML or code on multiple objects within a same trigger, yes you can do that.
HI jain i'm sorry i asked for multiple objects you have mention only for single object i.e Account