# Salesforce developer guide ## Trailhead [Trailhead](https://trailhead.salesforce.com/ ) 是 Salesforce 官方提供給開發者的線上學習平台,和 Google 的 [qwiklabs](https://go.qwiklabs.com/qwiklabs-free),AWS 的 [training and certification](https://www.aws.training/) 等服務類似,讓開發者透過線上互動的方式來學習特定的主題,解成就並取得相關認證,而且是完全免費的 Trailhead 還有一個公開的社群 [Trailhead Community](https://trailhead.salesforce.com/en/trailblazercommunity),是一個類似 stackoverflow 的服務,Trailhead 的使用者可以在上面訂閱感興趣的貼文或主題,也可以發問,讓其他有相關經驗的用戶回答,提問者可以選擇最佳答案並投票給他,讓答題者賺取聲望,是一個滿常見的互動方式 另外,Trailhead 還加入了一些遊戲成分,每個用戶有經驗值點數,每個學習主題(module)都有屬於自己的徽章,賺取足夠的經驗點數及徽章,就可以提升到下一個階級 ([Rank](https://trailhead.salesforce.com/en/trailblazer-ranks)) Trailhead 也提供了技能認證的服務,部分基礎的認證有提供免費參與,收費認證的部分有官方背書,這點和 AWS/Google 一樣 --- ## Playground 官方還提供了另一相服務: [Trailhead Playground](https://www.youtube.com/watch?v=teAeQ1Pmpis) Playground 在註冊 Trailhead 帳號時就已經自動建立,可以算是一個單人版 Salesforce platform, 基本功能都相同,Trailhead 的課程相關測驗,有時會需要在 Playground 上執行 > 與 Salesforce Developer Edition 的差異: Developer Edition 比較像是一般開發環境(dev/QA/staging/production)中的 dev 環境,和正式環境相比,具體而微;Playground 就相當於 local 的 container,僅供開發者自己使用,可以隨便亂搞 點擊右上角頭像, Hands-On Orgs > 點選 Launch,就可以進到 Playground 介面   操作上就和一般的 Salesforce platform 一樣,點設定圖示,就可以開啟 Developer Console 進行開發及測試  在 Playground 上還可以安裝額外套件,可能是一些輔助工具或是現成的資料,圖表或互動元件  例如 DreamHouse 套件是一個房地產仲介管理的系統,裡面有 Custom Class 的關聯範例 > SOQL 語法只有 SELECT,也沒有 JOIN,它有自己一套的關聯查詢方法   另外,為了避免環境弄亂,影響任務的 judgement,可以創建多個 playground 例如,可能遇到在前一個任務,更動了 Account table 的 schema,導致在當前任務 insert data 失敗 這時就可以創建一個新的 playground for the current module 創建方法非常簡單,除了可以在前面提到的 hands-on-org page 手動創建,也可以在當前 module 的頁面創建,如下圖:   Trailhead playground 在創建時會隨機產生一組使用者帳號,格式會是: ``` ${使用者}@${隨機字串}.com ``` 這組帳號可以在之後用來手動登入 playground,或是透過 VS Code 遠端開發 --- ## VS Code 整合 Playground Salesforce 可以透過 VS Code 的 extension 遠端開發/部屬 首先要安裝 [Salesforce CLI](https://developer.salesforce.com/tools/sfdxcli) 安裝完後可以下指令確認是否成功: ```shell= sfdx update ``` 接著就到 VS Code 安裝必須的 extension  > Salesforce extensions 需要 JDK 8 or 11,請記得安裝 另一個推薦的 optional extension 是 CLI Integration,可以在 VS Code 透過 F1 執行 Salsforce cli 的命令,非常方便   下一步就是建立一個新的專案,可以透過 CLI extension,選擇 Create Project 接著修改專案中的 `orgName` ,位置在 `config` > `project-scratch-def.json` ```json= { "orgName": "Learning VS Code", "edition": "Developer", "features": ["EnableSetPasswordInApi"], "settings": { "lightningExperienceSettings": { "enableS1DesktopEnabled": true }, "mobileSettings": { "enableS1EncryptedStoragePref2": false } } } ``` > 按照官方教學是命名為 Learning VS Code,可以自行更改 接下來要把這個專案與 Playground 連結 一樣透過 cli 執行命令 `SFDX: Authorize an Org`   這邊會要求輸入一個 Org alias,可以直接 enter,這裡是照範例輸入的 VSCodePlayground 這邊會遇到一個問題,因為 Playground 是系統自動建立的,所以使用者不會知道密碼  解決辦法是,到 Playground,點右上的 Setup > 點左邊的 Users > Users 進去後找到自己的名字,勾選 checkbox,然後點下方的 Rest Password(s)  之後會收到重置密碼的 email,就可以自行設定密碼,用來登入上一步的認證  點選 `Allow` 授權給 VS Code,完成之後就可以透過 VS Code 在 Playground 上開發 簡單的操作,例如建立一個新的 Class:  輸入 Class Name 之後,會問你要把 file 放在哪裡,基本上就放在預設位置就好    開發完之後,可以在左邊的 sidebar 直接將 source code deploy 到你的 playground上  之後到 Playground 打開 Developer Console,點選上方的 File > open 就可以在 Classes 中看到剛剛的 Class  也可以透過 `SFDX: Execute SOQL Query...`  輸入 SOQL 查詢語句  這邊選 Rest API 就可以  查詢成功後就可以在下方的 `Output` 看到結果  個人的使用心得: Salesforce native cloud IDE 使用上來說還是比較方便,畢竟 VS Code 還是必須透過 cli 將本地的檔案 deploy 到遠端,速度上比較慢,而且沒有 UI 可供查看;也許在某些特定情境下,例如要透過 git 作 source code 版控,就會需要用 VS Code 開發 一般情況下,cloud IDE 就可以滿足大部分的需求;另外 Saleseforce 強調 `Low Code`,所以 cloud IDE 也提供很多互動功能幫助 coding,debug tool 也很方便 --- ## Apex 相關 modules 目前找到與 Apex 開發相關的課程: * [Platform API Basics](https://trailhead.salesforce.com/en/content/learn/modules/api_basics): Salesforce Platform API 基本課程,介紹 Salesforce 的四大類型 API 服務 * [Build Apex Coding Skills](https://trailhead.salesforce.com/en/content/learn/trails/build-apex-coding-skills): 提供了 Apex 開發教學,內含4個主題,課程長度約4小時 * [Developer Beginner](https://trailhead.salesforce.com/en/content/learn/trails/force_com_dev_beginner): 完整的基礎開發課程,內容包括但不限於 Apex,課程長度約18小時 * [Developer Intermediate](https://trailhead.salesforce.com/en/content/learn/trails/force_com_dev_intermediate): 進階的開發課程,內含 以及 兩個 Apex modules --- ## Apex 相關影片 2017 官方介紹影片(義大利口音) * [Introduction to Apex Code (1)](https://www.youtube.com/watch?v=wB8afXfnTPQ&t=910s) * [Introduction to Apex Code (2)](https://www.youtube.com/watch?v=26Chs2STdQs) 2020有一系列的影片,較詳細 (印度口音): * [Salesforce Developer Training Series](https://www.youtube.com/watch?v=68X85SxAU1g&list=PLaGX-30v1lh1e8roeCUumUEel5ukdPubj&index=1) 影片中的 slides 可以搭配官方文件一起看: [Apex Developer Guide](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dev_guide.htm) 另外有簡體中文,bilibili 的教學系列,不介意簡中的可以參考看看(影片中 Salesforce 介面是日文) [Salesforce初级培训 68学时(零基础)_哔哩哔哩_bilibili ](https://www.bilibili.com/video/BV1Jq4y197Fb/?spm_id_from=333.788.recommend_more_video.1) 影片內容可以搭配 Trailhead Playground 實作或練習 ###### tags: `Salesforce` `Apex` `Trailhead`
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.