• Michael Callaghan
  • NEWBIE
  • 10 Points
  • Member since 2015
  • Business Analyst
  • SunTrust

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
I have run into a myriad of issues with process builder and have decided to build a trigger.

LLC_BI__Loan__c is the 'Parent'
LLC_BI__Loan_Collateral2__c is the 'Child'

I wanted to update the Stage_Number__c field on the child record with a number based on the stage of the parent when a stage is changed.  

trigger LoanStageNumberUpdate on LLC_BI__Loan__c (after update) {
 
 for(LLC_BI__Loan__c loan: Trigger.new){
  LLC_BI__Loan__c oldloan = Trigger.oldMap.get(loan.Id);
  if(oldloan.LLC_BI__Stage__c != loan.LLC_BI__Stage__c)
   { 
    List<LLC_BI__Loan_Collateral2__c> collateral = [ SELECT Id, LLC_BI__Loan__c FROM LLC_BI__Loan_Collateral2__c WHERE LLC_BI__Loan__c = :loan.Id];
    List<LLC_BI__Loan_Collateral2__c> newcollateral = new List<LLC_BI__Loan_Collateral2__c>();
 
    for(LLC_BI__Loan_Collateral2__c col: collateral)
    {
        if(loan.LLC_BI__Stage__c == 'Pre-Underwriting'){col.Stage_Number__c = 1;}
            else if(loan.LLC_BI__Stage__c == 'Underwriting'){col.Stage_Number__c = 2;}
              else if(loan.LLC_BI__Stage__c == 'Credit Decision'){col.Stage_Number__c = 3;}   
                  else if(loan.LLC_BI__Stage__c == 'Client Decision'){col.Stage_Number__c = 4;}   
                      else if(loan.LLC_BI__Stage__c == 'Pre-Closing'){col.Stage_Number__c = 5;}   
                          else if(loan.LLC_BI__Stage__c == 'Doc Prep'){col.Stage_Number__c = 6;}  
                              else if(loan.LLC_BI__Stage__c == 'Doc Review'){col.Stage_Number__c = 7;}  
                                  else if(loan.LLC_BI__Stage__c == 'Post-Closing'){col.Stage_Number__c = 8;}   
                                      else if(loan.LLC_BI__Stage__c == 'Funding/Booking'){col.Stage_Number__c = 9;}   
    }
           {
       if (newcollateral.isEmpty() == false){
       update newcollateral;
      }
    }
  }
}
}
I have run into a myriad of issues with process builder and have decided to build a trigger.

LLC_BI__Loan__c is the 'Parent'
LLC_BI__Loan_Collateral2__c is the 'Child'

I wanted to update the Stage_Number__c field on the child record with a number based on the stage of the parent when a stage is changed.  

trigger LoanStageNumberUpdate on LLC_BI__Loan__c (after update) {
 
 for(LLC_BI__Loan__c loan: Trigger.new){
  LLC_BI__Loan__c oldloan = Trigger.oldMap.get(loan.Id);
  if(oldloan.LLC_BI__Stage__c != loan.LLC_BI__Stage__c)
   { 
    List<LLC_BI__Loan_Collateral2__c> collateral = [ SELECT Id, LLC_BI__Loan__c FROM LLC_BI__Loan_Collateral2__c WHERE LLC_BI__Loan__c = :loan.Id];
    List<LLC_BI__Loan_Collateral2__c> newcollateral = new List<LLC_BI__Loan_Collateral2__c>();
 
    for(LLC_BI__Loan_Collateral2__c col: collateral)
    {
        if(loan.LLC_BI__Stage__c == 'Pre-Underwriting'){col.Stage_Number__c = 1;}
            else if(loan.LLC_BI__Stage__c == 'Underwriting'){col.Stage_Number__c = 2;}
              else if(loan.LLC_BI__Stage__c == 'Credit Decision'){col.Stage_Number__c = 3;}   
                  else if(loan.LLC_BI__Stage__c == 'Client Decision'){col.Stage_Number__c = 4;}   
                      else if(loan.LLC_BI__Stage__c == 'Pre-Closing'){col.Stage_Number__c = 5;}   
                          else if(loan.LLC_BI__Stage__c == 'Doc Prep'){col.Stage_Number__c = 6;}  
                              else if(loan.LLC_BI__Stage__c == 'Doc Review'){col.Stage_Number__c = 7;}  
                                  else if(loan.LLC_BI__Stage__c == 'Post-Closing'){col.Stage_Number__c = 8;}   
                                      else if(loan.LLC_BI__Stage__c == 'Funding/Booking'){col.Stage_Number__c = 9;}   
    }
           {
       if (newcollateral.isEmpty() == false){
       update newcollateral;
      }
    }
  }
}
}