toddhalfpenny / sfflowvisualiser-vscode

Salesforce Flow to PlantUML VS Code extension
ISC License
29 stars 5 forks source link

TypeError: Cannot read properties of undefined (reading 'targetReference') #4

Closed BrettMN closed 9 months ago

BrettMN commented 10 months ago

I have a simple flow that looks like this:

Test Flow

It gives the following error in the Extension Host after selecting the file in the Explorer and running Flow Visualizer: Mermaid from the command palette.

2023-11-09 09:27:10.901 [error] TypeError: Cannot read properties of undefined (reading 'targetReference')
    at /Users/BrettN/.vscode/extensions/toddhalfpenny.sfflowvisualiser-0.1.1/out/main.js:21:89
    at new Promise (<anonymous>)
    at qt (/Users/BrettN/.vscode/extensions/toddhalfpenny.sfflowvisualiser-0.1.1/out/main.js:17:54)
    at /Users/BrettN/.vscode/extensions/toddhalfpenny.sfflowvisualiser-0.1.1/out/main.js:15:11

I have attached the flow xml.

toddhalfpenny commented 10 months ago

Thanks @BrettMN . I cannot see the flow XML, maybe I'm missing something. Could you please paste it here?

jefersonchaves commented 9 months ago

Hello @toddhalfpenny - I have seen a similar error in Auto-launched Flows with Scheduled Paths (many thanks for this work):

<?xml version="1.0" encoding="UTF-8"?>
<Flow xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>58.0</apiVersion>
    <environments>Default</environments>
    <interviewLabel>Sample Flow Scheduled Path {!$Flow.CurrentDateTime}</interviewLabel>
    <label>Sample Flow Scheduled Path</label>
    <processMetadataValues>
        <name>BuilderType</name>
        <value>
            <stringValue>LightningFlowBuilder</stringValue>
        </value>
    </processMetadataValues>
    <processMetadataValues>
        <name>CanvasMode</name>
        <value>
            <stringValue>FREE_FORM_CANVAS</stringValue>
        </value>
    </processMetadataValues>
    <processMetadataValues>
        <name>OriginBuilderType</name>
        <value>
            <stringValue>LightningFlowBuilder</stringValue>
        </value>
    </processMetadataValues>
    <processType>AutoLaunchedFlow</processType>
    <recordLookups>
        <name>Get_Account</name>
        <label>Get Account</label>
        <locationX>964</locationX>
        <locationY>324</locationY>
        <assignNullValuesIfNoRecordsFound>false</assignNullValuesIfNoRecordsFound>
        <filterLogic>and</filterLogic>
        <filters>
            <field>Name</field>
            <operator>EqualTo</operator>
            <value>
                <stringValue>Acme</stringValue>
            </value>
        </filters>
        <getFirstRecordOnly>true</getFirstRecordOnly>
        <object>Account</object>
        <storeOutputAutomatically>true</storeOutputAutomatically>
    </recordLookups>
    <start>
        <locationX>970</locationX>
        <locationY>48</locationY>
        <object>Case</object>
        <scheduledPaths>
            <connector>
                <targetReference>Get_Account</targetReference>
            </connector>
            <pathType>AsyncAfterCommit</pathType>
        </scheduledPaths>
    </start>
    <status>Active</status>
</Flow>

So, leaving as regular flow without scheduled path then it works:

<?xml version="1.0" encoding="UTF-8"?>
<Flow xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>58.0</apiVersion>
    <environments>Default</environments>
    <interviewLabel>Sample Flow Scheduled Path {!$Flow.CurrentDateTime}</interviewLabel>
    <label>Sample Flow Scheduled Path</label>
    <processMetadataValues>
        <name>BuilderType</name>
        <value>
            <stringValue>LightningFlowBuilder</stringValue>
        </value>
    </processMetadataValues>
    <processMetadataValues>
        <name>CanvasMode</name>
        <value>
            <stringValue>FREE_FORM_CANVAS</stringValue>
        </value>
    </processMetadataValues>
    <processMetadataValues>
        <name>OriginBuilderType</name>
        <value>
            <stringValue>LightningFlowBuilder</stringValue>
        </value>
    </processMetadataValues>
    <processType>AutoLaunchedFlow</processType>
    <recordLookups>
        <name>Get_Account</name>
        <label>Get Account</label>
        <locationX>964</locationX>
        <locationY>324</locationY>
        <assignNullValuesIfNoRecordsFound>false</assignNullValuesIfNoRecordsFound>
        <filterLogic>and</filterLogic>
        <filters>
            <field>Name</field>
            <operator>EqualTo</operator>
            <value>
                <stringValue>Acme</stringValue>
            </value>
        </filters>
        <getFirstRecordOnly>true</getFirstRecordOnly>
        <object>Account</object>
        <storeOutputAutomatically>true</storeOutputAutomatically>
    </recordLookups>
    <start>
        <locationX>970</locationX>
        <locationY>48</locationY>
        <object>Case</object>
        <recordTriggerType>Update</recordTriggerType>
            <connector>
                <targetReference>Get_Account</targetReference>
            </connector>
        <triggerType>RecordAfterSave</triggerType>
    </start>
    <status>Active</status>
</Flow>

The difference is that the 'regular' connector on this case is empty but there is one under scheduledPaths:

     <start>
        <locationX>970</locationX>
        <locationY>48</locationY>
        <object>Case</object>
        <scheduledPaths>
            <connector>
                <targetReference>Get_Account</targetReference>
            </connector>
            <pathType>AsyncAfterCommit</pathType>
        </scheduledPaths>
    </start>
toddhalfpenny commented 9 months ago

Thanks @jefersonchaves - so it seems I may be mis-handling this scenario. Cheers so much for the extra XML examples.

toddhalfpenny commented 9 months ago

Fixed as part of v.0.2.2