> For the complete documentation index, see [llms.txt](https://docs.edgetag.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.edgetag.io/channels/webhook/templates/salesforce-lead-and-opportunity.md).

# Salesforce - Lead & Opportunity

### Objective

* **Fetch/Create/Update Lead** from customer data
* Create an **Opportunity** linked to the **Lead**
* Build and send the relevant payload via **EdgeTag**

### EdgeTag Salesforce Integration - Deployment & Salesforce Setup

This guide will help you set up and validate the EdgeTag integration with Salesforce and deploy it using EdgeTag's Webhook.

### **Salesforce Configuration**

1. **Create a Salesforce Connected App**
   1. Navigate to **Setup**:
      * Go to **App Manager** (under Setup).
      * Click **New Connected App**.
      * If not visible: Go to **Apps -> External Client Apps -> Settings -> Connected Apps**, then click **New Connected App**.
   2. Configure Your App:
      * Name: **EdgeTag Integration** (API Name auto-fills).
      * Enable OAuth Settings.
      * Callback URL: `https://localhost:3000/callback`
      * Selected OAuth Scopes:
        * Manage user data via APIs (`api`)
        * Perform requests on your behalf at any time (`refresh_token, offline_access`)
      * Edit OAuth Policies:
        * Permitted Users: Admin approved users are pre-authorized.
        * IP Relaxation: Relax IP restrictions (if needed).
        * Uncheck **Require Proof Key for Code Exchange (PKCE)**.
      * Save the `Connected App`.
      * Copy Credentials:
        * In the app detail page, click **Manage Consumer Details** and copy:
        * Consumer Key
        * Consumer Secret
2. **Add a Custom Lookup Field to Opportunity**
   * Go to: **Setup -> Object Manager -> Opportunity -> Fields & Relationships-> New**.
   * Choose: Data Type: **Lookup Relationship**, Related To: **Lead Reference**.
   * Enter:
     * Field Label: **Lead Reference**
     * Field Name: **LeadReference\_\_c**
   * Complete: Follow the wizard steps, and add the field to your Opportunity Page Layout(s).
3. **Generate a Salesforce Refresh Token via OAuth**
   * Authorize in Browser:

     Replace `CONSUMER_CLIENT_ID` in the URL below and paste in your browser:

     Code SnippetCopy
   * Approve the App: After approval, you'll be redirected to a URL like:

     Code SnippetCopy

     Extract the `code` parameter from the URL.
   * Exchange Code for Tokens:

     Use Postman or cURL to send:

     Code SnippetCopy

     Example cURL:

     Code SnippetCopy

     Copy the `refresh_token` from the response.
4. **Gather Credentials**
   * Save these values for later use in EdgeTag setup:
   * SF\_CLIENT\_ID = your Connected App Consumer Key\
     SF\_CLIENT\_SECRET = your Connected App Consumer Secret\
     SF\_REFRESH\_TOKEN = refresh token from OAuth process

### **EdgeTag Deployment**

1. **Access Your EdgeTag Project**
   * Log in at [app.edgetag.io](https://app.edgetag.io/).
   * Select your site (e.g., `hgtmv.bvnk.com`).
   * To add the Salesforce webhook: Click **Add Channel -> Webhook**.
2. **Configure Webhook Integration**
   * Consent Categories: Ensure at least **Strictly necessary** is enabled.
   * Webhook Name: e.g., **SF Lead & Opportunity**.
   * Webhook URL: Leave blank (EdgeTag will auto-generate).
   * Starter Template: Choose **Salesforce - Lead & Opportunity**
3. **Set Secrets**
   * In the secrets, set:
   * **SF\_CLIENT\_ID** = your consumer key
   * **SF\_CLIENT\_SECRET** = your consumer secret
   * **SF\_REFRESH\_TOKEN** = your refresh token
4. **Deploy**
   * Click **Save & Deploy** (top right). EdgeTag will compile and activate the webhook.

### **Validation & Testing**

* Send a test lead: Use [Shopify Order Created](https://shopify.dev/docs/api/webhooks?accordionItem=webhooks-orders-create\&reference=toml) payload.
* EdgeTag Logs: Make sure the script runs without exceptions.
* In Salesforce:
  * Verify the Lead record is created or updated for the customer email.
  * Confirm an associated Opportunity named `Order <orderId>` was created and is linked to the Lead.
* If you observe errors, contact the EdgeTag team.

### **Result**

The script will create or update the Lead in Salesforce and create an Opportunity with the Lead referenced (`LeadReference__c`).

<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.edgetag.io/channels/webhook/templates/salesforce-lead-and-opportunity.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
