• Tim Andrews
  • NEWBIE
  • 40 Points
  • Member since 2014
  • Salesforce Administrator
  • Texas Commission on State Emergency Communications

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 21
    Replies
I have a custom object called Public_Information_Request__c that is exposed in my Community site (Napili template) via a VF page, called PIARequest. I am new to VF, so what I need help with is this: Once the user submits (saves) the Public Information Request record, instead of the record detail page becoming visible, I want to redirect the user to another VF page, called PublicInformationRequestSuccessful. This page displays the success message, as well as output fields with the Name, Requestor First Name, Requestor Last Name and Subject of Request data.

Below are my VF pages and the controller that is supposed to trigger the display of the success page:

PIARequest VF Page:
 
<apex:page standardController="Public_Information_Request__c" showheader="false" sidebar="false">
    <apex:pageMessages />
    <apex:form >
        
        <apex:pageBlock title="New Public Information Request">
            
            <apex:pageBlockSection columns="1">
    			<apex:inputField value="{!Public_Information_Request__c.Name}"/>
        		<apex:inputField value="{!Public_Information_Request__c.Date_Request_Submitted__c}"/>
        		<apex:inputField value="{!Public_Information_Request__c.Requestor_First_Name__c}"/>
        		<apex:inputField value="{!Public_Information_Request__c.Requestor_Last_Name__c}"/>
        		<apex:inputField value="{!Public_Information_Request__c.Requestor_Email__c}"/>
        		<apex:inputField value="{!Public_Information_Request__c.Requestor_Phone__c}"/>
        		<apex:inputField value="{!Public_Information_Request__c.Subject_of_Request__c}"/>      		
            </apex:pageBlockSection>
            
            <apex:pageBlockButtons >
                <apex:commandButton value="Submit Request" action="{!save}" />
            </apex:pageBlockButtons>
        
        </apex:pageBlock>
        
    </apex:form>
</apex:page>

Controller:
 
public with sharing class MyPageController {

    Public_Information_Request__c request;
        
        private ApexPages.StandardController controller;
   		 public MyPageController(ApexPages.StandardController controller) {
            this.controller = controller;
        
    }
    
    public PageReference saveAndSuccess() {
        if(controller.save() !=null) {
        PageReference successPage = Page.PublicInformationRequestSuccessful;
        successPage.setRedirect(true);
        successPage.getParameters().put('id',controller.getId());
        return successPage;
        } return null; 
	}
}

PublicInformationRequestSuccessful VF Page:
 
<apex:page standardController="Public_Information_Request__c" showheader="false" sidebar="false" extensions="PublicInformationRequest"> 
  <apex:sectionHeader title="Public Information Request Request Received" subtitle="Thank You"/>

  <apex:form >
    <apex:pageBlock title="Public Information Request Details">

      <apex:pageBlockSection columns="1">
        <apex:outputField value="{!Public_Information_Request__c.name}"/>
        <apex:outputField value="{!Public_Information_Request__c.Requestor_First_Name__c}"/>
        <apex:outputField value="{!Public_Information_Request__c.Requestor_Last_Name__c}"/>
        <apex:outputField value="{!Public_Information_Request__c.Subject_of_Request__c}"/>    
        </apex:pageBlockSection>
        
        <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!save}" id="saveButton" />
        </apex:pageBlockButtons>

    </apex:pageBlock>
  </apex:form>
</apex:page>

I would sure appreciate any help that I can get to make this work!
Thank you!

 
Goal: Populate the fields Parent_Project__c and Child Project__c on the custom object Work_Products__c after a new Work_Products__c record is created. 

Background:
A Process Builder process creates a new Project__c record, with a record type of “Parent Project” when a TaskRay__Project__c parent project record is inserted.

Then,

A Process Builder process creates a new Project__c record, with a record type of “Child Project” when a TaskRay__Project__c child project record is inserted.

Then,

