Tutorial: Job development using a client machine

This tutorial provides step-by-step instructions for creating and developing jobs and other project resources using a client machine.

Prerequisites

Before continuing with this tutorial, ensure you have completed the following prerequisites:

Job devlopment

  1. Access the learn_sw folder created in Tutorial: Integrate a project with Github.

  2. Copy the file job_sfdc_get_object_data.yaml and rename the copied file to job_sfdc_search.yaml.

  3. Remove the id variable and include the following variable in the configuration file:

    - name: search_string
      type: text
      value: sForce
    

    Ensure that indentations are correctly aligned, especially if your editor does not automatically validate YAML syntax.

    ../_images/0.png
  4. To create a new job in the LEARN_DEV project using the updated resource file, execute the following Bash command:

    sw import job sfdc_search -c learn_dev -l
    
    ../_images/115.png
  5. Create a new file in the same directory and name it test.j2.

  6. Insert the following code snippet into the file:

    https://{{_proj.sfdc_account}}.my.salesforce.com/services/data/v61.0/search/?q=FIND+%7B{{_vars.search_string}}%7D
    
    ../_images/26.png
  7. Test this template as the endpoint component for the job.

    sw test job sfdc_search endpoint test.j2 -c learn_dev -l
    
    ../_images/34.png
  8. Update the job_sfdc_search.yaml file and replace the existing endpoint value with the code snippet tested in test.j2.

    ../_images/46.png
  9. Re-run the import command to refresh the job with the latest updates.

    sw import job sfdc_search -c learn_dev -l
    
  10. Run the command below to preview the web request:

    sw preview sfdc_search -c learn_dev
    
  11. Run the command below to make a test call. The call will return the references of the matched objects.

    sw testcall sfdc_search -c learn_dev
    
    ../_images/55.png
  12. Run the following command to build the job.

    sw build sfdc_search -c learn_dev
    
  13. The changes are now ready for commit and push to GitHub.

Hint

To ensure correct configuration, avoid creating jobs from scratch locally unless you have a thorough understanding of the resoruce properties and values. Instead, use the following methods for job creation:

  • Use the project console to create a draft job and export it as a file by using Snoweaver CLI.

  • Copy the YAML file of an existing job and edit it locally.

Macro library development

  1. Create a file named macro_lib_generate_ddl_script.yaml with the content specified below:

    macros: ' '
    test: ' '
    
    ../_images/62.png
  2. Run the following command to create a new macro library using the file

    sw import macro_lib generate_ddl_script -c learn_dev -l
    
  3. Create a file named lib.j2 with the content specified below:

    {% macro create_simple_table(names) -%}
    {% for t in names.split(',') -%}
       CREATE TABLE IF NOT EXISTS "{{t}}"(ID INT, DATA VARIANT);
    {% endfor %}
    {%- endmacro %}
    
  4. Create a file named test_lib.j2 with the content specified below:

    {{ create_simple_table('table1,table2,table3') }}
    
  5. Run the following command to test the files:

    sw test lib generate_ddl_script lib.j2 test_lib.j2 -c learn_dev -l
    
    ../_images/75.png
  6. Update the file macro_lib_generate_ddl_script.yaml and replace the existing values for macros and test with the corresponding code snippets from the tested files.

    ../_images/7a.png
  7. Re-run the import command to refresh the macro library with the latest updates.

    sw import macro_lib generate_ddl_script -c learn_dev -l
    
  8. Run the command below to test the updated macro library.

    sw test lib generate_ddl_script -c learn_dev
    

Function development

  1. Create a file named function_hello.yaml with the content specified below:

    definition: |-
      def hello():
          pass
    test: ' '
    
  2. Run the following command to create a new function using the file.

    sw import function hello -c learn_dev -l
    
  3. Create a file named def.py with the content specified below:

    def hello(name):
        return f'hello {name}!'
    
  4. Create a file named test_func.j2 with the content specified below:

    {{ hello('world') }}
    
  5. Run the following command to test the files:

    sw test func hello def.py test_func.j2 -c learn_dev -l
    
    ../_images/85.png
  6. Update the file function_hello.yaml and replace the existing values for definition and test with the corresponding code snippets from the tested files.

    ../_images/94.png
  7. Re-run the import command to refresh the function with the latest updates.

    sw import function hello -c learn_dev -l
    
  8. Run the command below to test the updated function.

    sw test func hello -c learn_dev