• Muhammad Kashif 27
  • NEWBIE
  • -2 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
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){
        CRsowId.add(proles.SOW__r.Related_SOW__c);
        system.debug('CRsowId is ' + CRsowId);
    }
    if(!CRsowId.isEmpty()){
        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>();
            CRProjectList.add(Project);
            CRProjectMap.put(project.SOW__c, CRProjectList);
        }
        for(Project_Role__c proles : projectroles){
            if(CRProjectMap.ContainsKey(proles.SOW__r.Related_SOW__c)){
                for(Project__c p : CRProjectMap.get(proles.SOW__r.Related_SOW__c)){
                    proles.Project__c = p.Id;
                }
            }
        }
    }
}

 
Hello Alll,

I am trying to create a trigger handler class to update records based on the field values from another object record.  But there is no direct relationship between the 2  objects.  Do I have have to create a relationship between them?
  • Object 1 lookup to obejct 3
  • Object 2 lookup to object 1
  • Object 3

I am trying to take the fields from object 3(only 1 record) and match them to the name of the records of object 2.
So field on obect 3 records are called
  • 'big dog - old' 
  • 'big cat - young'
  • small pig - old'
Name of records for obejct 2 are
  • record name is 'big dog' 
  • record name is 'big cat'
  • record name is 'small pig'
How do I do this when there is no direct relationship between the 2 objects.  Object 3 is a lookup on Object 1 and object 2 are children records of object 1? 

Thank you,
P