A Process Builder process creates a new Work_Products__c record, with a record type of “Deliverable” when a TaskRay__Project_Task__c project task record is inserted. This is where I run into trouble.
  • The Process Builder process is able to create the new Work_Products__c project deliverable record and populate all fields except for the Child_Project__c and Parent_Project__c fields, because the Child_Project__c and Parent_Project__c fields do not look-up to TaskRay__Project_Task__c.
  • There are lookup fields on Work_Products__c called Get_Child_Project__c and Get_Parent_Project__c, which look-up to TaskRay__Project_Task__c and link these fields with the associated TaskRay__Project__c (child project level) and TaskRay__Project_Parent__c records via traversing relationships through TaskRay__Project_Task__c up to TaskRay__Project__c and then up to TaskRay_-project_Parent__c.
  • As mentioned above, there are lookup fields on Work_Products__c called Child_Project__c and Parent_Project__c; these lookups look back up to the Project__c object, filtered for the “Child Project” and “Parent Project” record types.
    • These lookups capture the associated Child Project and Parent Project records on Project__c.
    • They look back up to Project__c because of roll-up relationships that are required for reporting.
I need a trigger that populates the Child_Project__c and Parent_Project__c lookup fields on Work_Products__c with the Child Project and Parent Project record-type records on Project__c that share their names with the associated Get_Child_Project__c and Get_Parent_Project__c record names.

Schema showing the Work_Products__c, Project__c,  TaskRay__Project_Task__c and TaskRay__Project__c objects and their relationships are attached; my attempt at the required code is below.
Schema
trigger UpdateProjects on Work_Products__c (before insert) {
    Map<String, RecordType> rtMap = new Map<String, RecordType>();

    // Build a map of record type name to record types
    for (RecordType rt : [
        select Name
        from RecordType
        where Name = 'Deliverable' or
            Name = 'Expense'
  ]) {
        rtMap.put(rt.Name, rt);
    } 

    Set<Id> parentProjectIds = new Set<Id>();
 
    // Iterate over all the work products
    for (Work_Products__c theProduct : Trigger.New) {
        // If we are dealing with a "deliverable" then put it's taskray parent Id in the set
        if (theProduct.RecordTypeId == rtMap.get('Deliverable').Id) {
            parentProjectIds.add(theProduct.Get_Parent_Project__c);  
        }
    }

    // Remove any null ids
    parentProjectIds.remove(null);
    
    Set<Id> childProjectIds = new Set<Id>();
 
    // Iterate over all the work products again
    for (Work_Products__c theProduct1 : Trigger.New) {
        // If we are dealing with a "deliverable" then put it's taskray child Id in the set
        if (theProduct1.RecordTypeId == rtMap.get('Deliverable').Id) {
            childProjectIds.add(theProduct1.Get_Child_Project__c);  
        }
    }

    // Remove any null ids
    childProjectIds.remove(null);
    
    // If we have taskray parent projects, deal with them
    if (!parentProjectIds.isEmpty()) {
        Map<Id, String> taskrayParentMap = new Map<Id, String>();
        
        // Get all the taskray parent projects we need to deal with and map their Ids to their names
        for (Taskray__Project__c trpp : [
            select Name
            from Taskray__Project__c
            where Id in :parentProjectIds
        ]) {
            taskrayParentMap.put(trpp.Id, trpp.Name);
        }
        
          // If we have taskray child projects, deal with them
    if (!childProjectIds.isEmpty()) {
        Map<Id, String> taskrayChildMap = new Map<Id, String>();
        
        // Get all the taskray child projects we need to deal with and map their Ids to their names
        for (Taskray__Project__c trpc : [
            select Name
            from Taskray__Project__c
            where Id in :childProjectIds
        ]) {
            taskrayChildMap.put(trpc.Id, trpc.Name);
        }  

        Map <String, Work_Products__c> workProductMap = new Map <String, Work_Products__c>();
        // Build a map of work product parent project names to projects for any work products that match our taskray project name and are "deliverables".
        for (Work_Products__c WorkProducts : [
            select Get_Parent_Project__r.Name
            from Work_Products__c
            where Name in :taskrayParentMap.values() and
                RecordTypeId = :rtMap.get('Deliverable').Id
        ]) {
            workProductMap.put(workProducts.Name, workProducts);
        } 
        
        Map <String, Work_Products__c> workProductMap1 = new Map <String, Work_Products__c>();
        // Build a map of work product child project names to projects for any work products that match our taskray project name and are "deliverables".
        for (Work_Products__c WorkProducts1 : [
            select Get_Child_Project__r.Name
            from Work_Products__c
            where Name in :taskraychildMap.values() and
                RecordTypeId = :rtMap.get('Deliverable').Id
        ]) {
            workProductMap1.put(workProducts1.Name, workProducts1);
        } 

        // Iterate through all the work products and do the mapping
        for (Work_Products__c theProducts : trigger.New) {
            // Bail out if we're not dealing with a "deliverable"
            if (theProducts.RecordTypeId != rtMap.get('Deliverable').Id) {
                continue;
            }

            // Bail out if we can't find the task ray parent project for that id
            if (!taskrayParentMap.containsKey(theProducts.Get_Parent_Project__c)) {
                continue;
            }
            
            // Bail out if we can't find the task ray child projects for that id
            if (!taskrayChildMap.containsKey(theProducts.Get_Child_Project__c)) {
                continue;
            }

            // Bail out if we cant find a parent project for the task ray project name
            if (!workProductMap.containsKey(taskrayParentMap.get(theProducts.Get_Parent_Project__c))) {
                continue;
            }
            
            // Bail out if we cant find a child project for the task ray project name
            if (!workProductMap1.containsKey(taskrayChildMap.get(theProducts.Get_Child_Project__c))) {
                continue;
            }

            // Set the parent project lookup
            theProducts.Parent_Projects__c = workProductMap.get(taskrayParentMap.get(theProducts.Get_Parent_Project__c)).Id;

	        // Set the child project lookup
	        theProducts.Child_Project__c = workProductMap1.get(taskrayChildMap.get(theProducts.Get_Child_Project__c)).Id;
         }
      }
   }
}

