> For the complete documentation index, see [llms.txt](https://support.attackforge.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://support.attackforge.com/attackforge-enterprise/modules/flows/salesforce.md).

# Salesforce

## Create Salesforce Opportunity

{% embed url="<https://youtu.be/15KbJKPVrtM?si=OnfvPpcM9jDG1v2F>" %}

The purpose of this example is to create a [Salesforce Opportunity](https://help.salesforce.com/s/articleView?id=sales.opportunities.htm\&type=5) when a Project is requested in AttackForge.

This example Flow can be downloaded from our [Flows GitHub Repository](https://github.com/AttackForge/Flows) and [imported](#importing-exporting-flows) into your AttackForge.

**Initial Set Up**

* **Event**: Project Requested
* **Secrets**:
  * sf\_client\_id - your [Salesforce OAuth Client Id](https://help.salesforce.com/s/articleView?id=xcloud.remoteaccess_oauth_flows.htm\&type=5)
  * sf\_client\_secret - your [Salesforce OAuth Client Secret](https://help.salesforce.com/s/articleView?id=xcloud.remoteaccess_oauth_flows.htm\&type=5)
  * sf\_password - Your [Salesforce User Password](https://help.salesforce.com/s/articleView?id=xcloud.remoteaccess_oauth_flows.htm\&type=5)
  * sf\_username - Your [SalesForce Username](https://help.salesforce.com/s/articleView?id=xcloud.remoteaccess_oauth_flows.htm\&type=5)

**Action 1 - Get Salesforce OAuth Token**

* **Method**: POST
* **URL**: <https://login.salesforce.com/services/oauth2/token>
* **Headers**:
  * Key = Content-Type; Type = Value; Value = application/x-www-form-urlencoded
* **Request Script**:

```javascript
return {
  request: {
    body: 'grant_type=password&client_id=' + secrets.sf_client_id + '&client_secret=' + secrets.sf_client_secret + '&username=' + secrets.sf_username + '&password=' + secrets.sf_password
  }, 
  data: {
    project_request: data
  } 
};
```

* **Response Script**:

```javascript
let body;

if (response.headers['Content-Type'] === 'application/json;charset=UTF-8') {
  body = JSON.parse(response.body);
}
else {
  return {
    decision: {
      status: 'abort',
      message: 'Content-Type is expected to be application/json;charset=UTF-8'
    }
  };
}

if (body?.access_token) {
  return {
    data: {
      project_request: data.project_request,
      sf_access_token: body.access_token
    }  
  };
}
else {
  return {
    decision: {  
      status: 'abort',
      message: 'Salesforce access token not found'
    }
  };
}
```

**Action 2 - Create Salesforce Opportunity**

* **Method**: POST
* **URL**: https\://\<YOUR-SALESFORCE>/services/data/v63.0/sobjects/Opportunity
* **Headers**:
  * Key = Content-Type; Type = Value; Value = application/json
* **Request Script**:

```javascript
if (data?.project_request && data?.sf_access_token) {
  let closeDate = '2030-12-31';
  
  if (data.project_request.project_request_end_date) {
    closeDate = String.slice(data.project_request.project_request_end_date, 0, 10);
  }

  return {
    request: {
      headers: {
        'Authorization': 'Bearer ' + data.sf_access_token
      },
      body: {
        'Name': data.project_request.project_request_name,
        'StageName': 'Needs Analysis',
        'CloseDate': closeDate
      }
    }
  };
}
else {
  return {
    decision: {  
      status: 'abort',
      message: 'Salesforce access token not found'
    }
  };
}
```

* **Response Script**:

```javascript
let body;

if (response.headers['Content-Type'] === 'application/json;charset=UTF-8') {
  body = JSON.parse(response.body);
}
else {
  return {
    decision: {
      status: 'abort',
      message: 'Content-Type is expected to be application/json;charset=UTF-8'
    }
  };
}

if (response.statusCode === 201 && body?.id && body.success === true) {
  return {
    decision: 'finish'
  };
}
else {
  return {
    decision: {  
      status: 'abort',
      message: 'Salesforce Opportunity not created'
    }
  };
}
```


---

# 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://support.attackforge.com/attackforge-enterprise/modules/flows/salesforce.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.
