• Jesse Lee
  • NEWBIE
  • 10 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

I have a custom object called "Application" and I'm trying to use a trigger to update a field on the Application record with a Case record Id when a case is created. More context....

There is an Application Number automatically created and added to a field on the Application object called "Application Number" (Application.Application_Number__c). The Case object also has a custom field called "Application Number" (Case.Application_Number__c). 

When a new Application record is created, Process Builder is invoked to create a new Case record. Process Builder takes the Application Number from my App object record and inserts it into the corresponding field on the Case record its creating. That's currently the only linked factor. 

Here's what I'm trying to accomplish with this trigger and need help with: 
I want this trigger to fire when the Case record is created, query my Application object records and look for the record with the matching Application Number (remember this is a stored value on both objects). Once it finds the record with the matching Application Number, I want to update the "Case_Id__c" field on my Application record with the actual Case record that was just created. This is so that I can relate them.

Example:
1)    Object: Application__c
          - Field: Application_Number__c
          - Field: Case_Id__c
2)  Object: Case
          - Field: Application_Number__c

I need a SOQL query to find the match via the application number, then simply update the field with the case Id.

My problem is right now I can't get this trigger to update the field and insert the Case Id. What am I doing wrong? I'm sure this is going to be a facepalm moment for me. Any help is appreciated!
 
trigger CaseRelateToApp on Case (after insert) // trigger when a new Case is created
{
    for (Case c : Trigger.new) 
    {
        String applicationNumber = c.Application_Number__c; //field on the Case holding the Application #
        String caseRecordId = c.Id;  // Case SFDC record Id

        List<Application__c> appRecord = [SELECT Id,Case_Id__c,Application_Number__c FROM Application__c WHERE Application_Number__c = :applicationNumber];  //query the Application object records and look for the matching Application Number that's stored on both object records in the field called "Application_Number__c"
       
        for(Application__c d: appRecord)
    	{
            d.Case_Id__c = caseRecordId;  //update the Case Id field on the Application object with the actual Case record Id that caused this trigger to execute.
        }
    }
}

 

I have a custom object called "Application" and I'm trying to use a trigger to update a field on the Application record with a Case record Id when a case is created. More context....

There is an Application Number automatically created and added to a field on the Application object called "Application Number" (Application.Application_Number__c). The Case object also has a custom field called "Application Number" (Case.Application_Number__c). 

When a new Application record is created, Process Builder is invoked to create a new Case record. Process Builder takes the Application Number from my App object record and inserts it into the corresponding field on the Case record its creating. That's currently the only linked factor. 

Here's what I'm trying to accomplish with this trigger and need help with: 
I want this trigger to fire when the Case record is created, query my Application object records and look for the record with the matching Application Number (remember this is a stored value on both objects). Once it finds the record with the matching Application Number, I want to update the "Case_Id__c" field on my Application record with the actual Case record that was just created. This is so that I can relate them.

Example:
1)    Object: Application__c
          - Field: Application_Number__c
          - Field: Case_Id__c
2)  Object: Case
          - Field: Application_Number__c

I need a SOQL query to find the match via the application number, then simply update the field with the case Id.

My problem is right now I can't get this trigger to update the field and insert the Case Id. What am I doing wrong? I'm sure this is going to be a facepalm moment for me. Any help is appreciated!
 
trigger CaseRelateToApp on Case (after insert) // trigger when a new Case is created
{
    for (Case c : Trigger.new) 
    {
        String applicationNumber = c.Application_Number__c; //field on the Case holding the Application #
        String caseRecordId = c.Id;  // Case SFDC record Id

        List<Application__c> appRecord = [SELECT Id,Case_Id__c,Application_Number__c FROM Application__c WHERE Application_Number__c = :applicationNumber];  //query the Application object records and look for the matching Application Number that's stored on both object records in the field called "Application_Number__c"
       
        for(Application__c d: appRecord)
    	{
            d.Case_Id__c = caseRecordId;  //update the Case Id field on the Application object with the actual Case record Id that caused this trigger to execute.
        }
    }
}