From e8f212c1759b83d9b44cbaf00a820ac75a74113d Mon Sep 17 00:00:00 2001 From: mshanemc Date: Mon, 16 Oct 2023 07:30:14 -0500 Subject: [PATCH] fix: don't use tooling api to get flow id --- src/commands/org/open.ts | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/commands/org/open.ts b/src/commands/org/open.ts index a01bb1a2..cfd130c9 100644 --- a/src/commands/org/open.ts +++ b/src/commands/org/open.ts @@ -176,18 +176,17 @@ export interface OrgOpenOutput { orgId: string; } -/** query the tooling API to turn a flow's filepath into a FlowId (starts with 301) */ +/** query the rest API to turn a flow's filepath into a FlowId (starts with 301) */ const flowFileNameToId = async (conn: Connection, filePath: string): Promise => { - const result = await conn.tooling.query<{ Id: string; FullName: string }>( - 'select id, MasterLabel, FullName from Flow' - ); - const fullName = path.basename(filePath).replace('.flow-meta.xml', ''); - // https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_flow.htm - // unfortunately, you can't query based on the fullname because `field 'FullName' can not be filtered in a query call` - // so we get all the flows and then filter. - const match = (result.records ?? []).find((r) => r.FullName === fullName)?.Id; - if (match) { - return match; + try { + const flow = await conn.singleRecordQuery<{ DurableId: string }>( + `SELECT DurableId FROM FlowVersionView WHERE FlowDefinitionView.ApiName = '${path.basename( + filePath, + '.flow-meta.xml' + )}' ORDER BY VersionNumber DESC LIMIT 1` + ); + return flow.DurableId; + } catch (error) { + throw messages.createError('FlowIdNotFound', [filePath]); } - throw messages.createError('FlowIdNotFound', [filePath]); };