Any help would be greatly appreciated!
With much help from @pcon, I've now got a pretty sweet trigger that I need for my org. I know that a best practice is to work with classes vs. triggers, so I've attempted to convert my trigger to a class. Can anyone help to verify that I've done this correctly and also perhaps provide some guidance on writing a test class for it?
 
public class UpdateParentUtility {
    
    Public static void updateParentProject(List<project__c> listProjects) {
        
    Map<String, RecordType> rtMap = new Map<String, RecordType>();

    // Build a map of record type name to record types
    for (RecordType rt : [
        select Name
        from RecordType
        where Name = 'Parent Project' or
            Name = 'Child Project'
  ]) {
        rtMap.put(rt.Name, rt);
    } 

    Set<Id> taskrayParentIds = new Set<Id>();
 
    // Iterate over all the projects
    for (Project__c theProject : listProjects) {
        // If we are dealing with a "child project" then put it's taskray parent Id in the set
        if (theProject.RecordTypeId == rtMap.get('Child Project').Id) {
            taskrayParentIds.add(theProject.Get_Parent_Project__c);  
        }
    }

    // Remove any null ids
    taskrayParentIds.remove(null);
    
    // If we have taskray parents, deal with them
    if (!taskrayParentIds.isEmpty()) {
        Map<Id, String> taskrayMap = new Map<Id, String>();
        
        // Get all the taskray projects we need to deal with and map their Id to their name
        for (Taskray__Project__c trp : [
            select Name
            from Taskray__Project__c
            where Id in :taskrayParentIds
        ]) {
            taskrayMap.put(trp.Id, trp.Name);
        } 

        Map <String, Project__c> parentProjectMap = new Map <String, Project__c>();
        // Build a map of project names to projects for any projects that match our taskray name and are "parent projects"
        for (Project__c parentProject : [
            select Name
            from Project__c
            where Name in :taskrayMap.values() and
                RecordTypeId = :rtMap.get('Parent Project').Id
        ]) {
            parentProjectMap.put(parentProject.Name, parentProject);
        } 

        // Iterate through all the projects and do the mapping
        for (Project__c theProject : listProjects) {
            // Bail out if we're not dealing with a "child project"
            if (theProject.RecordTypeId != rtMap.get('Child Project').Id) {
                continue;
            }

            // Bail out if we can't find the task ray project for that id
            if (!taskrayMap.containsKey(theProject.Get_Parent_Project__c)) {
                continue;
            }

            // Bail out if we cant find a parent project for the task ray project name
            if (!parentProjectMap.containsKey(taskrayMap.get(theProject.Get_Parent_Project__c))) {
                continue;
            }

             // Set the parent project lookup
            theProject.Parent_Project__c = parentProjectMap.get(taskrayMap.get(theProject.Get_Parent_Project__c)).Id;
        }
    }
}

}

 
Goal: Populate the field Parent_Project__c on the custom object Project__c after a new Project__c record is created. 

