function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

after update trigger help

Hi I have an issue with the after update , I have an application object and recommender object.I have an custom field as recommenders email address in application, once a student enters the email address and trigger should fire and create a corresponding recommender object record , it works fine for the first time.But if I make any changes in the recommender's email address it doesn't change that in the corresponding recommender object record.


Only after insert will not work in my scenario, because an application record it created once an contact record is created .So, i need to update the application record.


The problem is I am checking for if the recommender record is empty or not with recs.size==0, if it is not empty it recognizing it , but not



Trigger Rectrigger on EnrollmentrxRx__Enrollment_Opportunity__c (after insert,after update)
  Set<Id> appids= New Set<Id>();
  for(EnrollmentrxRx__Enrollment_Opportunity__c appli : Trigger.New)
  List<TestErx__Recommender__c> recs=[select TestErx__Application_ID__c from TestErx__Recommender__c where TestErx__Application_ID__c in : appids];
      for (EnrollmentrxRx__Enrollment_Opportunity__c newApplication: Trigger.New)
          if (newApplication.TestErx__Recommender_s_email_address__c != null)
              recs.add(new TestErx__Recommender__c(
              TestErx__Application_ID__c = newApplication.Id,
  upsert recs;


after the first time, there is a TestErx__Recommender__c in the database, which means that recs.size() is not 0 anymore, and your code is not executed. 

You probably need to store the TestErx__Recommender__c records in a map with the TestErx__Application_ID__c as the key. Then when you loop through the trigger.New for the second time, you can check if the map contains a corresponding key/record, and then update it if it exists and create a new one if it does not exist.