Skip to content
This repository was archived by the owner on Nov 5, 2023. It is now read-only.

Commit 2b93084

Browse files
author
Mohith Shrivastava
committed
refactor for insert and security patch
1 parent 609e2bb commit 2b93084

File tree

9 files changed

+561
-489
lines changed

9 files changed

+561
-489
lines changed

oclif.manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"0.2.8","commands":{"deploy:apex":{"id":"deploy:apex","description":"Deploy apex class using tooling api","usage":"<%= command.id %> -p <string> [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]","pluginName":"mo-dx-plugin","pluginType":"core","aliases":[],"examples":["$ sfdx deploy:apex -p filepath"],"flags":{"json":{"name":"json","type":"boolean","description":"format output as json","allowNo":false},"loglevel":{"name":"loglevel","type":"option","description":"logging level for this command invocation","required":false,"helpValue":"(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL)","options":["trace","debug","info","warn","error","fatal","TRACE","DEBUG","INFO","WARN","ERROR","FATAL"],"default":"warn"},"targetusername":{"name":"targetusername","type":"option","char":"u","description":"username or alias for the target org; overrides default target org"},"apiversion":{"name":"apiversion","type":"option","description":"override the api version used for api requests made by this command"},"filepath":{"name":"filepath","type":"option","char":"p","description":"file path","required":true}},"args":[]},"deploy:aura":{"id":"deploy:aura","description":"Deploy aura bundles using tooling api","usage":"<%= command.id %> -p <string> [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]","pluginName":"mo-dx-plugin","pluginType":"core","aliases":[],"examples":["$ sfdx deploy:aura -p filepath"],"flags":{"json":{"name":"json","type":"boolean","description":"format output as json","allowNo":false},"loglevel":{"name":"loglevel","type":"option","description":"logging level for this command invocation","required":false,"helpValue":"(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL)","options":["trace","debug","info","warn","error","fatal","TRACE","DEBUG","INFO","WARN","ERROR","FATAL"],"default":"warn"},"targetusername":{"name":"targetusername","type":"option","char":"u","description":"username or alias for the target org; overrides default target org"},"apiversion":{"name":"apiversion","type":"option","description":"override the api version used for api requests made by this command"},"filepath":{"name":"filepath","type":"option","char":"p","description":"file path","required":true}},"args":[]},"deploy:lwc":{"id":"deploy:lwc","description":"Deploy lwc wusing tooling api","usage":"<%= command.id %> [-p <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]","pluginName":"mo-dx-plugin","pluginType":"core","aliases":[],"examples":["$ sfdx deploy:lwc -p filepath"],"flags":{"json":{"name":"json","type":"boolean","description":"format output as json","allowNo":false},"loglevel":{"name":"loglevel","type":"option","description":"logging level for this command invocation","required":false,"helpValue":"(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL)","options":["trace","debug","info","warn","error","fatal","TRACE","DEBUG","INFO","WARN","ERROR","FATAL"],"default":"warn"},"targetusername":{"name":"targetusername","type":"option","char":"u","description":"username or alias for the target org; overrides default target org"},"apiversion":{"name":"apiversion","type":"option","description":"override the api version used for api requests made by this command"},"filepath":{"name":"filepath","type":"option","char":"p","description":"file path"}},"args":[]},"deploy:staticresource":{"id":"deploy:staticresource","description":"Deploy static resource using tooling api","usage":"<%= command.id %> [-p <string>] [-r <string>] [-c <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]","pluginName":"mo-dx-plugin","pluginType":"core","aliases":[],"examples":["$ sfdx deploy:staticresource -p <filepath>","$ sfdx deploy:staticresource -p <filepath> --cachecontrol public","$ sfdx deploy:staticresource -p <filepath> --cachecontrol public --resourcefolder <name of the folder where you have single page app>"],"flags":{"json":{"name":"json","type":"boolean","description":"format output as json","allowNo":false},"loglevel":{"name":"loglevel","type":"option","description":"logging level for this command invocation","required":false,"helpValue":"(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL)","options":["trace","debug","info","warn","error","fatal","TRACE","DEBUG","INFO","WARN","ERROR","FATAL"],"default":"warn"},"targetusername":{"name":"targetusername","type":"option","char":"u","description":"username or alias for the target org; overrides default target org"},"apiversion":{"name":"apiversion","type":"option","description":"override the api version used for api requests made by this command"},"filepath":{"name":"filepath","type":"option","char":"p","description":"file path of the resource bundle"},"resourcefolder":{"name":"resourcefolder","type":"option","char":"r","description":"name of the folder where you have single page app, This defaults to staticresources","default":"staticresources"},"cachecontrol":{"name":"cachecontrol","type":"option","char":"c","description":"cache control, defaults to public","default":"private"}},"args":[]},"deploy:trigger":{"id":"deploy:trigger","description":"Deploy apex triggers using tooling api","usage":"<%= command.id %> -p <string> [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]","pluginName":"mo-dx-plugin","pluginType":"core","aliases":[],"examples":["$ sfdx deploy:trigger -p filepath"],"flags":{"json":{"name":"json","type":"boolean","description":"format output as json","allowNo":false},"loglevel":{"name":"loglevel","type":"option","description":"logging level for this command invocation","required":false,"helpValue":"(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL)","options":["trace","debug","info","warn","error","fatal","TRACE","DEBUG","INFO","WARN","ERROR","FATAL"],"default":"warn"},"targetusername":{"name":"targetusername","type":"option","char":"u","description":"username or alias for the target org; overrides default target org"},"apiversion":{"name":"apiversion","type":"option","description":"override the api version used for api requests made by this command"},"filepath":{"name":"filepath","type":"option","char":"p","description":"file path","required":true}},"args":[]},"deploy:vf":{"id":"deploy:vf","description":"Deploy visualforce page using tooling api","usage":"<%= command.id %> -p <string> [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]","pluginName":"mo-dx-plugin","pluginType":"core","aliases":[],"examples":["$ sfdx deploy:vf -p filepath"],"flags":{"json":{"name":"json","type":"boolean","description":"format output as json","allowNo":false},"loglevel":{"name":"loglevel","type":"option","description":"logging level for this command invocation","required":false,"helpValue":"(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL)","options":["trace","debug","info","warn","error","fatal","TRACE","DEBUG","INFO","WARN","ERROR","FATAL"],"default":"warn"},"targetusername":{"name":"targetusername","type":"option","char":"u","description":"username or alias for the target org; overrides default target org"},"apiversion":{"name":"apiversion","type":"option","description":"override the api version used for api requests made by this command"},"filepath":{"name":"filepath","type":"option","char":"p","description":"file path","required":true}},"args":[]},"deploy:vfcomponent":{"id":"deploy:vfcomponent","description":"Deploy visualforce components using tooling api","usage":"<%= command.id %> -p <string> [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]","pluginName":"mo-dx-plugin","pluginType":"core","aliases":[],"examples":["$ sfdx deploy:vfcomponent -p filepath"],"flags":{"json":{"name":"json","type":"boolean","description":"format output as json","allowNo":false},"loglevel":{"name":"loglevel","type":"option","description":"logging level for this command invocation","required":false,"helpValue":"(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL)","options":["trace","debug","info","warn","error","fatal","TRACE","DEBUG","INFO","WARN","ERROR","FATAL"],"default":"warn"},"targetusername":{"name":"targetusername","type":"option","char":"u","description":"username or alias for the target org; overrides default target org"},"apiversion":{"name":"apiversion","type":"option","description":"override the api version used for api requests made by this command"},"filepath":{"name":"filepath","type":"option","char":"p","description":"file path","required":true}},"args":[]},"metadata:rename":{"id":"metadata:rename","description":"Rename metadata using metadata api","usage":"<%= command.id %> -t <string> -n <string> -o <string> [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]","pluginName":"mo-dx-plugin","pluginType":"core","aliases":[],"examples":["$ sfdx metadata:rename -t <metadatatype> -n <newname> -o <oldname>","$ sfdx metadata:rename -t CustomObject -n MyCustomObject1New__c -o MyCustomObject1__c"],"flags":{"json":{"name":"json","type":"boolean","description":"format output as json","allowNo":false},"loglevel":{"name":"loglevel","type":"option","description":"logging level for this command invocation","required":false,"helpValue":"(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL)","options":["trace","debug","info","warn","error","fatal","TRACE","DEBUG","INFO","WARN","ERROR","FATAL"],"default":"warn"},"targetusername":{"name":"targetusername","type":"option","char":"u","description":"username or alias for the target org; overrides default target org"},"apiversion":{"name":"apiversion","type":"option","description":"override the api version used for api requests made by this command"},"metadatatype":{"name":"metadatatype","type":"option","char":"t","description":"type of the metadata. Examples are CustomObject, Profile","required":true},"newfullname":{"name":"newfullname","type":"option","char":"n","description":"new name of the metadata element","required":true},"oldfullname":{"name":"oldfullname","type":"option","char":"o","description":"old name of the metadata element","required":true}},"args":[]},"retrieve:dxsource":{"id":"retrieve:dxsource","description":"Retrieves Source is DX format from Unmanaged/Managed package","usage":"<%= command.id %> -n <string> [-p <string>] [-m <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]","pluginName":"mo-dx-plugin","pluginType":"core","aliases":[],"examples":["$ sfdx retrieve:dxsource -n <package/changeset>","$ sfdx retrieve:dxsource -n <package/changeset> -m \"true\"","$ sfdx retrieve:dxsource -n <package/changeset> -p <[pathName]>","$ sfdx retrieve:dxsource -u myOrg@example.com -n <package/changeset> -p <[pathName]>"],"flags":{"json":{"name":"json","type":"boolean","description":"format output as json","allowNo":false},"loglevel":{"name":"loglevel","type":"option","description":"logging level for this command invocation","required":false,"helpValue":"(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL)","options":["trace","debug","info","warn","error","fatal","TRACE","DEBUG","INFO","WARN","ERROR","FATAL"],"default":"warn"},"targetusername":{"name":"targetusername","type":"option","char":"u","description":"username or alias for the target org; overrides default target org"},"apiversion":{"name":"apiversion","type":"option","description":"override the api version used for api requests made by this command"},"packagename":{"name":"packagename","type":"option","char":"n","description":"the name of the package you want to retrieve","required":true},"pathname":{"name":"pathname","type":"option","char":"p","description":"where to convert the result to.defaults to force-app","default":"force-app"},"retainmetadata":{"name":"retainmetadata","type":"option","char":"m","description":"If set retain the metadata folder in mdapiout directory and do not clean"}},"args":[]},"retrieve:pkgsource":{"id":"retrieve:pkgsource","description":"Retrieves Source from Unmanaged/Managed package in Metadata API format","usage":"<%= command.id %> -n <string> [-r <string>] [-u <string>] [--apiversion <string>] [--json] [--loglevel trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]","pluginName":"mo-dx-plugin","pluginType":"core","aliases":[],"examples":["$ sfdx retrieve:pkgsource -n <package/changeset>","$ sfdx retrieve:pkgsource -n <package/changeset> -r <relative path where source is retrieved and unzipped>","$ sfdx retrieve:pkgsource -n <package/changeset> -r /changesets/src"],"flags":{"json":{"name":"json","type":"boolean","description":"format output as json","allowNo":false},"loglevel":{"name":"loglevel","type":"option","description":"logging level for this command invocation","required":false,"helpValue":"(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL)","options":["trace","debug","info","warn","error","fatal","TRACE","DEBUG","INFO","WARN","ERROR","FATAL"],"default":"warn"},"targetusername":{"name":"targetusername","type":"option","char":"u","description":"username or alias for the target org; overrides default target org"},"apiversion":{"name":"apiversion","type":"option","description":"override the api version used for api requests made by this command"},"packagename":{"name":"packagename","type":"option","char":"n","description":"the name of the package you want to retrieve","required":true},"retrievedir":{"name":"retrievedir","type":"option","char":"r","description":"directory path to retrieve","required":false}},"args":[]}}}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"fs-extra": "^8.1.0",
1515
"lodash": "^4.17.13",
1616
"mime-types": "^2.1.24",
17+
"xmldom-sfdx-encoding": "^0.1.29",
1718
"tslib": "^1.9.3"
1819
},
1920
"devDependencies": {
@@ -35,7 +36,7 @@
3536
"nyc": "^14",
3637
"sinon": "5",
3738
"ts-node": "^7",
38-
"typescript": "~3.3.3"
39+
"typescript": "3"
3940
},
4041
"engines": {
4142
"node": ">=8.0.0"

src/commands/deploy/apex.ts

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { core, flags, SfdxCommand } from '@salesforce/command';
22
import { AnyJson } from '@salesforce/ts-types';
33
import * as chalk from 'chalk';
44
import fs = require('fs-extra');
5-
import { SobjectResult } from '../../models/sObjectResult';
65
import { Deploy, DeployResult } from '../../service/deploy';
76
import {display, displaylog} from '../../service/displayError';
87
import { getFileName } from '../../service/getFileName';
@@ -50,6 +49,8 @@ export default class ApexDeploy extends SfdxCommand {
5049

5150
const filebody = await fs.readFile(this.flags.filepath, 'utf8');
5251

52+
const fileMetaXML = await fs.readFile(this.flags.filepath + '-meta.xml', 'utf8');
53+
5354
// get the apex class Id using the class Name
5455
const className = getFileName(this.flags.filepath, '.cls');
5556
const apexclass = await conn.tooling.sobject('Apexclass').find({
@@ -59,37 +60,24 @@ export default class ApexDeploy extends SfdxCommand {
5960

6061
// logic to update apex class
6162
if (apexclass.length > 0) {
62-
const updateResult = await this.updateApex(apexclass, filebody, conn) as any; // tslint:disable-line:no-any
63+
const updateResult = await this.updateApex(apexclass, filebody, fileMetaXML, conn, className, 'Updated') as any; // tslint:disable-line:no-any
6364
return updateResult;
6465
} else {
65-
// logic to create an apex class
66-
const apexClass = {
67-
Body: filebody,
68-
NamespacePrefix: namespacePrefix
69-
} as ApexClass;
70-
71-
try {
72-
const apexSaveResult = await conn.tooling.sobject('ApexClass').create(apexClass) as SobjectResult;
73-
if ( apexSaveResult.success) {
74-
this.ux.stopSpinner(chalk.bold.green('Apex Class Successfully Created ✔'));
75-
} else {
76-
this.ux.table(apexSaveResult.errors);
77-
this.ux.stopSpinner(chalk.bold.red('Apex Class Creation Failed ×'));
78-
}
79-
return apexSaveResult as any ; // tslint:disable-line:no-any
80-
} catch (ex) {
81-
displaylog(chalk.bold.red(ex), this.ux);
82-
this.ux.stopSpinner(chalk.bold.red('Apex Class Creation Failed ×'));
83-
}
66+
// We compile the code with null as EntityId
67+
const updateResult = await this.updateApex(null, filebody, fileMetaXML, conn, className, 'Created') as any; // tslint:disable-line:no-any
68+
return updateResult;
8469
}
8570
}
8671

87-
private async updateApex(apexclass: ApexClass[], filebody: string, conn: core.Connection) {
88-
const classId = apexclass[0].Id;
89-
const deployAction = new Deploy('ApexContainer', 'ApexClassMember', classId, filebody, conn);
72+
private async updateApex(apexclass: ApexClass[], filebody: string, metadataXML: string, conn: core.Connection, className: string, mode: string) {
73+
let classId = null;
74+
if (apexclass ) {
75+
classId = apexclass[0].Id;
76+
}
77+
const deployAction = new Deploy('ApexContainer', 'ApexClassMember', className, classId, filebody, metadataXML, conn);
9078
const deployResult = await deployAction.deployMetadata() as DeployResult;
9179
if (deployResult.success) {
92-
this.ux.stopSpinner(chalk.bold.greenBright('Apex Class Successfully Updated ✔'));
80+
this.ux.stopSpinner(chalk.bold.greenBright('Apex Class Successfully ' + mode + ' ✔'));
9381
} else {
9482
if (deployResult.queryResult.records.length > 0 && deployResult.queryResult.records[0].DeployDetails.componentFailures.length > 0) {
9583
display(deployResult, this.ux);

0 commit comments

Comments
 (0)