turbot/salesforce
steampipe plugin install salesforce

Table: salesforce_opportunity - Query Salesforce Opportunities using SQL

Salesforce Opportunity is a component of Salesforce Sales Cloud that allows businesses to manage their sales cycles and deals. It provides a way to track and measure potential revenue, and monitor sales stages, from prospecting to closing. Salesforce Opportunity is instrumental in understanding a company's sales pipeline and forecasting sales.

Table Usage Guide

The salesforce_opportunity table provides insights into Opportunities within Salesforce Sales Cloud. As a sales manager or data analyst, explore opportunity-specific details through this table, including deal value, expected close date, and associated account details. Utilize it to uncover information about sales performance, such as deals in the pipeline, the value of potential revenue, and the progress of deals through sales stages.

Important Notes

  • If the naming_convention configuration argument is set to api_native, please see API Native Examples.

Examples

Basic info

Gain insights into your sales opportunities by sorting them based on their stage in the sales process. This helps prioritize opportunities that are closer to closing, improving sales efficiency and forecasting.

select
id,
name,
amount,
type,
stage_name,
forecast_category,
is_won
from
salesforce_opportunity
order by
stage_name;
select
id,
name,
amount,
type,
stage_name,
forecast_category,
is_won
from
salesforce_opportunity
order by
stage_name;

List only won opportunities

Explore which sales opportunities have been successful to understand the areas of high revenue generation. This can help in strategizing future sales approaches.

select
id,
name,
amount,
type,
is_won
from
salesforce_opportunity
where
is_won
order by
amount;
select
id,
name,
amount,
type,
is_won
from
salesforce_opportunity
where
is_won
order by
amount;

List number of opportunities with respective stage

Determine the distribution of sales opportunities across different stages. This can help you understand where most of your opportunities are concentrated, allowing you to strategize and allocate resources effectively.

select
count(*),
stage_name
from
salesforce_opportunity
group by
stage_name;
select
count(*),
stage_name
from
salesforce_opportunity
group by
stage_name;

API Native Examples

If the naming_convention config argument is set to api_native, the table and column names will match Salesforce naming conventions.

Basic info (with API Native naming convention)

Explore the opportunities in your pipeline, focusing on their names, amounts, types, and forecast categories, to gain insights into their stages. This is useful for understanding the distribution and potential value of your opportunities, which can inform your sales strategy and prioritization.

select
"ID",
"Name",
"Amount",
"Type",
"StageName",
"ForecastCategory"
from
"Opportunity"
order by
"StageName";
select
"ID",
"Name",
"Amount",
"Type",
"StageName",
"ForecastCategory"
from
"Opportunity"
order by
"StageName";

List only won opportunities (with API Native naming convention)

Discover the segments that have been successful by identifying instances where opportunities have been won. This can help assess the elements within these successful opportunities to strategize for future prospects.

select
"ID",
"Name",
"Amount",
"Type",
"StageName",
"ForecastCategory",
"IsWon"
from
"Opportunity"
where
"IsWon"
order by
"Amount";
select
"ID",
"Name",
"Amount",
"Type",
"StageName",
"ForecastCategory",
"IsWon"
from
"Opportunity"
where
"IsWon"
order by
"Amount";

List closed opportunities

Explore which business opportunities have already reached their close date. This can help in assessing past performance and strategizing for future opportunities.

select
"ID",
"Name",
"Amount",
"Type",
"StageName",
"ForecastCategory"
from
"Opportunity"
where
"CloseDate" <= now();
select
"ID",
"Name",
"Amount",
"Type",
"StageName",
"ForecastCategory"
from
"Opportunity"
where
"CloseDate" <= datetime('now');

List opportunities with open activity

Explore which opportunities have an open activity to determine areas for potential business growth. This can help in identifying instances where immediate action is required, aiding in effective decision making.

select
"ID",
"Name",
"Amount",
"Type",
"StageName",
"ForecastCategory"
from
"Opportunity"
where
"HasOpenActivity";
select
"ID",
"Name",
"Amount",
"Type",
"StageName",
"ForecastCategory"
from
"Opportunity"
where
"HasOpenActivity";

Schema for salesforce_opportunity

NameTypeOperatorsDescription
_ctxjsonbSteampipe context in JSON form, e.g. connection_name.
account_idtextID of the account associated with this opportunity.
amountdouble precisionEstimated total sale amount. For opportunities with products, the amount is the sum of the related products.
campaign_idtextID of a related Campaign. This field is defined only for those organizations that have the campaign feature Campaigns enabled.
close_datetimestamp with time zoneDate when the opportunity is expected to close.
created_by_idtextId of the user who created the opportunity.
created_datetimestamp with time zoneThe creation date and time of the opportunity.
descriptiontextDescription of the opportunity.
expected_revenuedouble precisionCalculated revenue based on the Amount and Probability fields.
fiscal_quarterbigintRepresents the fiscal quarter. Valid values are 1, 2, 3, or 4.
fiscal_yearbigintRepresents the fiscal year, for example, 2006.
forecast_categorytextForecast category name displayed in reports, opportunity detail and edit pages, opportunity searches, and opportunity list views.
forecast_category_nametextName of the forecast category.
has_open_activitybooleanIndicates whether an opportunity has an open event or task (true) or not (false).
has_opportunity_line_itembooleanIndicates whether the opportunity has associated line items. A value of true means that Opportunity line items have been created for the opportunity.
has_overdue_taskbooleanIndicates whether an opportunity has an overdue task (true) or not (false).
idtextUnique identifier of the opportunity in Salesforce.
is_closedbooleanIndicates that the opportunity is closed.
is_deletedbooleanIndicates that the opportunity is deleted.
is_privatebooleanIndicates that the opportunity is private.
is_wonbooleanIndicates that the quote or proposal has been signed or electronically accepted.
last_activity_datetimestamp with time zoneValue is one of the following, whichever is the most recent of a) Due date of the most recent event logged against the record or b) Due date of the most recently closed task associated with the record.
last_modified_by_idtextThe id of the user who last modified the oppurtinity record.
last_modified_datetimestamp with time zoneThe data and time of the last modification of the oppurtinity record.
lead_sourcetextSource of this opportunity, such as Advertisement or Trade Show.
nametextA name for this opportunity.
next_steptextDescription of next task in closing opportunity.
owner_idtextID of the User who has been assigned to work this opportunity.
pricebook_2_idtextID of a related Pricebook2 object. The Pricebook2Id field indicates which Pricebook2 applies to this opportunity. The Pricebook2Id field is defined only for those organizations that have products enabled as a feature.
probabilitydouble precisionPercentage of estimated confidence in closing the opportunity.
stage_nametextCurrent stage of opportunity.
system_modstamptextThe date and time when opportunity was last modified by a user or by an automated process.
total_opportunity_quantitytextNumber of items included in this opportunity. Used in quantity-based forecasting.
typetextType of opportunity, such as Existing Business or New Business.

Export

This table is available as a standalone Exporter CLI. Steampipe exporters are stand-alone binaries that allow you to extract data using Steampipe plugins without a database.

You can download the tarball for your platform from the Releases page, but it is simplest to install them with the steampipe_export_installer.sh script:

/bin/sh -c "$(curl -fsSL https://steampipe.io/install/export.sh)" -- salesforce

You can pass the configuration to the command with the --config argument:

steampipe_export_salesforce --config '<your_config>' salesforce_opportunity