Background:A Process Builder process creates a new Project__c record, with a record type of “Parent Project” when a TaskRay__Project__c parent project record is inserted.

Then,

A Process Builder process creates a new Project__c record, with a record type of “Child Project” when a TaskRay__Project__c child project record is inserted.
  • The Process Builder process is able to create the new Project__c child project record and populate all fields except for the Parent_Project__c field, because the Parent_Project__c field does not look-up to TaskRay__Project__c.
  • There is a lookup field on Project__c called Get_Parent_Project__c, which looks-up to TaskRay__Project__c and links it with the associated TaskRay__Project_Parent__c record.
  • As mentioned above, there is a second lookup field on Project__c called Parent_Project__c; this lookup looks back up to the Project__c object, filtered for the “Parent Project” record type.
    • This lookup captures the associated Parent Project record on Project__c.
    • It looks back up to Project__c because of a roll-up relationship that is required for reporting.
I need a trigger that populates the Parent_Project__c lookup field on Project__c with the Parent Project record-type record on Project__c that shares its name with the associated Get_Parent_Project__c record name.

Schema showing the Project__c and TaskRay__Project__c objects and their relationships are attached.

Schema
Hello all,

I am new to writing Apex triggers and am hung up on some practice I am working on. In my dev org, I have created two custom objects (Alpha__c and Beta__c). I am attempting to write a trigger that populates a lookup field on Beta__c called Beta_Apex_Test_Field_1__c with the data from the Alpha__c object field called Alpha_Test_Field_1__c. The update should trigger when the Alpha__c object record is updated to populate this field.

I've attempted to use code modified from other examples, but I'm getting stuck and the trigger doesn't fire or throw any exceptions. Below is the code I've written. Can someone help a struggling newbie developer?

// Attempting to update a lookup field on the Beta__c custom object called Beta_Apex_Test_Field_1__c with the value that is input into the Alpha__c custom 
// object field called Alpha_Test_Field_1__c. 

trigger SyncAlphaToBeta on Alpha__c (after update) {
    
    Set<String> fieldupdates = new Set<String>();
    for(Alpha__c a : Trigger.new) {
        if(a.Alpha_Test_Field_1__c != null) fieldupdates.add(a.Alpha_Test_Field_1__c);
    }
    
    Map<String, Beta__c> betas = new Map<String, Beta__c>();
    for(Beta__c b : [SELECT Id, Name, Beta_Apex_Test_Field_1__c FROM Beta__c WHERE Name IN :fieldupdates]) {
        betas.put(b.Name, b);
        
    }
              
    for(Alpha__c a : Trigger.new) {
        if(a.Alpha_Test_Field_1__c != null) {
            if(betas.containsKey(a.Alpha_Test_Field_1__c)) {
                a.Alpha_Test_Field_1__c = betas.get(a.Alpha_Test_Field_1__c).Id;
            }
        }
    }
}
Hello all, I am new to Apex and am trying to do a simple field update between two custom objects; I looked through other posts and tried to model mine on the others I saw, but I'm getting stuck. In a nutshell, when a date is entered into the Date_Received__c field on the Invoices__c object, that date should be written to the Invoice_Received_Date__c field on the Work_Products__c object. Work_Products__c is linked to Invoices__c via a lookup relationship. Below is the code I have written:

