Skip to main content

Creating a coupon dispenser button for Salesforce Accounts

In this tutorial, let's create a coupon dispenser button for our Salesforce Accounts.

Let's create a button in the Account layout that a sales agent can click. The button creates an on-demand coupon and stores it in a custom field of your Accounts.

Creating a custom field on an object

Let's use the Account object:

  1. Click Setup > Customize > Accounts > Fields.
  2. Click New in the Account Custom Fields & Relationships section.
  3. Set Data Type to Text and click Next.
  4. In Field Label, type Coupon (or a label of your choice)
  5. In Length, type 32.
  6. In Field Name, type Coupon. It will be named Coupon__c internally.
  7. Click Next and save the field.

Creating an Apex class

Let's create an Apex class that will talk to the Talon.One API:

  1. Click Setup > Develop > Apex Classes.

  2. Click New and paste the whole example from the Talon.One Apex SDK.

  3. Customize the first line of the NewCouponService() function that is located at the end of the file:

    TalonOneManagementAPI t = new TalonOneManagementAPI(
    'yourdomain', '', 'password', 1, 1
    1. Change yourdomain to your Talon.One subdomain name.
    2. Change password to the sign-in credentials for the Talon.One user that should act as the API user. We recommend you create a Talon.One user for this role.
    3. The last two parameters are the Application ID and the Campaign ID, in that order. You can find these values in Settings > Developer settings in the Campaign Manager after creating an Application and the campaign that should contain your coupons.
  4. Save the class.

Creating a button for the account layout

The button should call the Talon.One Apex Class:

  1. Click Setup > Customize > Accounts > Buttons, Links, and Actions.

  2. Click New Button or Link.

  3. In Label, choose type Create Coupon

  4. In Name field, type Talon_One_Coupon.

  5. In Behaviour, choose Execute JavaScript and OnClick JavaScript as the Content Source.

  6. Paste the following code into the code text field:

    var result = sforce.apex.execute(
    "TalonOneManagementAPI", "NewCouponService", {id:"{!Account.Id}"}

This script does the following:

  • Pass the Account's ID to the NewCouponService function of the TalonOneManagementAPI Apex Class.
  • NewCouponService triggers the Talon.One API to create a new coupon and store it in the Account's custom Coupon__c field.
  • Display the result of the coupon request as an alert.

Saving the button and inserting it into the account layout

  1. Click Setup > Customize > Accounts > Page Layouts > Edit.
  2. Select the Buttons section in the toolbox at the top and drag the Create Coupon button to an appropriate place in your layout.
  3. Save.

You can now create Talon.One coupons directly from Salesforce CRM.