Wednesday, 21 February 2018

Twin Fields in CPQ and Salesforce

Twin field is a new term that introduced by CPQ and it has some similarity to formula field in salesforce.

If you are coming from programming background , definitely you have heard about auto-mapper which basically maps to fields between two objects if the field name and type are the same.

If you don't have programming background, nothing to worry about as it is simple.Basically the requirement is mapping two fields in two objects if the name and type are exactly the same.

CPQ Twin Fields

CPQ Twin Fields

To give you an example , consider you like to have access to a field you created or existed in Product object in Quote Line. Based on the above, auto mapping is available between these two objects, and if you have a field called "MyField__c" on product as a text or picklist  that wanted to map to Quote line , go to Quote line object and create exactly the same field name "MyField__c" with text or picklist, and that's it.

Now if you set some value to that field in product the the value automatically will be available on  Quote line, this value can be used later for some filtering or ...


CPQ Product basic configuration

I recently went to the salesforce CPQ training and found it really useful so decided to share my knowledge as I still can remember :) with everyone else as there are not many resources available.


If this is a fresh org without any data first you need to add product family.
Go to Setup -> Product -> fields -> Product Family and add your product families to the picklist values



I only added hardware as a product family.

Then go to product and add new product.


I added "Dell laptop" and selected the "Hardware" as the product family and make sure you click on Active checkbox/


After installing CPQ package you need to change some of the existing layout of the objects, Now let's start with Product object, by default all profiles can see the default layout of product layout.
Go to product pay layout assignment

And click on Page Layout assignment -> Edit assignment and assign CPQ product layout to all profiles and save it.

Go to the one of existing product and view it, this time you should be able to see a layout like this :


Based on the product you selling , you might have a subscription product like selling a licence with some duration or service with some duration or a a laptop,...

All product behavior cane be set here , then later on you can see it in Quote Line Editor.

The first item is Pricing method, this can be List, Block and Cost.
The second item is Subscription products.


If the product you are selling is like a service or licence with subscription then in the "Subscription" section it needs to be configured.

Subscription Pricing can be fixed price , subscription terms can be 1 , also you can say if this product is renewable or not ,...

The other option for subscription pricing can be "percent of total" this is more like a warrant service or administration service that can be applied based on the amount of other selling product, to give you more specific example this can be you are selling a laptop and now you would like to add warranty , the warranty itself is a product with subscription pricing of percent of total , then you need to specify the subscription percentage like 5% or 10%


The last item is bundle configuration.

Note: In order to set the term in you org, go to setup-> install package-> CPQ package and click on configure , then go to Subscription and Renewals tab and set the related "Subscription Term Unit" to Month or day. plus you can set the "Subscription Prorate Precision" to Day, Month, Month+Day


Consider there are two product with following information and term setting is Month and Prorate is Month

LicenseProduct , Term : 1, price :fixed $10

SupportProduct, Term :12, price: fixed $20

Now if you want to create a quote for 3 months and 15 days and 1 quantity the calculation would be

LicenseProduct  1*4 month(because prorate is month) *10 = $40
SupportProduct 1* (4/12) * 20 = *20 = $6.66



How to calculate Prorate Multiplier 

Consider a scenario which start date of a subscription is 1/July/2017 and end date is 1/July/2018.
If prorate multiplier needs to be calculated for different Term and Prorate precision, also consider the term of the product covers whole 1 year (12 months or 365 days).

366 days or 12 Months and 1 day in 1/July/2017 -  1/July/2018 period

Prorate Multiplier : Subscription duration / Subscription term duration

Scenario 1
Term : Month
Product term:12
Prorate Precision : Monthly


Prorate Multiplier : 13 / 12 = 1.0833

Scenario 2
Term : Day
Product term:365
Prorate Precision : Daily

Prorate Multiplier : 366/365 = 1.0027

Scratch Org and installing CPQ package

Scratch Orgs in salesforce is a disposable salesforce environment, it means it's a fresh salesforce env with an expiry date on it, so many configuration can be set in the Salesforce ScratchOrg definition file like if you want multi currency is enabled or not ,....

If you want to know the capabilities please refer to Salesforce DX developer guide as it explains in detail

I've found it interesting as I like working with commands and script to maintain my development environment  better!

Recently I started learning about CPQ and wanted to see if I can create a scratch org and then install the CPQ package on it.

Prepare the environment:

If you have't create a scratch Org first you need to download and install the Salesforce CLI.
Then you need to enable Dev Hub, Go to setup and look for "Dev Hub" and enable it.
\
Go to command prompt and type sfdx without anything else and see if it recognise it.


Create the first Scratch Org

Go to command prompt and type the following command

  • />sfdx force:auth:web:login --setdefaultdevhubusername

Once you login to your org then it save your credential info(user/.sfdx folder)

  • Create a Scratch Org definition file with the following data and save it with a name(mysctrachorg.json)

{
  "orgName": "Cool org",

  "country": "AU",

  "edition": "Enterprise",

  "features": "MultiCurrency;AuthorApex",

  "orgPreferences": {

    "enabled": ["S1DesktopEnabled", "ChatterEnabled"],

    "disabled": ["SelfSetPasswordInApi"]
  }
}

go to command prompt again
  • >sfdx force:org:create -f mysctrachorg.json

After couple of seconds you should see the similar message as bellow
Successfully created scratch org: orgId like 0HF.... , username: test-lkjflkds5@example.com

Now you can open your org just by typing the following command
>sfdx force:org:open --targetusername test-lkjflkds5@example.com

Now since your org is ready go ahead and install the CPQ package

/>sfdx force:package:install -i 04tA0000000WZvmIAG


the open your org and go to setup -> install package and you should able to see the CPQ package in the list





Setting Global username in SFDX

If you are trying to install a package on an org and you get the following error
No defaultusername org found.

Then set the global username that sfdx used , this user should be link to at least one of your scratchorg, this is a example command

>sfdx force:config:set defaultusername=test-lkjflkds5@example.com --global


CPQ Renewal Opportunity and Forecasting

In order to create Renewal Opportunity which will be used you need to refer to Contract. Contract object has a field called " SBQQ__R...