> ## Documentation Index
> Fetch the complete documentation index at: https://docs.refold.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Write Data to 3rd Party App

> Create a sample workflow to create new data in Salesforce using Events

Consider a use-case where you want to create a contact present in your system to Salesforce.

This workflow will be fired when you send an Event with the payload of the contact to be added.

In the Salesforce integration, go to `Workflows` and create a new workflow by clicking on `+Add Workflow` button and name it as `Create New Contact`.

## Building Workflow

Follow the steps given to build the workflow:

<Steps>
  <Step title="Add Trigger in Start Node">
    All workflows start with a trigger, which determines when the workflow will run and how data is passed into the workflow.
    For this workflow we will use the Event Based trigger.

    <Tip>
      Learn more about the triggers and its types [here](https://docs.gocobalt.io/build/workflow/triggering_workflow).
    </Tip>

    Click on the `Start Node`, select your native app option and click on `+ Create New Event`.

    <img height="200" src="https://mintcdn.com/cobalt-55/C3P12YsraPVmMY5N/images/Examples/salesforce/event_salesforce_add.png?fit=max&auto=format&n=C3P12YsraPVmMY5N&q=85&s=e9bc9cf0ad229b19ee6518b8d29cee85" alt="Event for workflow" data-path="images/Examples/salesforce/event_salesforce_add.png" />

    Give a name to your event and provide all the data related to the contact in the payload.
  </Step>

  <Step title="Add Salesforce Node">
    Now to create a new contact in Salesforce, we need to call Salesforce API.

    Click on `Nodes` option in the top right and drag the Salesforce Node from **Native Apps** section to the workflow builder. Connect this node with Start Node.
  </Step>

  <Step title="Add Action in node">
    Click on Salesforce Node and add the `Create Contact` action.
    To provide the data in all the fields from your Event payload, just click on a field and from the **Event** tab under Insert Variable, select the fields from the body that you sent as payload.

    <img height="200" src="https://mintcdn.com/cobalt-55/C3P12YsraPVmMY5N/images/Examples/salesforce/create_salesforce.png?fit=max&auto=format&n=C3P12YsraPVmMY5N&q=85&s=a8b48b74b14597322168c2559b4872c6" alt="Create Contact action" data-path="images/Examples/salesforce/create_salesforce.png" />

    <Warning>
      Ensure that all the mandatory fields in the action are filled, else the Salesforce API will give error.
    </Warning>
  </Step>
</Steps>

And done, you can now successfully create a contact in Salesforce whenever the event is triggered.

<Tip>
  Refer to the Trigger Event API [here](https://docs.gocobalt.io/api-reference/event/trigger-event) to fire the event and workflow.
</Tip>

## Test Workflow

Once your workflow is built, you can perform both node level and workflow level testing to check it.

Before testing a workflow, ensure the following pre-requisites are completed:

* Linked Account configured with authentication completed with the integration.
* Sample Payload for testing is available & configured.

<Tip>
  Learn in depth how you can configure the pre-requisites in our Workflow Testing guide [here](https://docs.gocobalt.io/build/workflow/workflow_testing#pre-requisites-for-workflow-testing).
</Tip>

Based on the type of testing that you want to perform, follow the steps below:

#### Testing Node

<Steps>
  <Step title="Select Node">
    Click on the node you want to test.
  </Step>

  <Step title="Run Node">
    In the node, switch to `Input/Output` tab and click on `Run Node` button.
    <Warning>Testing for Group Node and Pagination is currently not supported.</Warning>

    <img height="200" src="https://mintcdn.com/cobalt-55/rCTCKBbhiwGPdeWb/images/implementation/node_output.png?fit=max&auto=format&n=rCTCKBbhiwGPdeWb&q=85&s=f16568a7b9d8d57df6cd2f4fb60ee9d7" alt="Checking Input and Output of Test execution" data-path="images/implementation/node_output.png" />
  </Step>
</Steps>

<Check>Once the node executes successfully, a checkmark appears on the node, indicating it has been tested.</Check>

#### Testing Entire Workflow

Open the testing modal present at the bottom.

Click on `Run Workflow` button to perform a test execution and a **Test Run** log is generated with output of each node.
<Warning>Since testing for Group nodes is not supported currently, you might not receive the logs of the group node.</Warning>

<img height="200" src="https://mintcdn.com/cobalt-55/rCTCKBbhiwGPdeWb/images/implementation/workflow_output.png?fit=max&auto=format&n=rCTCKBbhiwGPdeWb&q=85&s=0ee856c94f445d4aea0f0218ed39173e" alt="Checking Output of Workflow Test run" data-path="images/implementation/workflow_output.png" />

Once you are satisfied with the testing results, you can close the testing modal and move to the next steps for implementation.

<Check>
  Hurray!!

  You have successfully created and tested a Salesforce workflow to create a new contact.
</Check>
