You need to sign in to do that
Don't have an account?
Lightning Practice
Update Trigger Conflict
Trigger Test on Account (before insert,before Update,After Update) {
if(trigger.isbefore&& trigger.isInsert ) {
set<Id> acids =new set<Id>();
for(Account ac:trigger.new){
if(ac.ParentId!=null){
acids.add(ac.ParentID);
}
}
system.debug('acids'+acids);
Map<string,string> mpads=new Map<string,string>();
for(Account acc:[select id,Rating,ParentID from account where ID IN: acids]){
system.debug('Rating'+acc.Rating);
mpads.put(acc.ID,acc.Rating);
}
system.debug('mpads'+mpads);
for(Account accc:trigger.new){
if(accc.ParentId!=null){
accc.Rating=mpads.get(accc.ParentID);
system.debug('mpads==>'+mpads.get(accc.parentid));
}
}
}
if(Trigger.isBefore && Trigger.isUpdate){
set<Id> acids =new set<Id>();
for(Account ac:trigger.new){
if(ac.ParentId!=null){
acids.add(ac.ParentID);
}
}
system.debug('acids'+acids);
Map<string,string> mpads=new Map<string,string>();
for(Account acc:[select id,Rating,ParentID from account where ID IN: acids]){
system.debug('Rating'+acc.Rating);
mpads.put(acc.ID,acc.Rating);
}
system.debug('mpads'+mpads);
// Map<Id,Account> olcAcc=trigger.oldMap;
for(Account accc:trigger.new){
Account olcAcc=trigger.oldMap.get(accc.id);
if((accc.Rating!=olcAcc.Rating) && accc.ParentID==olcAcc.ParentID) {
// accc.Rating=mpads.get(accc.ParentID);
system.debug('mpads==>'+mpads.get(accc.parentid));
}else {
accc.Rating=mpads.get(accc.ParentID);
}
}
}
if(trigger.isbefore&& trigger.isInsert ) {
set<Id> acids =new set<Id>();
for(Account ac:trigger.new){
if(ac.ParentId!=null){
acids.add(ac.ParentID);
}
}
system.debug('acids'+acids);
Map<string,string> mpads=new Map<string,string>();
for(Account acc:[select id,Rating,ParentID from account where ID IN: acids]){
system.debug('Rating'+acc.Rating);
mpads.put(acc.ID,acc.Rating);
}
system.debug('mpads'+mpads);
for(Account accc:trigger.new){
if(accc.ParentId!=null){
accc.Rating=mpads.get(accc.ParentID);
system.debug('mpads==>'+mpads.get(accc.parentid));
}
}
}
if(Trigger.isBefore && Trigger.isUpdate){
set<Id> acids =new set<Id>();
for(Account ac:trigger.new){
if(ac.ParentId!=null){
acids.add(ac.ParentID);
}
}
system.debug('acids'+acids);
Map<string,string> mpads=new Map<string,string>();
for(Account acc:[select id,Rating,ParentID from account where ID IN: acids]){
system.debug('Rating'+acc.Rating);
mpads.put(acc.ID,acc.Rating);
}
system.debug('mpads'+mpads);
// Map<Id,Account> olcAcc=trigger.oldMap;
for(Account accc:trigger.new){
Account olcAcc=trigger.oldMap.get(accc.id);
if((accc.Rating!=olcAcc.Rating) && accc.ParentID==olcAcc.ParentID) {
// accc.Rating=mpads.get(accc.ParentID);
system.debug('mpads==>'+mpads.get(accc.parentid));
}else {
accc.Rating=mpads.get(accc.ParentID);
}
}
}
here am having a issue on update trigger.
Example: i have inserted Account1 with choosing parentid lookup whaterver the rating field value existing for parentid need to update on Rating in Newly Created Account1.after i update Account1 with other Parentid lookup then its fine updating Rating Accordingly.looks fine for insert and update and now the issue is when i open any parentAccount and try change the Rating it should update for already lookup exits Accounts.
EG:
ParentAccount ==> Rating --HOT
ParentAccount1 ==> Rating --COLD
Newly created Account
Account1 ==> Rating --Hot -- works Fine
Choosen ParentAccount
now updated
Account1==>Rating --COLD -Works Fine
Choosen ParentAccount1 ==> Rating --COLD
next
Choosen ParentAccount ==>updated with -Warm
Account1 ==> Rating --Warm-- Not Working
please help on it.
Thanks.
Lightning Practice.
THanks ,
Lightning Practice