---
title: "sfdcCreateOpportunity"
canonical: "https://support.appfire.com/space/PSJ/15482738/sfdcCreateOpportunity"
format: markdown
---
> Macro (aura-html)


# Syntax

**<span style="color: #3366ff">sfdcCreateOpportunity(sfdcConnection, sfdcOpportunity, [sfdcAPIVersion])</span>**

## Description

> Macro (excerpt)
> 
> Creates an opportunity in the Salesforce environment.

##   
<span style="color: #bd5528">Parameters</span>

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| sfdcConnection | [SFDCConnection](https://appfire.atlassian.net/wiki/spaces/PSJ/pages/15482612) | Yes | Salesforce connection - it is the object resulted from the call to the **connectToSalesforce** function |
| sfdcOpportunity | [SFDCOpportunity](https://appfire.atlassian.net/wiki/spaces/PSJ/pages/15482806) | Yes | Structure containing the [fields](#SFDCOpportunity fields and types) of the opportunity that will be created. This is a predefined structure type described below. When creating an opportunity, there are three required fields that must have values: **Name**, **CloseDate**, and **StageName**. |
| sfdcAPIVersion | string | No | The Salesforce API version to be called when creating the opportunity, it should have the following form: "vXX.X" - eg: "v43.0", "v42.0".   
It is not required and if empty, the latest available version will be used. |

  


### SFDCOpportunity fields and types

> ⚠️ **Note**
> ⚠️ 
> ⚠️ **CloseDate**, **Name**, and **StageName **attributes are required when creating a new [SFDCOpportunity](https://appfire.atlassian.net/wiki/spaces/PSJ/pages/15482806) type. See [SFDCOpportunity](https://appfire.atlassian.net/wiki/spaces/PSJ/pages/15482806) for more details.

##   
Return type

string - the Salesforce Opportunity ID

## Example

The following example will create an opportunity in Salesforce with the specified fields.

```
SFDCConnection conn = connectToSalesforce("SFDC_test");
logPrint("WARN", "Connected to SF: " + conn.instance_url + " - " + conn.access_token);

SFDCOpportunity opp;
opp.Name = "Test Opp using function";
opp.CloseDate = currentDate();
opp.StageName = "Prospecting";

string oppId = sfdcCreateOpportunity(conn, opp, "v43.0");

logPrint("WARN", "Created opportunity with id: " + oppId);
```

## See also

> Macro (contentbylabel)