trigger DateReceivedUpdate on Invoices__c (before insert, before update){
   
  List<ID> WorkProductIds = New List<ID>();
   
  for(Invoices__c a : Trigger.new){
   if(a.Date_Received__c != null){
     WorkProductIds.add(a.Work_Product_Name__c);
   }
  }         
  List<Invoices__c> WorkProductsList = [SELECT id, Date_Received__c FROM Invoices__c WHERE id in :WorkProductIds];
   
    Map<id,Invoices__c> mInvtoWP = New Map<id,Invoices__c>();
   
    for(Work_Products__c p : trigger.new)
     mInvtoWP.put(p.Invoice_Received_Date__c, p);
   
    for(integer i = 0 ; i < WorkProductList.size(); i++){
      WorkProductsList[i].Work_Products__c = mInvtoWP.get(WorkProductsList[i].ID).Invoices__c;
    }
        
    update WorkProductsList;
}

Any help that I can get would be greatly appreciated.
Thanks!
I have a custom object called Public_Information_Request__c that is exposed in my Community site (Napili template) via a VF page, called PIARequest. I am new to VF, so what I need help with is this: Once the user submits (saves) the Public Information Request record, instead of the record detail page becoming visible, I want to redirect the user to another VF page, called PublicInformationRequestSuccessful. This page displays the success message, as well as output fields with the Name, Requestor First Name, Requestor Last Name and Subject of Request data.

Below are my VF pages and the controller that is supposed to trigger the display of the success page:

PIARequest VF Page:
 
<apex:page standardController="Public_Information_Request__c" showheader="false" sidebar="false">
    <apex:pageMessages />
    <apex:form >
        
        <apex:pageBlock title="New Public Information Request">
            
            <apex:pageBlockSection columns="1">
    			<apex:inputField value="{!Public_Information_Request__c.Name}"/>
        		<apex:inputField value="{!Public_Information_Request__c.Date_Request_Submitted__c}"/>
        		<apex:inputField value="{!Public_Information_Request__c.Requestor_First_Name__c}"/>
        		<apex:inputField value="{!Public_Information_Request__c.Requestor_Last_Name__c}"/>
        		<apex:inputField value="{!Public_Information_Request__c.Requestor_Email__c}"/>
        		<apex:inputField value="{!Public_Information_Request__c.Requestor_Phone__c}"/>
        		<apex:inputField value="{!Public_Information_Request__c.Subject_of_Request__c}"/>      		
            </apex:pageBlockSection>
            
            <apex:pageBlockButtons >
                <apex:commandButton value="Submit Request" action="{!save}" />
            </apex:pageBlockButtons>
        
        </apex:pageBlock>
        
    </apex:form>
</apex:page>

Controller:
 
public with sharing class MyPageController {

    Public_Information_Request__c request;
        
        private ApexPages.StandardController controller;
   		 public MyPageController(ApexPages.StandardController controller) {
            this.controller = controller;
        
    }
    
    public PageReference saveAndSuccess() {
        if(controller.save() !=null) {
        PageReference successPage = Page.PublicInformationRequestSuccessful;
        successPage.setRedirect(true);
        successPage.getParameters().put('id',controller.getId());
        return successPage;
        } return null; 
	}
}

PublicInformationRequestSuccessful VF Page:
 
<apex:page standardController="Public_Information_Request__c" showheader="false" sidebar="false" extensions="PublicInformationRequest"> 
  <apex:sectionHeader title="Public Information Request Request Received" subtitle="Thank You"/>

  <apex:form >
    <apex:pageBlock title="Public Information Request Details">

      <apex:pageBlockSection columns="1">
        <apex:outputField value="{!Public_Information_Request__c.name}"/>
        <apex:outputField value="{!Public_Information_Request__c.Requestor_First_Name__c}"/>
        <apex:outputField value="{!Public_Information_Request__c.Requestor_Last_Name__c}"/>
        <apex:outputField value="{!Public_Information_Request__c.Subject_of_Request__c}"/>    
        </apex:pageBlockSection>
        
        <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!save}" id="saveButton" />
        </apex:pageBlockButtons>

    </apex:pageBlock>
  </apex:form>
</apex:page>

I would sure appreciate any help that I can get to make this work!
Thank you!

 
Goal: Populate the fields Parent_Project__c and Child Project__c on the custom object Work_Products__c after a new Work_Products__c record is created. 

