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:
To modify the resource files on your client machine, install a code editor of your choice.
Note
In this tutorial, we use Visual Studio Code with extensions including Python, Better Jinja, and YAML. You may complete this tutorial using your preferred editor.
Job devlopment
Access the learn_sw folder created in Tutorial: Integrate a project with Github.
Copy the file job_sfdc_get_object_data.yaml and rename the copied file to job_sfdc_search.yaml.
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.
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
Create a new file in the same directory and name it test.j2.
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
Test this template as the endpoint component for the job.
sw test job sfdc_search endpoint test.j2 -c learn_dev -l
Update the job_sfdc_search.yaml file and replace the existing endpoint value with the code snippet tested in test.j2.
Re-run the import command to refresh the job with the latest updates.
sw import job sfdc_search -c learn_dev -l
Run the command below to preview the web request:
sw preview sfdc_search -c learn_dev
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
Run the following command to build the job.
sw build sfdc_search -c learn_dev
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
Create a file named macro_lib_generate_ddl_script.yaml with the content specified below:
macros: ' ' test: ' '
Run the following command to create a new macro library using the file
sw import macro_lib generate_ddl_script -c learn_dev -l
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 %}
Create a file named test_lib.j2 with the content specified below:
{{ create_simple_table('table1,table2,table3') }}
Run the following command to test the files:
sw test lib generate_ddl_script lib.j2 test_lib.j2 -c learn_dev -l
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.
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
Run the command below to test the updated macro library.
sw test lib generate_ddl_script -c learn_dev
Function development
Create a file named function_hello.yaml with the content specified below:
definition: |- def hello(): pass test: ' '
Run the following command to create a new function using the file.
sw import function hello -c learn_dev -l
Create a file named def.py with the content specified below:
def hello(name): return f'hello {name}!'
Create a file named test_func.j2 with the content specified below:
{{ hello('world') }}
Run the following command to test the files:
sw test func hello def.py test_func.j2 -c learn_dev -l
Update the file function_hello.yaml and replace the existing values for definition and test with the corresponding code snippets from the tested files.
Re-run the import command to refresh the function with the latest updates.
sw import function hello -c learn_dev -l
Run the command below to test the updated function.
sw test func hello -c learn_dev