Skip to main content
Full Circle Insights

Resetting First and Last Touch Campaigns on Opportunities

Goal

Sometimes organizations need to reset the First Touch Campaign or Last Touch Campaign fields on opportunities. This can be required for several reasons:

  1. The fields were not initially set because a validation error was encountered.
  2. The organization wants to update the criteria for setting First Campaign Touch fields.

Response Management does have a function you can use in the Developer Console that will trigger resetting these fields for a single or multiple set of opportunities. Please review how these fields are set.

This document will show you how to use the Developer Console to recalculate the first and last touch campaigns for specific opportunities. This approach can set only blank fields, or reset one or both fields..

First Step

Check your first touch configuration settings.

First Touch Campaign Days to Filter

From the Campaign Attribution button or the Full Circle Campaign Influence tab , click the Advanced configuration Button.

This setting determines how far back the system looks to populate a campaign in the opportunity First Touch Campaign field.

If the field is blank, there is no timeframe restriction.

If the field is populated it restricts how far back the application will look for a response for the Admin Originating Contact, if populated, else, if the Admin Originating Contact field is blank, the application will reference the Primary Contact Role.

 First & Last Touch Delay

Normally the opportunity first and last touch fields are set in a future context. This global setting allows you to specify the number of minutes to wait before these fields are set. Use this setting when you know your users immediately edit newly created opportunities and set this value to the time they would need to complete typical edits. This will prevent code update conflicts. Note: Only applies if the 2015 Async System is Enabled.

Based on the First & Last touch delay you can determine how long for the data to populate. You may want to temporarily shorten the timeframe during this upload.

Let's review the syntax you'll be using. We'll be using the following function:

SetFirstLastTouchOnOpportunities

Set<ID> SetFirstLastTouchOnOpportunities(Set<ID> opportunityIDs)

Calculates the first and last campaign touch on the specified opportunities that is associated to a response if they are not currently set.

Unlike SetFirstLastTouchOnAssociatedOpportunity, this function will set first & last touch on a set of opportunities based on primary contact role if the opportunity is not associated with a response. This function will only operate on opportunities that have either first or last touch set to null.

If opportunityIDs is null, this function will perform the same operation as SetFirstLastTouchOnAssociatedOpportunities.

Returns a Set of IDs of opportunities where the update failed.

As you can see - this function, as written will only populate the First Touch Campaign or Last Touch Campaign fields if they are blank. If you want to recalculate first and last touch campaigns, they will need to be cleared first.

We'll be using the developer console to call this function with the opportunity id's we want to process.

The line: Set<ID> oppsToProcess = new Set<Id>{'006C000000hVpiN','006C000000ih4jM'}; identifies which opportunities you want to process - you can have a single opportuinty id <Id>{'006C000000ih4jM'}; or multiple id's surrounded by single quotes and comma separated as displayed in the example above. The opportunity Id's can be 15 or 18 characters. You can have a maximum of 200 opportunity Id's in a single command.

Below are some options you can use depending on what you want to populate.

1. Only update first and last touch campaigns if the campaign field is not populated. Update the first line below with your opportunity IDs

Set<ID> oppsToProcess = new Set<Id>{'006C000000hVpiN','006C000000ih4jM'};
FCRM.FCR_SupportAPI.SetFirstLastTouchOnOpportunities(oppsToProcess);

2. Recalculate First Touch Campaign even if it's populated, we've added a command to clear the first touch field. Update the first line below with your opportunity IDs.

Set<ID> oppsToProcess = new Set<Id>{'006C000000hVpiN','006C000000ih4jM'};
List<Opportunity> oppsToUpdate = [SELECT Id, FCRM__FCR_Admin_Update_Counter__c, FCRM__FCR_First_Campaign_Touch__c  FROM Opportunity WHERE Id IN :oppsToProcess];
for(Opportunity opp : oppsToUpdate)
{
    opp.FCRM__FCR_First_Campaign_Touch__c = null;
    opp.FCRM__FCR_Admin_Update_Counter__c = (opp.FCRM__FCR_Admin_Update_Counter__c != null) ? opp.FCRM__FCR_Admin_Update_Counter__c+1 : 1;
}
update oppsToUpdate;
FCRM.FCR_SupportAPI.SetFirstLastTouchOnOpportunities(oppsToProcess);

3. Recalculate Last Touch Campaign even if it's populated, we've added a command to clear the last touch field. Update the first line below with your opportunity IDs.

