Campaign Item Amount Calculation API

In order to use the Campaign Item Calculation API, your Salesforce Org needs to have API usage activated through having an API usage license as well as having the finance module activated with the finance license.

The Campaign Item Calculation API is implemented as Apex class and is exposed as REST web service by using Salesforce standard functionality (see Apex Developer Guide for more information). For general information about the Campaign Item calculations, see . The Campaign Item Calculation functionality calculates the net and gross amounts (B3-N3) and also calculates values in package Campaign Items.

REST web service

URL

https://<my-domain-name>.my.salesforce.com/services/apexrest/ADvendio/ADvendio__Campaign_Item__c/DoCalculations/

Method

PATCH

URL Params

  •  

Data Params

A JSON object with the attribute campaignItems, containing a JSON serialized list of Campaign Items.

Example: { "campaignItems":[{<Campaign Item>}, ...]}

Success Response

Code: 200

Content: A JSON serialized list of the Campaign Items from the request body, but now with updated packages and amount fields.

Example: [{<Campaign Item>}, ...]

Error Response

See Salesforce Apex REST Documentation

Logic

Amount Calculation

The Campaign Item amounts are calculated by using the Sales Price, the Quantity and the Frequency with all the surcharge and discount fields.

Package Calculations

Fields calculated

The following fields are calculated by either the amount calculation or the package calculation:

Sales_Price__c, SurchargeSalesPrice__c, SurchargeSalesPricePct__c, Quantity__c, Frequency__c, Amount_B3APEX__c, SurchargeB3__c, SurchargeB3Abs__c, Amount_B2APEX__c, SurchargeB2__c, SurchargeB2Abs__c, AmountAPEX__c, RateDiscount1AbsCustom__c, Quantity_Discount_custom__c, RateDiscount2AbsCustom__c, Rate_Discount_2_custom__c, RateDiscount3AbsCustom__c, Rate_Discount_3_custom__c, RateDiscount4AbsCustom__c, Rate_Discount_4__c, Amount_netAPEX__c, AC__c, Agency_Commission__c, Amount_net_netAPEX__c, ThirdPartyCommissionCustom__c, Amount_net3APEX__c, from_Date__c, until_Date__c, Guaranteed_AI__c, VatAmount__c, VatAmountB__c, AgencyEarnings__c, RateDiscount1Abs__c, RateDiscount2Abs__c, RateDiscount3Abs__c, RateDiscount4Abs__c, ThirdPartyCommissionAbs__c

Examples

Get a Session-ID

curl -v https://login.salesforce.com/services/oauth2/token -d "grant_type=password" -d "client_id=<CLIENT_ID>" -d "client_secret=<CLIENT_SECRET>" -d "username=<USER_NAME>" -d "password=<PASSWORD+TOKEN>" -H 'X-PrettyPrint:1'

 

Get CLIENT_ID and CLIENT_SECRET from any connected app or create a new app in your org: App Manager -> New Connected App

Simple request for an existing Campaign Item

A simple request with an existing Campaign Item to calculate the amounts with a new Quantity Discount of 10%.

Call Amount calculation web service

curl https://<my-domain-name>.my.salesforce.com/services/apexrest/ADvendio/ADvendio__Campaign_Item__c/DoCalculations/ -H 'Authorization: Bearer <SESSION_ID>' -H "Content-Type: application/json" -H 'X-PrettyPrint:1' -d @requestBody.txt --request PATCH


requestBody.txt


Response

Simple request for a new Campaign Item (virtual Campaign Item)

A simple request with a Campaign Item we want to create, to calculate the amounts.

Call Amount calculation web service


requestBody.txt


Response

Simple request for new Campaign Items (virtual Campaign Items) in the same Media Campaign

A simple request with multiple Campaign Items in the same Media Campaign we want to create, to calculate the amounts.

Call Amount calculation web service

In this part you need to execute the an Apex method through the developer console in order to obtain a valid virtual MC Id.

System.debug(CheckAvailabilityService.getFakeId(MediaCampaign__c.SObjectType));

Then the following request can be used:

Simple request for a Package

A simple request with an existing Campaign Item to calculate the amounts for a package.

Call Amount calculation web service

Usage in Apex