trigger Accounttrigger on
Account (after update) {
if (Trigger.isAfter &&
Trigger.isUpdate) {
List<Account> accList = new
List<Account>();
List<Contact> conList= new
List<Contact>();
for (Account acc: Trigger.new) {
If(!checkRecursiveApexClass.accIdSet.contains(acc.Id)){
If(Trigger.newmap.get(acc.Id).phone!=Trigger.oldmap.get(acc.Id).phone){
for (Contact con: [SELECT id from
contact where accountid=:acc.id]) {
con.Phone=acc.phone;
conList.add(con);
}
}
checkRecursiveApexClass.accIdSet.add(acc.Id);
}
}
if(conList.size() > 0){
update conList;
}
}
}
public class
checkRecursiveApexClass{
public static set<id> accIdSet=new
set<id>();
}
trigger Accounttrigger on Account (after insert) {
if (Trigger.isAfter && Trigger.isInsert) {
List<Account> accList = new List<Account>();
List<Contact> conList= new List<Contact>();
If(checkRecursiveApexClass.firstRun){
system.debug('Trigger is in if block and record size is'+trigger.new.size());
checkRecursiveApexClass.firstRun=false;
}
Else{
system.debug('Trigger is in else block and record size is'+trigger.new.size());
}
}
}
public class checkRecursiveApexClass{
public static boolean firstRun=true;
}
what would happen the next time trigger is invoked? If the value is already set to false.
ReplyDelete1: When Reset of boolean variable occurs
ReplyDelete2: What if Upsert operation in progress for bunch of data, how boolean variable works?