0

I have created an apex class and executed anonymously a code which forces my flow to run every hour, but I am getting this error

If you use a record variable to update or delete records, the ID value in the variable must be populated.

What is the actual issue, I tried using "Scheduled-flow" and also "record-triggered flow" but still the same issue, when I debug the flow from debugger, it works as expected. Only when Apex Job is running I get the error.

.cls

global class ScheduledFlow implements Schedulable {
   global void execute(SchedulableContext sc) {
       Map<String, Id> params = new Map<String, Id> ();
            Flow.Interview kycScoringFlow = Flow.Interview.createInterview('Scheduled_Flow',params );
            kycScoringFlow.start();
   }
}

The code to run it anonymously: (Flow_name is just for reference I am using flow's api name and this would run every hour at 25th minute)

ScheduledFlow sc = new ScheduledFlow();
String cronExp = '0 25 * * * ?';
String JobId = system.schedule('Flow_Name', cronExp, sc);

enter image description here

2 Answers 2

0

You will need to pass the case Object and have it an ID for update scenario before you invoke the flow. Where are you passing it?

You would do something like below

global class ScheduledFlow implements Schedulable {
 global void execute(SchedulableContext sc) {
   Map<String, Object> params = new Map<String, Object> ();
   // May be do an SOQL to get the case record Id
   params.put('Id', '<put case object with recordId here for update>');
        Flow.Interview kycScoringFlow = Flow.Interview.createInterview('Scheduled_Flow',params );
        kycScoringFlow.start();
   }
 }
1
  • I am not familiar with Programming, can you please help me here. I need like this: SELECT Id FROM Case WHERE SlaStartDate != Null AND Status = 'New' OR Status = 'In Progress' And after this how should I invoke this variable in the flow?
    – Dharmin
    Commented Oct 20, 2023 at 14:38
0

Instead of passing the record Id to force edit the Case, I preferred to go with simple solution:

I am sure we could achieve this using Apex but what I did was:

  • A helper checkbox field (Default = False)
  • A record triggered flow on Case where whenever it is created / edited
  • I set it to FALSE
  • Run a scheduled Path - After 1 hour, which sets it to TRUE
  • As soon as it is true, again the same flow runs (as it is edited) and next recur for after 1 hour will be scheduled and it will keep recurring.

Just some heads-up

Maximum 2000 elements limit. According to this limit, in a flow transaction, the total number of flow elements that can be executed is 2000.

250,000 records limit. As per this limit, per 24 hours, the total number of records returned by all the scheduled flows’ Start element query must not be more than 250,000 records or the number of user licenses in your org multiplied by 200, records, whichever is greater.

Here is the official documentation for considerations on scheduled flow

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .