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
louisa barrett 7louisa barrett 7 

flow from VF page being called twice

I have a VF page which uses a lightning component to call a flow(checks and decisions are made in the flow to determine if the asset should be deleted) to delete an asset. Depending on whether the user is in Classic or a console view the behaviour should be different. I use an identical page to delete a case rather than an asset and it works perfectly.
However when the asset is deleted. the flow appears to be called again. I'm getting the following error via email
Flow Details
Flow API Name: Delete_Asset
Type: Screen Flow
Version: 1
Status: Active
Org: CRB Cunninghams (00Db0000000eIN5)
Flow Interview Details
Interview Label: Delete Asset 18/03/2019 10:27
Current User: Louisa Barrett (005b0000003IbLU)
Start time: 18/03/2019 10:27
Duration: 0 seconds
How the Interview Started
Louisa Barrett (005b0000003IbLU) started the flow interview.
Some of this flow's variables were set when the interview started.
AssetID = 02i0J00000XVygLQAT
FAST LOOKUP: GetAsset
Find all Asset records where:
Id Equals {!AssetID} (02i0J00000XVygLQAT)
Assign those records to {!Asset}.
Save these field values in the variable: Id, Name, Added_to_Service_Contract__c, Service_Contract__c, Service_Contract_Status__c, Service_Contract_Start_Date__c, Service_Contract_End_Date__c, AccountId
Result
Failed to find records.
________________________________________
Salesforce Error ID: 624516304-414064 (-1789764336)

This is my VF page that calls the flow
<apex:page standardController="Asset" lightningStylesheets="true" >
<!-- Orignal method to call flow -->
<!--<flow:interview name="Delete_Asset"

finishLocation="/{!Asset.AccountID}">

<apex:param name="AssetID" value="{!Asset.Id}"/>

</flow:interview>-->
    
  <apex:includeScript value="/support/console/40.0/integration.js"/>
    <html>
        <head>
            <apex:includeLightning />
        </head>
        <body class="slds-scope">
            <div id="flowContainer" />
            <script type="text/javascript">
            var returnID = "{!Asset.Account.Id}";
            var statusChange = function (event) 
            {
                console.log('Status change = ' + event.getParam("status"));
                if(event.getParam("status") === "FINISHED") 
                {
                    // Use my return Id to open a tab
                    if (sforce.console.isInConsole())
                    {
                        sforce.console.getEnclosingTabId(closeSubtab);
                        sforce.console.getFocusedPrimaryTabId(refreshPrimaryTab);
                    }
                    else
                    { 
                        window.parent.location = '/' + returnID; 
                    }
                }
            };
            $Lightning.use
            ("c:TestLightningApp2", function()
             {
                 // Create the flow component 
                 console.log('function called');
                 $Lightning.createComponent("lightning:flow", 
                                            {"onstatuschange":statusChange},
                                            "flowContainer",
                                            function (component) 
                                            {
                                                // Set my input variables
                                                var inputVariables =
                                                    [
                                                        {
                                                            name : 'AssetID',
                                                            type : 'String',
                                                            value : '{!Asset.Id}'
                                                        }
                                                    ];
                                                // Start the flow and pass in the input variables
                                                component.startFlow("Delete_Asset", inputVariables);
                                            }
                                           );
             }
            );                       
            var closeSubtab = function closeSubtab(result)
            {
                var tabId = result.id;
                sforce.console.closeTab(tabId);
            }
            var refreshPrimaryTab = function getTabId(result)
            {
                var tabId = result.id;
                sforce.console.refreshPrimaryTabById(tabId, true);
            }
            </script>
        </body>
    </html>
</apex:page>

If I use the original method to call the flow(commented text at the top of the page' it works fine.

Any help would be much appreciated