Skip to main content
The Trailblazer Community will be undergoing scheduled maintenance from 8:40 PM PDT on Wednesday, September 30 to 3:00 AM PDT on Thursday, October 1, 2026. During this window, the site will be unavailable.

Fetch Opportunity Data

Learning Objectives

After completing this unit, you’ll be able to:

  • Create a context definition.
  • Add attributes and tags for a context definition.
  • Configure context mapping for a context definition.

Sign Up for a Developer Edition Org with Business Rules Engine and Context Service

To complete this module, you need a special Developer Edition org that contains Business Rules Engine, Context Service, and our sample data. Get the free Developer Edition org and connect it to Trailhead now so you can complete the challenges in this module. Note that this Developer Edition org is designed to work with the challenges in this badge, and might not work for other badges. Always check that you’re using the Trailhead Playground or special Developer Edition org that we recommend.

  1. Sign up for a free Developer Edition org with Business Rules Engine and Context Service.
  2. Fill out the form:
    • For Email, enter an active email address.
    • For Username, enter a username that looks like an email address and is unique, but it doesn't need to be a valid email account (for example, yourname@example.com).
  3. After you fill out the form, select Sign me up. A confirmation message appears.
  4. When you receive the activation email (this can take a few minutes), open it and select Verify Account.
  5. Complete your registration by setting your password and challenge question.
    Tip: Save your username, password, and login URL in a secure place—such as a password manager—for easy access later.
  6. You're logged in to your Developer Edition.

Now, connect your new Developer Edition org to Trailhead.

  1. Make sure you’re logged in to your Trailhead account.
  2. In the Challenge section at the bottom of this page, select the org name and then select Connect Org.
  3. On the login screen, enter the username and password for the Developer Edition org you just set up.
  4. On the Allow Access? screen, select Allow.
  5. On the Want to connect this org for hands-on challenges? screen, select Yes! Save it. You’re redirected back to the challenge page and ready to use your new Developer Edition to earn this badge.

Note

This badge uses USD as the currency for the examples and hands-on challenges. Your Developer Edition org’s currency depends on the country and postal code you select on the sign-up page.

Create a Context Definition

In the previous unit, you learned about the requirements for the example scenario. Now, it’s time to build your solution. Start by building a context structure using a context definition that includes Nodes, Attributes, and Tags that you use to fetch opportunity data.

First, create your context definition.

  1. From Setup, in the Quick Find box, enter Context Definitions, and then select Context Definitions.
  2. Select New.
  3. In the Create Context Definition window, for Name, enter SalesTransaction.
  4. Select Next.
  5. In the Add Nodes section, enter Opportunity as the node name.
  6. Select Next.

Now, you can configure the context definition.

Add Attributes and Tags

Next, add attributes to the Opportunity node.

  1. In the Create Context Definition window, select Add Attributes.
  2. Provide these attribute details.
    • Name: AccountId
    • Type: INPUT
    • Data Type: STRING
  3. Similarly, add these attributes and select Next.

Name

Type

Data Type

OpportunityAmount

INPUT OUTPUT

CURRENCY

AccountRating

INPUT OUTPUT

PICKLIST

CalculatedDiscount

INPUT OUTPUT

PERCENT

RiskStatus

INPUT OUTPUT

STRING

Next, add tags to the node and each attribute.

  1. In the Create Context Definition window, for the Opportunity node, select + Add Tags.
  2. For the tag name, enter Opportunity.
  3. Select Done.
  4. Similarly, add tag names for each of these attributes, and save your work

Attribute Name

Tags

RiskStatus

Opportunity_RiskStatus

CalculatedDiscount

Opportunity_CalculatedDiscount

AccountRating

AccountRating

OpportunityAmount

OpportunityAmount

AccountId

Opportunity_AccountId

Your context definition with the context structure is ready.

Add Context Mapping

Next, map the nodes and attributes with the Opportunity object and its fields respectively.

  1. In the Context Definitions setup page, select the Custom Definitions tab.
  2. Select SalesTransaction.
  3. Select the Map Data tab.
  4. Select Add Mapping and specify these details in the Add Context Mapping window.
    • Name: ContextMap
    • Select Mark as Default.
  5. Select Next and then Map. The context mapping page opens in a new tab.

The attributes are listed for each node. Next, connect the objects for each node and the fields with each attribute.

  1. In the Context Mapping page, under the Object Mapping tab, select Select Object.
  2. In the Salesforce Objects window, find and select Opportunity.
  3. Save your work.
  4. For the RiskStatus attribute, select Select Fields in the Field section, then find and select Risk_Status__c.
  5. Save your work.
  6. Similarly map these attributes and fields, and save your changes.

Attributes

Fields

CalculatedDiscount

Calculated_Discount__c

OpportunityAmount

Amount

AccountId

AccountId

Mapping the AccountRating attribute is slightly different. You map the AccountRating attribute to the Rating field, which is available in the Account object. But you perform this mapping through the Opportunity object. You use the AccountId lookup field to find the Rating field and complete the mapping. Here’s how you do it.

  1. In the Context Mapping page, for the AccountRating attribute, select Select Fields in the Field section.
  2. Select Additional options beside the AccountId field and then find and select Rating.
  3. Save your changes.
  4. In the Context Mapping page, select Save to save your mapping.

The Context Mapping page showing the mappings between nodes and objects, and attributes and fields.

  1. In the Context Mapping page, select Back to go back to the SalesTransaction context definition.
  2. Select Activate.
Note

In the Context Mapping page, if you’re unable to see the full list of mapping attributes and fields, reduce your browser zoom to 90% or less.

Your context mapping is complete and your context definition is now available for use in Business Rules Engine.

What’s Next?

In this unit, you created a context definition to build a context structure that includes nodes, attributes, and tags. You also created a context mapping to map the nodes with objects and attributes with fields. This gives you the data to calculate opportunity discounts and ensure compliance.

In the next unit, you create a decision table to calculate the base discount. You also create an expression set to configure a rule to calculate opportunity discount and risk status.

Resources

Comparta sus comentarios de Trailhead en la Ayuda de Salesforce.

Nos encantaría saber más sobre su experiencia con Trailhead. Ahora puede acceder al nuevo formulario de comentarios en cualquier momento en el sitio de Ayuda de Salesforce.

Más información Continuar a Compartir comentarios