Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const conn = this.org.getConnection();
const query = 'Select Name, TrialExpirationDate from Organization';
// The type we are querying for
interface Organization {
Name: string;
TrialExpirationDate: string;
}
// Query the org
const result = await conn.query(query);
// Organization will always return one result, but this is an example of throwing an error
// The output and --json will automatically be handled for you.
if (!result.records || result.records.length <= 0) {
throw new core.SfdxError(messages.getMessage('errorNoOrgResults', [this.org.getOrgId()]));
}
// Organization always only returns one result
const orgName = result.records[0].Name;
const trialExpirationDate = result.records[0].TrialExpirationDate;
let outputString = `Hello ${name}! This is org: ${orgName}`;
if (trialExpirationDate) {
const date = new Date(trialExpirationDate).toDateString();
outputString = `${outputString} and I will be around until ${date}!`;
}
this.ux.log(outputString);
// this.hubOrg is NOT guaranteed because supportsHubOrgUsername=true, as opposed to requiresHubOrgUsername.
if (this.hubOrg) {
const hubOrgId = this.hubOrg.getOrgId();
const conn = this.org.getConnection();
const query = 'Select Name, TrialExpirationDate from Organization';
// The type we are querying for
interface Organization {
Name: string;
TrialExpirationDate: string;
}
// Query the org
const result = await conn.query(query);
// Organization will always return one result, but this is an example of throwing an error
// The output and --json will automatically be handled for you.
if (!result.records || result.records.length <= 0) {
throw new core.SfdxError(messages.getMessage('errorNoOrgResults', [this.org.getOrgId()]));
}
// Organization always only returns one result
const orgName = result.records[0].Name;
const trialExpirationDate = result.records[0].TrialExpirationDate;
let outputString = `Hello ${name}! This is org: ${orgName}`;
if (trialExpirationDate) {
const date = new Date(trialExpirationDate).toDateString();
outputString = `${outputString} and I will be around until ${date}!`;
}
this.ux.log(outputString);
// this.hubOrg is NOT guaranteed because supportsHubOrgUsername=true, as opposed to requiresHubOrgUsername.
if (this.hubOrg) {
const hubOrgId = this.hubOrg.getOrgId();
public static throwError(msg: any) {
this.isAborted = true;
this.abortedCounter++;
if (msg.stack) {
Util.writeLog(`*** Abort Counter: ${this.abortedCounter} ***`, LogLevel.FATAL);
Util.writeLog(msg.stack, LogLevel.FATAL);
}
throw new core.SfdxError(msg, "Error", null, -1);
}