Set<ID> oppsToProcess = new Set<Id>{'006C000000hVpiN','006C000000ih4jM'};
List<Opportunity> oppsToUpdate = [SELECT Id, FCRM__FCR_Admin_Update_Counter__c, FCRM__FCR_Last_Campaign_Touch__c FROM Opportunity WHERE Id IN :oppsToProcess];
for(Opportunity opp : oppsToUpdate)
{
    opp.FCRM__FCR_Last_Campaign_Touch__c = null;
    opp.FCRM__FCR_Admin_Update_Counter__c = (opp.FCRM__FCR_Admin_Update_Counter__c != null) ? opp.FCRM__FCR_Admin_Update_Counter__c+1 : 1;
}
update oppsToUpdate;
FCRM.FCR_SupportAPI.SetFirstLastTouchOnOpportunities(oppsToProcess);

4. Recalculate First Touch and Last Touch Campaigns even if they are populated, we've added a command to clear the first and last touch fields. Update the first line below with your opportunity IDs.

Set<ID> oppsToProcess = new Set<Id>{'006C000000hVpiN','006C000000ih4jM'};
List<Opportunity> oppsToUpdate = [SELECT Id, FCRM__FCR_Admin_Update_Counter__c, FCRM__FCR_First_Campaign_Touch__c, FCRM__FCR_Last_Campaign_Touch__c FROM Opportunity WHERE Id IN :oppsToProcess];
for(Opportunity opp : oppsToUpdate)
{
    opp.FCRM__FCR_First_Campaign_Touch__c = null;
    opp.FCRM__FCR_Last_Campaign_Touch__c = null;
    opp.FCRM__FCR_Admin_Update_Counter__c = (opp.FCRM__FCR_Admin_Update_Counter__c != null) ? opp.FCRM__FCR_Admin_Update_Counter__c+1 : 1;
}
update oppsToUpdate;
FCRM.FCR_SupportAPI.SetFirstLastTouchOnOpportunities(oppsToProcess);

Second Step

You are going to be updating opportunities. Are there any validation rules you will need to either modify or deactivate during this update?

You can modify validation rules not to fire for this update by adding the criteria not to fire if the Admin Response control field is updated. To do so, add this line within an AND statement

NOT(ISCHANGED( FCRM__FCR_Admin_Update_Counter__c ))

Third Step

Create an opportunity report of all of the opportunities you want to update. This report should have the opportunity ID. Export the report.

Arrange the opportunity ID's in groups of 200 or less, with each ID surrounded by single quotes, and comma separated.

If you use a Sublime Text 2 or a similar text editor you can select all > split into lines > then mass edit the lines to get to this final stage

'006C0000012nKLn','006C0000012oLCX','006C0000013H3wV','006C0000012mpUI','006C0000011rt69','006C0000013I9jP',
'006C0000012mF9H','006C0000012n5Ez','006C0000011lkwQ','006C0000010pGtn','006C0000012XN5m','006C0000012O21F',
'006C0000012n5Ct','006C0000013IFak','006C0000012pjmL','006C0000012mFeZ','006C0000013HAvV','006C0000012pjmz',
'006C0000013GzKZ','006C0000013HqB1','006C0000012lxBP','006C0000013I83H','006C0000013IlkY','006C0000012mnqm',
'006C0000013J0jC','006C0000011u0Z1','006C0000011susq','006C0000011lqMT','006C0000012pV8K','006C0000012mzvC',
'006C0000012n4DH','006C0000012mAcG','006C0000013HUOl','006C0000012onh0','006C000001264ua','006C0000012nFBa',
'006C0000013IfkF','006C0000012ndkb','006C0000013IEYd','006C0000013JPkK','006C0000012pTlr','006C0000012pHQI',
'006C0000013H5PZ','006C0000012n3l5','006C0000012Wj93','006C0000012XhTr','006C0000013JQF8','006C0000012ojfc',
'006C0000013HZAD','006C0000013JaeT','006C0000013JVMu','006C0000013H3AQ','006C000001265dG','006C000001278D7',
'006C000000ynL6h','006C0000013H5MV'

Select the code from first step that has the desired functionality.

You will need to chunk the ID's in to groups of 200 or less and then paste them into the first line of your code so that

Set<ID> oppsToProcess = new Set<Id>{'006C000000hVpiN','006C000000ih4jM'};

changes to - without the carriage returns - we have to make some concessions for the sake of readability.

