Skip to content

Commit 271e69b

Browse files
authored
Merge pull request #836 from salesforcecli/sm/flow-via-non-tooling-api
fix: don't use tooling api to get flow id
2 parents abbe44c + e8f212c commit 271e69b

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/commands/org/open.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,17 @@ export interface OrgOpenOutput {
176176
orgId: string;
177177
}
178178

179-
/** query the tooling API to turn a flow's filepath into a FlowId (starts with 301) */
179+
/** query the rest API to turn a flow's filepath into a FlowId (starts with 301) */
180180
const flowFileNameToId = async (conn: Connection, filePath: string): Promise<string> => {
181-
const result = await conn.tooling.query<{ Id: string; FullName: string }>(
182-
'select id, MasterLabel, FullName from Flow'
183-
);
184-
const fullName = path.basename(filePath).replace('.flow-meta.xml', '');
185-
// https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_flow.htm
186-
// unfortunately, you can't query based on the fullname because `field 'FullName' can not be filtered in a query call`
187-
// so we get all the flows and then filter.
188-
const match = (result.records ?? []).find((r) => r.FullName === fullName)?.Id;
189-
if (match) {
190-
return match;
181+
try {
182+
const flow = await conn.singleRecordQuery<{ DurableId: string }>(
183+
`SELECT DurableId FROM FlowVersionView WHERE FlowDefinitionView.ApiName = '${path.basename(
184+
filePath,
185+
'.flow-meta.xml'
186+
)}' ORDER BY VersionNumber DESC LIMIT 1`
187+
);
188+
return flow.DurableId;
189+
} catch (error) {
190+
throw messages.createError('FlowIdNotFound', [filePath]);
191191
}
192-
throw messages.createError('FlowIdNotFound', [filePath]);
193192
};

0 commit comments

Comments
 (0)