Interview

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

There are three objects User, Contact, and Account.

and these objects have one


custom field name is isActive.
So, if I will uncheck the IsActive Checkbox from the Account then also uncheck
the isActive checkbox of thethe related user
of that account and all the contact associate with the account

=====================================================
trigger Accounttri9gger on Account (After insert,After update) {
AccountTriggerHandler.makeInactive(trigger.new,trigger.oldMap)
}
===========================================================
public class AccountTriggerHandler{

public static void makeInactive(List <Account> accList){


set <id> accids = new set <id>();
set <id> ownerid = new set <id >();
List <Contact> updateContacts = new list <contact>();
for (Account acc : accList ){
if (acc.isActive == false ){
accids .add(acc.id);
ownerid .add(acc.ownerid);

}
List <Contact > conlist = [select id,Accountid from contact where Accountid IN :
accids];
for (Contact con :conlist){
if (accids .contains(con.Accountid)){
con.IsActive = false ;
updateContacts .add(con);

if (!updateContacts .isEmpty()){
update updateContacts ;

updateUser (ownerid); // calling anothe method


}

@ future
private static void updateUser (List <id> ownerid){
List <user> updateUserList = new list <user> ();
List <user> userList = [select id from user where id IN :ownerid];
for (user u : userList ){
u.isActive = false;
updateUserList .add(u);

}
if (!updateUserList .isEmpty(){
update updateUserList ;

You might also like