Background:
A Process Builder process creates a new Project__c record, with a record type of “Parent Project” when a TaskRay__Project__c parent project record is inserted.

Then,

A Process Builder process creates a new Project__c record, with a record type of “Child Project” when a TaskRay__Project__c child project record is inserted.

Then,

A Process Builder process creates a new Work_Products__c record, with a record type of “Deliverable” when a TaskRay__Project_Task__c project task record is inserted. This is where I run into trouble.
  • The Process Builder process is able to create the new Work_Products__c project deliverable record and populate all fields except for the Child_Project__c and Parent_Project__c fields, because the Child_Project__c and Parent_Project__c fields do not look-up to TaskRay__Project_Task__c.
  • There are lookup fields on Work_Products__c called Get_Child_Project__c and Get_Parent_Project__c, which look-up to TaskRay__Project_Task__c and link these fields with the associated TaskRay__Project__c (child project level) and TaskRay__Project_Parent__c records via traversing relationships through TaskRay__Project_Task__c up to TaskRay__Project__c and then up to TaskRay_-project_Parent__c.
  • As mentioned above, there are lookup fields on Work_Products__c called Child_Project__c and Parent_Project__c; these lookups look back up to the Project__c object, filtered for the “Child Project” and “Parent Project” record types.
    • These lookups capture the associated Child Project and Parent Project records on Project__c.
    • They look back up to Project__c because of roll-up relationships that are required for reporting.
I need a trigger that populates the Child_Project__c and Parent_Project__c lookup fields on Work_Products__c with the Child Project and Parent Project record-type records on Project__c that share their names with the associated Get_Child_Project__c and Get_Parent_Project__c record names.

