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

when child's filed updated update the parent's field..Need help
Hi,
I have two object QOD__c--> child object, Approval_Status__c is a field on this object
Project__c--> Parent Object, Project_State__c is a field on this object.
I'm writting a trigger whenevr Approval_Status__c changes and equal to Approved then update the Project__State__c to "Closed"
below is the trigger but m getting error on it...
trigger Populate on Quality_of_Delivery__c (after update) {
List<Project__c> Lstprj=new List<Project__c>(); Set<Id> PrjId =new Set<Id>();
Lstprj=[Select Id from Project__c];
for(Project__c proj : lstprj){
PrjId.add(proj.Id);
}
Map<Id,Project__c> prj = new Map<Id, Project__c>([select Project_State__c,Id from project__c where id in :prjid]);//Getting error here..DML requires SObject or SObject list type: MAP<Id,Project__c> at line 30 column 13
for(Quality_of_Delivery__c q: Trigger.new)
{
if(trigger.oldmap.get(q.Id).Approved_Status__c!=trigger.newmap.get(q.Id).Approved_Status__c)
{
if( trigger.newmap.get(q.Id).Approved_Status__c=='Approved'){
prj.get(q.Project__c).Project_State__c='Closed';
}
}
update prj;
}
}
please look into this
The first part of your trigger seems kind of redundant since you are building a set of all the project ids and then querying all the project records again into a map. You are also attempting to update a record inside a FOR loop, which is a no-no. Try out this bulkified code and see if it works...
Let me know if you have any questions.
All Answers
The first part of your trigger seems kind of redundant since you are building a set of all the project ids and then querying all the project records again into a map. You are also attempting to update a record inside a FOR loop, which is a no-no. Try out this bulkified code and see if it works...
Let me know if you have any questions.
Method does not exist or incorrect signature: trigger.newmap.get(Id) at line 11 column 57
Did you pass just "Id" into the method, or "q.Id" like in my example above? In all reality though you can change trigger.newmap.get(q.Id).Approved_Status__c to just q.Approved_Status__c since it's in the Trigger.new loop.