You need to sign in to do that
Don't have an account?
Jesus G
Update List of records
Hello,
Please, could you help me to determine which is the issue in this code? I am trying to update a list of records related (through a lookup field) to the object which is being modified.
Thank you very much!
Jesus
Please, could you help me to determine which is the issue in this code? I am trying to update a list of records related (through a lookup field) to the object which is being modified.
public class HandlerResources { public static void handleAfterInsert(List<Resource__c> ResourceList) { List <Project__c> ProjectsToUpdate = new List<Project__c>(); for (Resource__c currentResource : ResourceList) { if (currentResource.Project__c != '') { for (Project__c Project : currentResource.Project__c.Id) { Project.Hours__c = Project.Hours__c + currentResource.Hours__c; ProjectsToUpdate.add(Project); } } } Database.update(ProjectsToUpdate); } }
Thank you very much!
Jesus
My question have been solved in this other post: https://developer.salesforce.com/forums/ForumsMain?id=906F0000000D7ySIAS
Many thanks for your answers,
Jesus
All Answers
what error are you getting?
The error with that code is 'Invalid foreign key relationship: Resource_Estimate__c.copado_Project__c' on the line 6.
If I replace Project__c.Id with Project__r.Id, the error is 'Loop must iterate over a collection type: Id'.
My question would be more about if my approach is right or if other one would be more recommended in this case.
Many thanks,
Jesus
Can you share your requirnmnet ? what exactly you need...I can help you out ? ABove approach is wrong.
Try below code and it will solve nad rllup teh data for you
Try and let me know if it works for you!
Thanks!
Sandeep
The idea would be to update a Project record when its related Resource record is edited, so when we change a number field on the Resource record, another number field on the Project record is updated to add the amount of the first one. I hope this makes sense :)
Thank you!
Jesus
I have provided the code above which you can use. check and let me know if that works for you.
Thanks!
Use below code where I haev updated it to get the data from object first and then update it ...so if already somedata is there then it will add it to...
I am afraid I have not managed to have my class working with the code provided by Sandeep. However, it has given me a good idea about the approach to follow using the Map and Set classes.
Now, I am trying to simplify the scenario in order to understand the last step (adding the value of the child records to the parent).
Please, could you let me know how to complete the code? Thank you very much!
J
My question have been solved in this other post: https://developer.salesforce.com/forums/ForumsMain?id=906F0000000D7ySIAS
Many thanks for your answers,
Jesus