Visual Studio Code for Salesforce

#1.必要なツールのインストール

- [Visual Studio Code](https://code.visualstudio.com/)
- [Java 8 Platform, Standard Edition Development Kit](https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html)
- [Salesforce CLI](https://developer.salesforce.com/ja/tools/sfdxcli)

#2.Visual Studio Code プラグインのインストール

- Salesforce Extension Pack(**※必須**)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/332907/7a8b3f04-4073-bccb-c884-005e6d571e65.png)


#3.便利な機能
**3-1.オブジェクト情報の補完機能**
ⅰ．「SFDX:Refresh SObject Definitions」コマンド実行
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/332907/a0311100-bb0e-d059-f0ce-381411d395a1.png)

ⅱ．オブジェクト定義情報取得
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/332907/7d19893e-c2fe-6af2-edf3-3739399ebecc.png)

ⅲ．コマンド実行後、組織からオブジェクトの情報が読み込まれ、完了後オブジェクトの補完が可能になります。

- オブジェクト情報取得後は一度 Visual Studio Code を再起動した方がよさそうです。
- 組織でオブジェクトに項目の追加があった際などは、再度コマンドを実行して再取得します。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/332907/73581cd1-b2cd-d811-1448-3ebcee6f7f01.png)

**3-2.Diff機能**
Salesforce Extension Pack 本体が正しくインストールされていることが前提条件となります。
ⅰ．下記のコマンドをコマンドプロンプトから実行します。

```
sfdx plugins:install @salesforce/sfdx-diff
```

ⅱ．比較イメージ
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/332907/6589633a-573d-76a5-60f3-54c4c269d263.png)

#4.Visual Studio Code 設定
4-1.半角スペース可視化
VS Codeではユーザー設定／ワークスペース設定でeditor.renderWhitespace項目を設定することで、空白文字の描画方法（表示形式）を切り替えられる。設定可能な値は次の3つだ。

- "none"：空白文字を描画しない（空白のまま）
- "boundary"：単語を分ける単一の空白文字以外は描画する
- "all"：全ての空白文字を描画する

