7

Recently started using Salesforce DX. Got a scratch org spun up and pushed some source to it. However I needed to create a new trigger, which I couldn't find a CLI command to do. So I instead created in the UI of the scratch org. Now I'm trying to pull the trigger down to source but can't figure out how to do so.

Questions

  1. Is there a salesforce CLI command to create a trigger (sfdx force:apex:?)
  2. How can I specify from the CLI that I want to pull down this new trigger?
3

Use Source pull command to pull changes you have in your scratch org to your local folder

Note that your scratch org is exact replica of source code you have in your local machine

Check the status using the command below before running pull

sfdx force:source:status

This shows all the changes between local and your org.

Run the below pull command in the project folder


sfdx force:source:pull

I would double check below to make sure I am missing nothing

  1. Am I connected to right scratch org

  2. Am I running this command inside the project folder .

You can see all the orgs listed using the below command

sfdx force:org:list

Looks like force:pull somehow does not bring trigger .

Current work around was to crete a trigger.xml file with file name as of trigger.

Sounds like a major flaw and will wait for comments from product team.

| improve this answer | |
  • 1
    Sorry for not specifying, I've done that and each time I get "No Results Found", essentially indicating no differences from source. But I can confirm I've created the trigger in the scratch org UI. – George Albrecht Oct 20 '17 at 0:36
  • Are you sure you are connected to right scratch org ? I would double check if i am connected to right scratch org and I am running this command inside the project folder . – Mohith Shrivastava Oct 20 '17 at 0:40
  • No Results found makes me feel you are connected to wrong scratch org . – Mohith Shrivastava Oct 20 '17 at 0:45
  • See below, I blanked out some info but I only have one scratch org. I believe I'm connected correctly to it: HQ-2040:agentTerm georgealbrecht$ sfdx force:org:list === Orgs ALIAS USERNAME ORG ID CONNECTED STATUS (D) george.albrecht@xxx.com xxxxx Connected ALIAS SCRATCH ORG NAME USERNAME ORG IDEXPIRATION DATE (U) TermScratchOrg georgealbrecht Company test-xxx@georgealbrecht_company.net xxxx-10-25 – George Albrecht Oct 20 '17 at 0:51
  • 2
    Just added workaround to answer .Tweeted to PM of product to see we get any help here – Mohith Shrivastava Oct 20 '17 at 1:28
2

To answer your first question below is the command to create the trigger from the SFDX CLI:

sfdx force:apex:trigger:create -n mytrigger -s Account -e 'before insert, after upsert' -d <***app-dir***>/main/default/triggers

Visit the below link for more details on the creation of trigger from CLI.

https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_develop_create_trigger.htm

To check the changes b/w the remote and local folder use the below command:

  1. If the current scratch org is your default scratch org:

    sfdx force:source:status
    
  2. If the current scratch org is not your default scratch org:

    sfdx force:source:status -u <Scratch Org Alias Name>
    

You can pull the data from the scratch org to the local folder using the below command:

  1. If the current scratch org is your default scratch org:

    sfdx force:source:pull
    
  2. If the current scratch org is your default scratch org:

    sfdx force:source:pull -u <Scratch Org Alias Name>
    
| improve this answer | |
1

let me start by answering the questions:

  1. while we have implemented some scaffolding as you can see with force:apex:class:create, we have not yet implemented the command for triggers. You can still create the trigger file yourself as long as you follow the conventions.
  2. force:source:pull is the command to run to pull down any changes made on the server side. Triggers are supported and should be working. I'll work to repro this myself and will log a bug to get fixed asap if its reproducible.

In the mean time try creating a new scratch org and pushing the source to the new org. If it works then my guess is the change tracking somehow got out of sync.

| improve this answer | |
1

I confirm the original problem. I have the exact same thing happening. Created a trigger in (the only) scratch org. source:status shows no changes, source:pull (obviously) does nothing.

And I confirmed the workaround. I created a local file, did a source:push. That overwrote the trigger I had created in the scratch org.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.