Schema showing the Work_Products__c, Project__c,  TaskRay__Project_Task__c and TaskRay__Project__c objects and their relationships are attached; my attempt at the required code is below.
Schema
trigger UpdateProjects on Work_Products__c (before insert) {
    Map<String, RecordType> rtMap = new Map<String, RecordType>();

    // Build a map of record type name to record types
    for (RecordType rt : [
        select Name
        from RecordType
        where Name = 'Deliverable' or
            Name = 'Expense'
  ]) {
        rtMap.put(rt.Name, rt);
    } 

    Set<Id> parentProjectIds = new Set<Id>();
 
    // Iterate over all the work products
    for (Work_Products__c theProduct : Trigger.New) {
        // If we are dealing with a "deliverable" then put it's taskray parent Id in the set
        if (theProduct.RecordTypeId == rtMap.get('Deliverable').Id) {
            parentProjectIds.add(theProduct.Get_Parent_Project__c);  
        }
    }

    // Remove any null ids
    parentProjectIds.remove(null);
    
    Set<Id> childProjectIds = new Set<Id>();
 
    // Iterate over all the work products again
    for (Work_Products__c theProduct1 : Trigger.New) {
        // If we are dealing with a "deliverable" then put it's taskray child Id in the set
        if (theProduct1.RecordTypeId == rtMap.get('Deliverable').Id) {
            childProjectIds.add(theProduct1.Get_Child_Project__c);  
        }
    }

    // Remove any null ids
    childProjectIds.remove(null);
    
    // If we have taskray parent projects, deal with them
    if (!parentProjectIds.isEmpty()) {
        Map<Id, String> taskrayParentMap = new Map<Id, String>();
        
        // Get all the taskray parent projects we need to deal with and map their Ids to their names
        for (Taskray__Project__c trpp : [
            select Name
            from Taskray__Project__c
            where Id in :parentProjectIds
        ]) {
            taskrayParentMap.put(trpp.Id, trpp.Name);
        }
        
          // If we have taskray child projects, deal with them
    if (!childProjectIds.isEmpty()) {
        Map<Id, String> taskrayChildMap = new Map<Id, String>();
        
        // Get all the taskray child projects we need to deal with and map their Ids to their names
        for (Taskray__Project__c trpc : [
            select Name
            from Taskray__Project__c
            where Id in :childProjectIds
        ]) {
            taskrayChildMap.put(trpc.Id, trpc.Name);
        }  

        Map <String, Work_Products__c> workProductMap = new Map <String, Work_Products__c>();
        // Build a map of work product parent project names to projects for any work products that match our taskray project name and are "deliverables".
        for (Work_Products__c WorkProducts : [
            select Get_Parent_Project__r.Name
            from Work_Products__c
            where Name in :taskrayParentMap.values() and
                RecordTypeId = :rtMap.get('Deliverable').Id
        ]) {
            workProductMap.put(workProducts.Name, workProducts);
        } 
        
        Map <String, Work_Products__c> workProductMap1 = new Map <String, Work_Products__c>();
        // Build a map of work product child project names to projects for any work products that match our taskray project name and are "deliverables".
        for (Work_Products__c WorkProducts1 : [
            select Get_Child_Project__r.Name
            from Work_Products__c
            where Name in :taskraychildMap.values() and
                RecordTypeId = :rtMap.get('Deliverable').Id
        ]) {
            workProductMap1.put(workProducts1.Name, workProducts1);
        } 

        // Iterate through all the work products and do the mapping
        for (Work_Products__c theProducts : trigger.New) {
            // Bail out if we're not dealing with a "deliverable"
            if (theProducts.RecordTypeId != rtMap.get('Deliverable').Id) {
                continue;
            }

            // Bail out if we can't find the task ray parent project for that id
            if (!taskrayParentMap.containsKey(theProducts.Get_Parent_Project__c)) {
                continue;
            }
            
            // Bail out if we can't find the task ray child projects for that id
            if (!taskrayChildMap.containsKey(theProducts.Get_Child_Project__c)) {
                continue;
            }

            // Bail out if we cant find a parent project for the task ray project name
            if (!workProductMap.containsKey(taskrayParentMap.get(theProducts.Get_Parent_Project__c))) {
                continue;
            }
            
            // Bail out if we cant find a child project for the task ray project name
            if (!workProductMap1.containsKey(taskrayChildMap.get(theProducts.Get_Child_Project__c))) {
                continue;
            }

            // Set the parent project lookup
            theProducts.Parent_Projects__c = workProductMap.get(taskrayParentMap.get(theProducts.Get_Parent_Project__c)).Id;

	        // Set the child project lookup
	        theProducts.Child_Project__c = workProductMap1.get(taskrayChildMap.get(theProducts.Get_Child_Project__c)).Id;
         }
      }
   }
}

Any help would be greatly appreciated!
With much help from @pcon, I've now got a pretty sweet trigger that I need for my org. I know that a best practice is to work with classes vs. triggers, so I've attempted to convert my trigger to a class. Can anyone help to verify that I've done this correctly and also perhaps provide some guidance on writing a test class for it?
 
public class UpdateParentUtility {
    
    Public static void updateParentProject(List<project__c> listProjects) {
        
    Map<String, RecordType> rtMap = new Map<String, RecordType>();

    // Build a map of record type name to record types
    for (RecordType rt : [
        select Name
        from RecordType
        where Name = 'Parent Project' or
            Name = 'Child Project'
  ]) {
        rtMap.put(rt.Name, rt);
    } 

    Set<Id> taskrayParentIds = new Set<Id>();
 
    // Iterate over all the projects
    for (Project__c theProject : listProjects) {
        // If we are dealing with a "child project" then put it's taskray parent Id in the set
        if (theProject.RecordTypeId == rtMap.get('Child Project').Id) {
            taskrayParentIds.add(theProject.Get_Parent_Project__c);  
        }
    }

    // Remove any null ids
    taskrayParentIds.remove(null);
    
    // If we have taskray parents, deal with them
    if (!taskrayParentIds.isEmpty()) {
        Map<Id, String> taskrayMap = new Map<Id, String>();
        
        // Get all the taskray projects we need to deal with and map their Id to their name
        for (Taskray__Project__c trp : [
            select Name
            from Taskray__Project__c
            where Id in :taskrayParentIds
        ]) {
            taskrayMap.put(trp.Id, trp.Name);
        } 

        Map <String, Project__c> parentProjectMap = new Map <String, Project__c>();
        // Build a map of project names to projects for any projects that match our taskray name and are "parent projects"
        for (Project__c parentProject : [
            select Name
            from Project__c
            where Name in :taskrayMap.values() and
                RecordTypeId = :rtMap.get('Parent Project').Id
        ]) {
            parentProjectMap.put(parentProject.Name, parentProject);
        } 

        // Iterate through all the projects and do the mapping
        for (Project__c theProject : listProjects) {
            // Bail out if we're not dealing with a "child project"
            if (theProject.RecordTypeId != rtMap.get('Child Project').Id) {
                continue;
            }

            // Bail out if we can't find the task ray project for that id
            if (!taskrayMap.containsKey(theProject.Get_Parent_Project__c)) {
                continue;
            }

            // Bail out if we cant find a parent project for the task ray project name
            if (!parentProjectMap.containsKey(taskrayMap.get(theProject.Get_Parent_Project__c))) {
                continue;
            }

             // Set the parent project lookup
            theProject.Parent_Project__c = parentProjectMap.get(taskrayMap.get(theProject.Get_Parent_Project__c)).Id;
        }
    }
}

}

 
Goal: Populate the field Parent_Project__c on the custom object Project__c after a new Project__c record is created. 

