【Salesforce/VSCode】組織からソースを取得 についての補足
概要
Salesforce組織側でのみ保持しているApexソースを、Visual Studio Code(VSCode)を使った統合開発環境上に取得する際にCLIの実行が必要だったので、その内容を記載します。
(VSCode>Salesforce Extension Packの「SFDX:組織からソースを取得」では取得できませんでした)
前提
今回はVSCode上でのプロジェクト作成や組織認証については割愛します。
下記あたりをざっくり理解していれば大丈夫です。
Salesforce CLI
Salesforce Extensions for VS Code
クイックスタート: Salesforce 開発のための Visual Studio Code
事象
今回はApex Triggerの取得を行いたいので、VSCode上で/force-app/main/default/triggers
フォルダに対して「SFDX:組織からソースを取得」を実行しました。
が、下記出力ログの通り、取得ができません。。。
Starting SFDX: 組織からソースを取得
No components in the package to retrieve
解決方法
CLIを使ってsfdx force:source:retrieve -m ApexTrigger
の実行で取得できました。
$ sfdx force:source:retrieve -m ApexTrigger
Preparing retrieve request... done
=== Retrieved Source
FULL NAME TYPE PROJECT PATH
───────────────────── ─────────── ──────────────────────────────────────────────────────────────────────
AccountTrigger ApexTrigger force-app/main/default/triggers/AccountTrigger.trigger
AccountTrigger ApexTrigger force-app/main/default/triggers/AccountTrigger.trigger-meta.xml
※ Apexクラスの取得であればsfdx force:source:retrieve -m ApexClass
で可能です
補足
VSCodeのSalesforce Extension Packでは解決ができていないようなので、CLI側で解決しました。(該当ヘルプは下記の通りです)
また、一度ソース取得を行うとVSCode側の「SFDX:組織からソースを取得」からでも取得ができるようになりました。
$ sfdx force:source:retrieve --help
retrieve source from an org
USAGE
$ sfdx force:source:retrieve [-p <array> | -x <filepath> | -m <array>] [-w <minutes>] [-n <array>] [-u <string>] [-a <string>] [--verbose] [--json] [--loglevel
trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL]
OPTIONS
-a, --apiversion=apiversion override the api version used for api requests made by this command
-m, --metadata=metadata comma-separated list of metadata component names
-n, --packagenames=packagenames a comma-separated list of packages to retrieve
-p, --sourcepath=sourcepath comma-separated list of source file paths to retrieve
-u, --targetusername=targetusername username or alias for the target org; overrides default target org
-w, --wait=wait [default: [object Object]] wait time for command to finish in minutes
-x, --manifest=manifest file path for manifest (package.xml) of components to retrieve
--json format output as json
--loglevel=(trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL) [default: warn] logging level for this command invocation
--verbose verbose output of retrieve result
DESCRIPTION
Use this command to retrieve source (metadata that’s in source format) from an org.
To take advantage of change tracking with scratch orgs, use "sfdx force:source:pull".
To retrieve metadata that’s in metadata format, use "sfdx force:mdapi:retrieve".
The source you retrieve overwrites the corresponding source files in your local project. This command does not attempt to merge the source from your org with your local source files.
If the comma-separated list you’re supplying contains spaces, enclose the entire comma-separated list in one set of double quotes. On Windows, if the list contains commas, also enclose it in one set of double quotes.
EXAMPLES
To retrieve the source files in a directory:
$ sfdx force:source:retrieve -p path/to/source
To retrieve a specific Apex class and the objects whose source is in a directory:
$ sfdx force:source:retrieve -p "path/to/apex/classes/MyClass.cls,path/to/source/objects"
To retrieve source files in a comma-separated list that contains spaces:
$ sfdx force:source:retrieve -p "path/to/objects/MyCustomObject/fields/MyField.field-meta.xml, path/to/apex/classes
To retrieve all Apex classes:
$ sfdx force:source:retrieve -m ApexClass
To retrieve a specific Apex class:
$ sfdx force:source:retrieve -m ApexClass:MyApexClass
To retrieve all custom objects and Apex classes:
$ sfdx force:source:retrieve -m "CustomObject,ApexClass
To retrieve all Apex classes and two specific profiles (one of which has a space in its name):
$ sfdx force:source:retrieve -m "ApexClass, Profile:My Profile, Profile: AnotherProfile"
To retrieve all metadata components listed in a manifest:
$ sfdx force:source:retrieve -x path/to/package.xml
To retrieve metadata from a package or multiple packages:
$ sfdx force:source:retrieve -n MyPackageName
$ sfdx force:source:retrieve -n "Package1, PackageName With Spaces, Package3"
To retrieve all metadata from a package and specific components that aren’t in the package, specify both -n | --packagenames and one other scoping parameter:
$ sfdx force:source:retrieve -n MyPackageName -p path/to/apex/classes
$ sfdx force:source:retrieve -n MyPackageName -m ApexClass:MyApexClass
$ sfdx force:source:retrieve -n MyPackageName -x path/to/package.xml
Author And Source
この問題について(【Salesforce/VSCode】組織からソースを取得 についての補足), 我々は、より多くの情報をここで見つけました https://qiita.com/abichibi/items/f272bd913300a947a97d著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .