You need to sign in to do that
Don't have an account?
Kamal Rehmani
Bulk trigger
Hi everyone,
I have just started learning apex, pls help .
I need to write a bulk trigger When Account ‘active’ field is updated, status field should be set to Active for all the contacts related to Account.
I have just started learning apex, pls help .
I need to write a bulk trigger When Account ‘active’ field is updated, status field should be set to Active for all the contacts related to Account.
There two ways for this
1. You can simply create a formula field on contact object refering to Account.
2. If you really want to write trigger then bulk trigger would some thing like below:
Trigger updateContacts on Account ( before Update)
{
List<Contact> ListofCont = new List<Contact>();
for( Account a : [select yourfield, (Select id from contacts ) from Account where id in Trigger.New ])
{
for(contact c : a.contacts )
{
// if your criteria meet then make changes in c and inlcude in ListofCont
}
}
If(ListofCont.size()>0)
update ListofCont ;
}
Thanks
Sandeep Singha;
http://www.codespokes.com/
{
set<Id> accId = new set<Id>();
List<Contact> ListofConts = new List<Contact>();
for(Account acc:Trigger.new){
if(acc.active__c)
accId.add(acc.Id);
}
for( Contact cont : [Select id, status_c from contact where id in:accId ]) {
a.status_c ='Active';
ListofConts.add(cont);
}
If(ListofConts.size()>0)
update ListofConts ;
}
Hope this can help you .