Set<ID> oppsToProcess = new Set<Id>{'006C0000012nKLn','006C0000012oLCX','006C0000013H3wV','006C0000012mpUI',
'006C0000011rt69','006C0000013I9jP',
'006C0000012mF9H','006C0000012n5Ez','006C0000011lkwQ','006C0000010pGtn','006C0000012XN5m','006C0000012O21F',
'006C0000012n5Ct','006C0000013IFak','006C0000012pjmL','006C0000012mFeZ','006C0000013HAvV','006C0000012pjmz',
'006C0000013GzKZ','006C0000013HqB1','006C0000012lxBP','006C0000013I83H','006C0000013IlkY','006C0000012mnqm',
'006C0000013J0jC','006C0000011u0Z1','006C0000011susq','006C0000011lqMT','006C0000012pV8K','006C0000012mzvC',
'006C0000012n4DH','006C0000012mAcG','006C0000013HUOl','006C0000012onh0','006C000001264ua','006C0000012nFBa',
'006C0000013IfkF','006C0000012ndkb','006C0000013IEYd','006C0000013JPkK','006C0000012pTlr','006C0000012pHQI',
'006C0000013H5PZ','006C0000012n3l5','006C0000012Wj93','006C0000012XhTr','006C0000013JQF8','006C0000012ojfc',
'006C0000013HZAD','006C0000013JaeT','006C0000013JVMu','006C0000013H3AQ','006C000001265dG','006C000001278D7',
'006C000000ynL6h','006C0000013H5MV'};

so if we're using example 2 in the first step your code will look like this for each set of 200 opportunities.

Set<ID> oppsToProcess = new Set<Id>{'006C0000012nKLn','006C0000012oLCX','006C0000013H3wV','006C0000012mpUI',
'006C0000011rt69','006C0000013I9jP',
'006C0000012mF9H','006C0000012n5Ez','006C0000011lkwQ','006C0000010pGtn','006C0000012XN5m','006C0000012O21F',
'006C0000012n5Ct','006C0000013IFak','006C0000012pjmL','006C0000012mFeZ','006C0000013HAvV','006C0000012pjmz',
'006C0000013GzKZ','006C0000013HqB1','006C0000012lxBP','006C0000013I83H','006C0000013IlkY','006C0000012mnqm',
'006C0000013J0jC','006C0000011u0Z1','006C0000011susq','006C0000011lqMT','006C0000012pV8K','006C0000012mzvC',
'006C0000012n4DH','006C0000012mAcG','006C0000013HUOl','006C0000012onh0','006C000001264ua','006C0000012nFBa',
'006C0000013IfkF','006C0000012ndkb','006C0000013IEYd','006C0000013JPkK','006C0000012pTlr','006C0000012pHQI',
'006C0000013H5PZ','006C0000012n3l5','006C0000012Wj93','006C0000012XhTr','006C0000013JQF8','006C0000012ojfc',
'006C0000013HZAD','006C0000013JaeT','006C0000013JVMu','006C0000013H3AQ','006C000001265dG','006C000001278D7',
'006C000000ynL6h','006C0000013H5MV'};
List<Opportunity> oppsToUpdate = [SELECT Id, FCRM__FCR_Admin_Update_Counter__c, FCRM__FCR_First_Campaign_Touch__c  FROM Opportunity WHERE Id IN :oppsToProcess];
for(Opportunity opp : oppsToUpdate)
{
    opp.FCRM__FCR_First_Campaign_Touch__c = null;
    opp.FCRM__FCR_Admin_Update_Counter__c = (opp.FCRM__FCR_Admin_Update_Counter__c != null) ? opp.FCRM__FCR_Admin_Update_Counter__c+1 : 1;
}
update oppsToUpdate;
FCRM.FCR_SupportAPI.SetFirstLastTouchOnOpportunities(oppsToProcess);

At the end of this process you should have a set of code blocks ready to cut and paste into the developer console.

Fourth Step

Go to the Developers Console - from your name in the top right of the browser click on Developer Console

Select Debug > Open Execute Anonymous Window

Paste and click the Execute button and you will see the Executing popup.

You are looking for a Success in the Logs tab below.

Last Step

In this step you are going to validate that the code works. Keep in mind that the first and last touch campaigns are updated asynchronously, so you won't see results right away. If you're doing a lot of records the updates will be queued up.

Review the opportunities from your report and over time you will see the fields being reset.

Make sure to check the Response Management event logs - you may see update failures there if validation rules were hit.

Setup > Installed Packages > Manage (By Full Circle Insights Response Management) > Event Logs

If you see any issues you can adjust validation rules etc. and run those opportunities through again.

 

  • Was this article helpful?