Guys I have a requirement to execute a piece of code only once. I created a flow to call a invokable method and called this flow from login flow. This was working fine and the code is being called only once. The issue here is when a newly registered user tries to login into the application, instead of redirecting to the user to the default page(visualforce tab based on user profile) an intermediate page("Your Flow Finished" page of the flow) is being displayed. This happens only during the first time login or if there is any change in the flow. Is there any way to stop or avoid this behavior? Is there any other approach to invoke a class only once.
Use of static variables might be an option to do this. Declare a static variable in a class and set it to false on declaration. Every time you enter the flow check the value of this variable before, enter the flow only if this value is false.
Once your flow begins set this variable to true. So that when the code tries to invoke the class for a second time it detects that the code has already run once and prevents running again. Hope this helps. Thanks
You're looking to set the LoginFlow_FinishLocation variable...
LoginFlow_FinishLocation - String type. Setting this variable will determine where to send the user when the flow completes. [https://developer.salesforce.com/page/Login-Flows]
You need to set it with an Assignment element to make it go - but yeah, thats the way to do it.