4-2.全角スペース可視化
Visual Studio Code プラグインのインストール：[evilinspector](https://marketplace.visualstudio.com/items?itemName=saikou9901.evilinspector)


4-3.convert spaces to tabs 
コマンドパレットで下記のcommandを実行する

```
Convert Indentation to Tabs
```

#90.Q＆A
**90-1.SFDX: Authorize an Org**
>15:23:41.710 sfdx force:auth:web:login --setalias VSCodePlayground --instanceurl >https://login.salesforce.com --setdefaultusername
> ›   Warning: force:auth:web:login is not a sfdx command.
>Did you mean auth:web:login? [y/n]: 
> ›   Error: Run sfdx help force for a list of available commands.
>15:23:47.396 sfdx force:auth:web:login --setalias VSCodePlayground --instanceurl >https://login.salesforce.com --setdefaultusername
> ended with exit code 127

```java:解決方法
Run this in CMD "sfdx plugin:install @salesforce/plugin-auth@1.4.3"
```
https://github.com/forcedotcom/salesforcedx-vscode/issues/2869
https://github.com/forcedotcom/cli/issues/757#issuecomment-741885504

**90-2.SFDX: Retrieve Source in Manifest from Org**
>01:32:49.862 sfdx force:source:retrieve --manifest > c:\Users\xuwenzhen\Desktop\Demo\manifest\package.xml
>ERROR running force:source:retrieve:  Cannot read property 'fileName' of undefined
>01:35:01.917 sfdx force:source:retrieve --manifest c:\Users\xuwenzhen\Desktop\Demo\manifest\package.xml
> ended with exit code 1

```java:解決方法
Run this in CMD "sfdx update"
```
https://salesforce.stackexchange.com/questions/251431/sfdx-error-cannot-read-property-filename-of-undefined

#91.Package.xml to get all the metadata using Visual Studio Code for Salesforce
https://www.infallibletechie.com/2018/12/packagexml-to-get-all-metadata-using.html

https://marketplace.visualstudio.com/items?itemName=VignaeshRamA.sfdx-package-xml-generator

```xml:Package.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>  
<Package xmlns="http://soap.sforce.com/2006/04/metadata">  
    <types>  
        <members>*</members>  
        <name>ApexClass</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>ApexComponent</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>ApexPage</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>ApexTestSuite</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>ApexTrigger</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>AuraDefinitionBundle</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>StaticResource</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>CustomApplication</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>ApprovalProcess</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>AssignmentRule</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>AuthProvider</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>CallCenter</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>Community</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>ConnectedApp</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>CustomApplicationComponent</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>CustomMetadata</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>CustomPermission</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>Dashboard</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>DataCategoryGroup</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>Document</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>EmailTemplate</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>EntitlementProcess</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>EntitlementTemplate</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>FlexiPage</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>Flow</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>Group</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>HomePageComponent</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>HomePageLayout</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>CustomLabels</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>Layout</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>MilestoneType</name>  
    </types>  
    <types>  
        <members>Account</members>  
        <members>AccountContactRole</members>  
        <members>Activity</members>  
        <members>Asset</members>  
        <members>AssetRelationship</members>  
        <members>AssistantProgress</members>  
        <members>Campaign</members>  
        <members>CampaignMember</members>  
        <members>Case</members>  
        <members>CaseContactRole</members>  
        <members>CaseMilestone</members>  
        <members>ChatterActivity</members>  
        <members>CollaborationGroup</members>  
        <members>CollaborationGroupMember</members>  
        <members>Contact</members>  
        <members>ContentVersion</members>  
        <members>Contract</members>  
        <members>ContractContactRole</members>  
        <members>ContractLineItem</members>  
        <members>DuplicateRecordItem</members>  
        <members>DuplicateRecordSet</members>  
        <members>EmailMessage</members>  
        <members>Entitlement</members>  
        <members>EntitlementContact</members>  
        <members>EntityMilestone</members>  
        <members>Event</members>  
        <members>ExchangeUserMapping</members>  
        <members>FeedItem</members>  
        <members>ForecastingAdjustment</members>  
        <members>ForecastingCategoryMapping</members>  
        <members>ForecastingOwnerAdjustment</members>  
        <members>ForecastingQuota</members>  
        <members>ForecastingTypeToCategory</members>  
        <members>Idea</members>  
        <members>Indicator_Badge__mdt</members>  
        <members>Lead</members>  
        <members>LeadGen_Reroute_Parent_Queue__mdt</members>  
        <members>Macro</members>  
        <members>MacroAction</members>  
        <members>MacroInstruction</members>  
        <members>Opportunity</members>  
        <members>OpportunityCompetitor</members>  
        <members>OpportunityContactRole</members>  
        <members>OpportunityLineItem</members>  
        <members>Order</members>  
        <members>OrderItem</members>  
        <members>PartnerRole</members>  
        <members>PersonAccount</members>  
        <members>Pricebook2</members>  
        <members>PricebookEntry</members>  
        <members>Product2</members>  
        <members>ProfileSkill</members>  
        <members>ProfileSkillEndorsement</members>  
        <members>ProfileSkillUser</members>  
        <members>QuickText</members>  
        <members>Quote</members>  
        <members>QuoteLineItem</members>  
        <members>RecordAction</members>  
        <members>RequestsForAccessSIQ</members>  
        <members>Scorecard</members>  
        <members>ScorecardAssociation</members>  
        <members>ScorecardMetric</members>  
        <members>ServiceContract</members>  
        <members>Site</members>  
        <members>SocialPersona</members>  
        <members>Solution</members>  
        <members>StreamActivityAccess</members>  
        <members>StreamingChannel</members>  
        <members>Task</members>  
        <members>Topic</members>  
        <members>TopicAssignment</members>  
        <members>User</members>  
        <members>WorkBadge</members>  
        <members>WorkBadgeDefinition</members>  
        <members>WorkOrder</members>  
        <members>WorkOrderLineItem</members>  
        <members>WorkThanks</members>  
        <members>*</members>  
        <name>CustomObject</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>Letterhead</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>CustomObjectTranslation</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>PermissionSet</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>PostTemplate</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>Profile</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>Queue</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>QuickAction</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>RemoteSiteSetting</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>ReportType</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>Workflow</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>Report</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>SiteDotCom</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>CustomSite</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>Scontrol</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>Settings</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>CustomTab</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>Translations</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>CustomPageWebLink</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>Role</name>  
    </types>  
    <types>  
        <members>*</members>  
        <name>SamlSsoConfig</name>  
    </types>  
    <version>44.0</version>  
</Package>  

```

#◆参照資料◆
Visual Studio CodeでSalesforceの開発環境を構築する(winter '19)
https://base.terrasky.co.jp/articles/5f2tk

Visual Studio Code開発環境で役立つエクステンション機能について（その１）
https://base.terrasky.co.jp/articles/2NoKM

Visual Studio Code開発環境で役立つエクステンション機能について（その２）
https://base.terrasky.co.jp/articles/mIaRN

Visual Studio Code開発環境で役立つエクステンション機能について（その３）
https://base.terrasky.co.jp/articles/ijWiN

Visual Studio Code開発環境で役立つエクステンション機能について（その４）

可読性が高いSOQLフォーマットのご紹介
https://base.terrasky.co.jp/articles/FRD1u