You need to sign in to do that
Don't have an account?
Deepak Sharma 184
trigger scenario- need Help
have to update the "total actual cost field" in custom object called "project portfolio" from its associated custom object called "projects"'s fiels total actual cost. means all the "total actual cost" fields of different projects associated with the "project portfolio" should come into "total actual cost" field of "project portfolio"
Both have total actual cost field.
Both have total actual cost field.
I am assuming that project portfolio is the parent object of project.
You dont need a trigger. The following solutions can be adopted:
1. If the relationship is master detail, simply create the total-cost field on project portfolio as a rollup field
2. If the relationship is lookup, create a workflow on project object to update total-cost field on project portfolio whenever project record is create or edited
If you need help in creating these, let me know.
Regards
Mann.
Please mark this as the best answer if you feel so!!
"total actual cost" field of project is changable and have a formula in which this field is calculating some costs. hence that is changable. than how to
set the criteria for that.
Regards,
Deepak
Create another rollup field - call it "rollup_total_cost__c".
Then in the "total actual cost" formula field use the "rollup_total_cost__c" field
e.g. "total actual cost" = 2*rollup_total_cost__c
Create roll up field on which object. there is a look up relationship between "Project Portfolio" and "Projects".
when i creating roll up field on "projects". it is asking for summarized objects which is required in which it is showing only "project members" object.
"total actual cost" field of projects there is a formula like-
CloudbyzITPM__Actual_Labor_Cost__c + CloudbyzITPM__Actual_Travel_Cost__c + CloudbyzITPM__Actual_HW_SW_Costs__c
and there is no option of creating roll up summary on "Project Portfolio" object.
Thanks & Regards
Deepak
Try the below trigger for roll up on look up field.(I did this for another req. I changed the object names to yours.I have assumed the child relationship name as pobs__r. Parent Object: project_portfolio__c child object : projects__c, Lookup field name on child : project_portfolio__c )
let me know how it worked out.
Regards
Thanks for help.
what is pobs__r, in this ?
the relationship between them is look up.
like..in "project" there is a look up field for "project portfolio" means i can select "project portfolio" in "project" object.
Api name-
Project- CloudbyzITPM__Project__c
Project Portfolio- CloudbyzITPM__Project_Portfolio__c
Field- CloudbyzITPM__Total_Actual_Cost__c
Regards
below is the screenshots attached.
Child Relationship Name- Projects.
means i have to replace pobs__r with Projects__r
could u resend me the code.
Thanks & Regards,
Deepak
Regards
my code is
trigger UpdateTotalActualCosts on CloudbyzITPM__Project__c (after insert,after update, after delete,after undelete) {
List<id> QuotationsIds = new List<id>();
if(Trigger.isInsert || Trigger.isUndelete || Trigger.isupdate){
For(CloudbyzITPM__Project__c con1 : Trigger.new){
QuotationsIds.add(con1.CloudbyzITPM__Project_Portfolio__c);
}
}
if(Trigger.isDelete){
For(CloudbyzITPM__Project__c con1 : Trigger.old){
QuotationsIds.add(con1.CloudbyzITPM__Project_Portfolio__c);
}
}
List<CloudbyzITPM__Project_Portfolio__c> QuotationsToUpdate = new List<CloudbyzITPM__Project_Portfolio__c>();
decimal sum = 0;
if(Trigger.isInsert || Trigger.isUndelete || Trigger.isupdate){
For(CloudbyzITPM__Project_Portfolio__c q : [select CloudbyzITPM__Total_Actual_Cost__c,(SELECT id,CloudbyzITPM__Total_Actual_Cost__c FROM Projects__r) FROM CloudbyzITPM__Project_Portfolio__c WHERE id =: QuotationsIds]){
sum = 0;
for(CloudbyzITPM__Project__c p : q.Projects__r)
sum = sum + p.CloudbyzITPM__Total_Actual_Cost__c ;
q.CloudbyzITPM__Total_Actual_Cost__c = sum;
QuotationsToUpdate.add(q);
}
try{
update QuotationsToUpdate ;
}Catch(Exception e){
System.debug('Exception :'+e.getMessage());
}
}
}
but now error it is showing is-
Didn't understand relationship 'Projects__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
Also tell me the field names in both parent and child objects.Screenshots would be great
Also try this, while creating your lookup field to the parent object CloudbyzITPM__Project_Portfolio__c give a different child relationship name.Then give that name appended with __r instead of projects__r
field names on both the objects are same-
iam getting error on line no. 31
below is the screenshots attached
look up relationship is already created. can i create another look up relationship in this or can edit the current one.
Thanks
Deepak