+ Start a Discussion
Sainath VenkatSainath Venkat 

class to update parent id in grand child

I am working on one trigger which will populate the Project id in Project Roles.

I have SOW__c object which is having self lookup relationship, Project__c object is having look up to sow object and Project_Role__c object is having look up to sow.

since SOW is having self look up, I will be having parent sow and child sow records, if I create any role to child sow then I want to populate project id that is related to parent sow to the role that is creating to child sow, I tried below a class but somehow it's not working.

Can anyone help me out with this issue, please?
public static void CRroleProjectUpdate(List<Project_Role__c> projectroles){
    set<Id> CRsowId = new set<Id>();
    Map<Id,List<Project__c>> CRProjectMap = new Map<Id,List<Project__c>>();
    for(Project_Role__c proles : projectroles){
        system.debug('CRsowId is ' + CRsowId);
        for(Project__c project:[select Id, SOW__c from Project__c where SOW__c IN: CRsowId]){
            list<Project__c> CRProjectList= CRProjectMap.containsKey(project.Sow__c)?CRProjectMap.get(project.Sow__c):new list<Project__c>();
            CRProjectMap.put(project.SOW__c, CRProjectList);
        for(Project_Role__c proles : projectroles){
                for(Project__c p : CRProjectMap.get(proles.SOW__r.Related_SOW__c)){
                    proles.Project__c = p.Id;

ANUTEJANUTEJ (Salesforce Developers) 
Hi Sainath,

I have found below link that has a similar requirement can you try checking it out:

>> https://developer.salesforce.com/forums/?id=906F0000000BXIFIA4

I hope this helps.

Muhammad Kashif 27Muhammad Kashif 27

I was reading your contents and found a lot of information. Keep posting such contents for us. SEO Dubai (https://www.dubaifirstseo.com/)