Background:A Process Builder process creates a new Project__c record, with a record type of “Parent Project” when a TaskRay__Project__c parent project record is inserted.

Then,

A Process Builder process creates a new Project__c record, with a record type of “Child Project” when a TaskRay__Project__c child project record is inserted.
  • The Process Builder process is able to create the new Project__c child project record and populate all fields except for the Parent_Project__c field, because the Parent_Project__c field does not look-up to TaskRay__Project__c.
  • There is a lookup field on Project__c called Get_Parent_Project__c, which looks-up to TaskRay__Project__c and links it with the associated TaskRay__Project_Parent__c record.
  • As mentioned above, there is a second lookup field on Project__c called Parent_Project__c; this lookup looks back up to the Project__c object, filtered for the “Parent Project” record type.
    • This lookup captures the associated Parent Project record on Project__c.
    • It looks back up to Project__c because of a roll-up relationship that is required for reporting.
I need a trigger that populates the Parent_Project__c lookup field on Project__c with the Parent Project record-type record on Project__c that shares its name with the associated Get_Parent_Project__c record name.

Schema showing the Project__c and TaskRay__Project__c objects and their relationships are attached.

Schema
Hello all,

I am new to writing Apex triggers and am hung up on some practice I am working on. In my dev org, I have created two custom objects (Alpha__c and Beta__c). I am attempting to write a trigger that populates a lookup field on Beta__c called Beta_Apex_Test_Field_1__c with the data from the Alpha__c object field called Alpha_Test_Field_1__c. The update should trigger when the Alpha__c object record is updated to populate this field.

I've attempted to use code modified from other examples, but I'm getting stuck and the trigger doesn't fire or throw any exceptions. Below is the code I've written. Can someone help a struggling newbie developer?

// Attempting to update a lookup field on the Beta__c custom object called Beta_Apex_Test_Field_1__c with the value that is input into the Alpha__c custom 
// object field called Alpha_Test_Field_1__c. 

trigger SyncAlphaToBeta on Alpha__c (after update) {
    
    Set<String> fieldupdates = new Set<String>();
    for(Alpha__c a : Trigger.new) {
        if(a.Alpha_Test_Field_1__c != null) fieldupdates.add(a.Alpha_Test_Field_1__c);
    }
    
    Map<String, Beta__c> betas = new Map<String, Beta__c>();
    for(Beta__c b : [SELECT Id, Name, Beta_Apex_Test_Field_1__c FROM Beta__c WHERE Name IN :fieldupdates]) {
        betas.put(b.Name, b);
        
    }
              
    for(Alpha__c a : Trigger.new) {
        if(a.Alpha_Test_Field_1__c != null) {
            if(betas.containsKey(a.Alpha_Test_Field_1__c)) {
                a.Alpha_Test_Field_1__c = betas.get(a.Alpha_Test_Field_1__c).Id;
            }
        }
    }
}