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
cnaranjocnaranjo 

Update new record from flow designer with trigger

Hello everyone,

 

Well, I have been trying to get my head around this trigger but I haven't been able to get it right, kind of desperate now :( , that is why I'm here. Kind of new to APEX development too, so any help will be much appreciated. 

 

I have a flow that will create a new record using Data Target Elements on a customer object and that is all fine after finishing the flow process. The new record is created without any problems.

Things get bad when I'm trying to do use a trigger that will update some of the fields that are part of that new entry that it has have been created with the flow.

When I compile the trigger it looks fine and there are not errors but when I run the all thing the new records dont get updated on that particular field. (v.Honorarium2__c)

The script:

 

trigger NewIbenExpenses on IBEN_Expenses__c (before insert) {
  List <IBEN_Expenses__c> newExpenses = new List <IBEN_Expenses__c> ();
    
      for(IBEN_Expenses__c o: Trigger.new) {
           
                           
          IBEN_Expenses__c v = new IBEN_Expenses__c (id = o.id);
              if (v.External_Reference_Number_Flow__c =='W045'){
               v.Honorarium2__c = '12.4567.3456.5678'; 
              newExpenses.add(v);

        }
}

    try {
        insert newExpenses; 
    } catch (system.Dmlexception e) {
        system.debug (e);
    }
}

I'm going to keep trying but any directions on how to successfully accomplish this will be a total relief.

 

 

Regards,

cnaranjocnaranjo

Nevermind, I got it ...

 

 

cnaranjocnaranjo

Nevermind ... I got it