You need to sign in to do that
Don't have an account?

Update another object when updating multiple data with ApexDataloader
When I update one record, this trigger works, but when I update multiple records by using Apex Dataloader, it doesn't work.
This trigger updates parent object when its child object's status is updated.
1. Child object Trigger: it just updates parent object.
trigger RFTSetPDStatusFromMS on Ichthys_RFT__c(after insert, after update) { if (Trigger.isInsert||Trigger.isUpdate) { list<Ichthys_RFT__c>msl=[SELECT id,Status__c,RFT_Category__r.Id FROM Ichthys_RFT__c WHERE Id in :Trigger.new]; Ichthys_RFT__c newMs=null; if(msl.size()>0) { newMs=msl[0]; RFT_Category__c[] pdList = [SELECT id, Name, PD_Status__c FROM RFT_Category__c WHERE Id = :newMs.RFT_Category__r.Id]; if(pdList.size()>0) { update pdList[0]; } } } }
2. Parent Object Trigger: it checks child object status and update parent status.
trigger RFTSetPDStatus on RFT_Category__c (before update) { if (Trigger.isUpdate) { List<Ichthys_RFT__c > msList= [SELECT RFT_Category__r.Id,Status__c FROM Ichthys_RFT__c WHERE RFT_Category__r.Id in :Trigger.new]; Integer msExist=0; Integer msCnt=0; if(msList.size()>0){ msExist +=1; } for(RFT_Category__c pd:Trigger.new){ if(msExist==0){ pd.PD_Status__c ='Open'; }else{ for( Ichthys_RFT__c ms :msList){ if( ms.RFT_Category__r.Id == pd.Id && ms.Status__c <>'Completed' && ms.Status__c <>'Not Applicable'){ msCnt +=1; } } if(msCnt==0){ pd.PD_Status__c ='Close'; } else if(msCnt>0){ pd.PD_Status__c ='Open'; } } } } }
Thanks in advance for your help.
Anna
All Answers
replace the above code with
Thank you very much for your help!!
I modified my code, but it seems that pdList can't get any data.
Always pdList.size() is zero.
Is something wrong with this ??
RFT_Category__r.Id should not be null...
can you provide the debug log for this?
Thank you for your help...
There is no debug log created.
This trigger update its parent object, and the parent object also has a trigger to update its status.
I prepared new custom field "RFT_Category_ID__c" which gets ID from another lookup field.
And I modified the code as following, but when I update multiple data, it doesn't work correctly.
Finally it works!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Thank you so much for your very very kind support !!!!!!!!!!!
I can't thank you enough...
Anna