You need to sign in to do that
Don't have an account?
Galeeb SK
Parent Record Update
Hi ,
iam tried to Update Parent Record Status,My scenario is
when ''all'' the child records status is 'Closed' then its corresponding Parent record status is also 'Closed'.iam trying but fail because iam changing the one child record status is closed its corresponding parent record is also changed this not good,please help me.. My code is
trigger StatusChangePostion on Job_Application__c (after insert,after update) {
list<Position__c> pslist=new list<Position__c>();
list<ID> listids=new list<ID>();
for(Job_Application__c jb:trigger.new){
listids.add(jb.Position__c);
}
pslist=[select id,Name,(select id,Status__c from Job_Applications2__r)from Position__c where id IN:listids];
for(Position__c p:pslist){
Boolean setToApproved=true;
for(Job_Application__c ja:p.Job_Applications2__r){
/*if(ja.Status__c=='Open'){
//p.Status__c='Closed';
setToApproved=false;
break;
}
if(ja.Status__c=='Approved'){
setToApproved=false;
break;
}*/
if(ja.Status__c=='Closed'){
p.Status__c='Closed';
}
}
update pslist;
}
}
Regards
Galeeb SK
iam tried to Update Parent Record Status,My scenario is
when ''all'' the child records status is 'Closed' then its corresponding Parent record status is also 'Closed'.iam trying but fail because iam changing the one child record status is closed its corresponding parent record is also changed this not good,please help me.. My code is
trigger StatusChangePostion on Job_Application__c (after insert,after update) {
list<Position__c> pslist=new list<Position__c>();
list<ID> listids=new list<ID>();
for(Job_Application__c jb:trigger.new){
listids.add(jb.Position__c);
}
pslist=[select id,Name,(select id,Status__c from Job_Applications2__r)from Position__c where id IN:listids];
for(Position__c p:pslist){
Boolean setToApproved=true;
for(Job_Application__c ja:p.Job_Applications2__r){
/*if(ja.Status__c=='Open'){
//p.Status__c='Closed';
setToApproved=false;
break;
}
if(ja.Status__c=='Approved'){
setToApproved=false;
break;
}*/
if(ja.Status__c=='Closed'){
p.Status__c='Closed';
}
}
update pslist;
}
}
Regards
Galeeb SK
Try with belwo code !!
Let me know if it helps!!
Thanks
Manoj
Its working fine ,when we update the all child records status the parent record status is changed to 'Closed'.But if we insert new one child record status is set to 'Closed' after creation of parent record ,status of parent is also changed to 'Closed'.I think we are using 'After insert' event thats why it is changed to 'Closed'.Supose we are using 'After insert ' event the status of parent is not changed to 'Closed' .How? After Update event its working fine.