You need to sign in to do that
Don't have an account?
Nicolai Nonnenbroich
Business Hours Invocable Action
Hi,
This is my first question and I'm completely new to Apex.
I'm essentially trying to write am invocable class that I can use in a flow. It should check now() against the default business hours and return a boolean as an output variable that I can then use in a decision element.
I think I found the piece on writing the query for business hours but I'm not sure how to turn that into an invocable action that I can use in a flow.
Any help would be greatly appreciated!!
The Apex-Code should be like this:
Maybe you should change the name of the class and variable to be meaningful.
In the Flow you add an Apex Action then you select the invocabel method "Get business hours". After that you can use the outputMember in the flow!
Regards,
Omar
All Answers
Please see the example in the refference below, it should guide you to implement you requirements:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableMethod.htm#:~:text=If%20a%20flow%20invokes%20Apex,values%20and%20support%20describe%20calls.
Let me know if anything is not clear to you, and mark as the best answer if this help you!
Regards
Omar
Hi Omar,
Thank you for the link! This is one of the resources I used as well as this one:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_businesshours.htm
// Get the default business hours
BusinessHours bh = [SELECT Id FROM BusinessHours WHERE IsDefault=true];
// Create Datetime on May 28, 2013 at 1:06:08 AM in the local timezone.
Datetime targetTime = Datetime.newInstance(2013, 5, 28, 1, 6, 8);
// Find whether the time is within the default business hours
Boolean isWithin= BusinessHours.isWithin(bh.id, targetTime);
Now it's just about putting the pieces together. Would you happen to have some pointers for working this piece of code into my invocable class?
The Apex-Code should be like this:
Maybe you should change the name of the class and variable to be meaningful.
In the Flow you add an Apex Action then you select the invocabel method "Get business hours". After that you can use the outputMember in the flow!
Regards,
Omar
Sorry, I most likely read this wrong. I was referring to this section:
//Create a Results object to hold the return values Results response = new Results();
//Add the return values to the Results object response.outputMember = isWithin;
yes you are right:
"A list of a primitive data type or a list of lists of a primitive data type – the generic Object type is not supported."
Please refer to the link i sent you before, then go to the section "InvocableMethod Considerations".you will find the types of input and return supported by invocable method!