Flow creates duplicate records during bulk update!

Tags

,

I faced a strange issue w.r.t Flows which was creating Duplicate records when I did bulk update of records. Details are as follows.

We have a custom object Rate Card which stores information related to rates(Currency fields) based on the service and the account(master detail relationship between Account and Rate Card). Let’s say for physiotherapy service and the account (let’s say ‘HomeCare’), we capture several rate fields(Daily Rate, Half-a-day Rate, Hourly Rate etc). Also, we have Validated flag and once the record is validated(by checking the flag), we trigger a flow(below screenshot) from the process and it will create Pricebook, Product and Pricebook entry records since we want to create Opportunity and Opportunity Product from the Rate Card record.

flow screenshot

Each Pricebook corresponds to an account and Products which will be the services(e.g. Physiotherapy) that we provide to the account.

First step in the flow is to check if the pricebook exists and if it exists, create the product. If it doesn’t exist, create the pricebook and create the product.

Then, create a Pricebook Entry record for Standard Pricebook and a Pricebook Entry record for custom pricebook(associate the pricebook and product created in previous steps).

This works absolutely fine when I validate Rate Card records manually one by one in UI. But, we have around 500+Rate Card records for which we need to create Pricebook, Product and Pricebook Entry records. So, I went ahead and used dataloader.io to update Validated flag and unfortunately, flow created duplicate Pricebook records and this issue happens only for the account which has more than one Rate Card.

When I investigated further, I could find this link https://developer.salesforce.com/forums/ForumsMain?id=906F0000000ArtkIAC which highlights the same issue.

When I checked the logs, it looks like the flow runs in parallel for all the records that I updated so the first step Lookup Pricebook did not find the Pricebook for the  updated records, hence created duplicate entries.

Then, I found a workaround by extracting the accounts which has more than one Rate Card. From the list, make sure that I extracted Rate Card records which has unique account ids and update the Validated flag.  System created Pricebook, Products and Pricebook Entry as expected without any duplicates.Then, updated the Validated flag for the rest of the records and system created Pricebook, Products and Pricebook Entry records.

Has anyone else faced this issue before? Is it a known issue and if so, is there an idea for it in Salesforce Success community? Please let me know your comments.

 

Tip#16 – Overriding Standard New button

Tags

, ,

Suppose, you have created a flow which will create Opportunity and this process is invoked by a custom button (Create Opportunity) on the Account object. In this case, you might want to override New button available in Opportunity tab(Recent records) with the Visualforce page and clicking on it, should throw an error message saying that Opportunity can be created by clicking on Create Opportunity button in Account record.

Also, provide a back button in the VF page and code for the same is given below:

[code language=”html”]

<apex:page standardController="Opportunity">
<p>You cannot create an opportunity from here, instead click on Create Opportunity button by going to Account Detail page.</p>
<apex:form>
<apex:commandbutton action="{!cancel}" value="Return" rerender=""/>
</apex:form>
</apex:page>

[/code]

Tip# 15 – Matching Rule

Tags

, ,

Recently, I have got chance to work in Matching rule for Account, Contact and a custom object.
Have a look at these videos to get an introduction about Duplicate Management and Matching rules:
http://salesforce.vidyard.com/watch/PdYJPLbTqiI-kCXlWrr32w

Few points to note:

a. A matching rule can have only one lookup relationship field.
b. We cannot have a Date field in the matching criteria. Work around is to have a text field which has the date in text format and use it in the Matching Criteria. Suppose, you have a DOB field and to use it in the criteria, create a text field which will hold the date in text format. You can have a workflow to update this field when DOB is not empty(use TEXT() function).
c. We cannot have multi select field in the matching criteria.

Please let us know your comments.

P.S: When you use TEXT function, Dates are returned in the form of YYYY-MM-DD, that is, a four-digit year and two-digit month and day.

Tip#14: Updating blank values using Data loader

Tags

, ,

Recently, I had a requirement to update a field with NULL value using APEX Data loader.

There is a setting in Data Loader that allows for updating a field with a NULL value and it’s as follows:

1. Launch Data Loader
2. Select Settings
3. Check box – Insert Null Values.

Then, follow the below procedure:

1. Export the data – include id and Field that should be changed to blank.
2. Delete data contained in column that should be returned as NULL (no values).
3. Save new .csv with new name to avoid overwriting Data Export in Step 1 of this sample process.
4. Run Data Loader Update using new file with Blank values.

Sharing is fun!

Tip#13: Process Builder bulkified!

Tags

, ,

I developed a process recently in Accounts object and when I did a mass update of account records(around 600+ records), I got an error saying Too many SOQL queries: 101. This is due to the reason that process builder is not bulkified. Good news is that from winter 16 release onwards, the chances of getting this error would be reduced as Salesforce made process builder to handle bulkification.

Release notes link: http://releasenotes.docs.salesforce.com/en-us/winter16/release-notes/rn_forcecom_process_bulkification.htm#rn_forcecom_process_pb_bulkification.xml

Tip# 12: Resolving “Schedulable class has jobs pending or in progress” error

Tags

,

This error “Schedulable class has jobs pending or in progress” might occur when saving the class after editing it.

This could be due to the reason that there are scheduled jobs related to the class that we are trying to edit or its dependent classes. To resolve the issue, we can abort the jobs manually from Setup->Jobs->Scheduled Jobs.

There is a detailed explanation about this error in the link https://help.salesforce.com/apex/HTViewSolution?id=000004423&language=en_US

P.S. I had got this error recently in Sandbox for one of the class after I modify it, though its dependent class is scheduled and after deleting the corresponding jobs in Setup->Jobs->Scheduled Jobs, I could save the class successfully.

Tip#10: APEX Data loader for Mac OS

Tags

As of Summer’15 release, APEX Data Loader for Mac OS X is available. It is available in Enterprise, Professional, Performance, Unlimited, and Developer Editions.

APEX Data Loader is an easy-to-use graphical tool that helps you to import, export, update, and delete Salesforce data.

To download the Mac version, click on Setup->Data Management->Data Loader in your Salesforce Org. Salesforce recommends the uninstall of LexiLoader or any similar tool which you might have been using, before installing the Data loader.

P.S: There is an another useful Data loader tool available which is Dataloader.io and I love it due to ease of use, task history and other features(including scheduled tasks).

Tip#9: CASESAFEID and Converting 15 Character Salesforce Id to 18 Character Id

Tags

,

Salesforce has 2 versions of Id, 15 and 18 characters. Originally, all Salesforce IDs were 15-characters and case-sensitive whereas 18 character Id is case insensitive.

Suppose, we are exporting report data from salesforce onto excel and using the Excel VLOOKUP function to match up records. Since VLOOKUP doesn’t handle case-sensitive data well, we would have to convert 15 character Salesforce Id to 18 character Id.

As part of Spring ’12 release, Salesforce introduced a new formula function CASESAFEID, which accepts a 15-character ID as a parameter and returns the 18-character version. For instance, CASESAFEID(Id).

Also, I use the link https://www.adminbooster.com/tool/15to18 to convert 15 character Id to 18 character Id instantly.

There is a knowledge article on converting 15 to 18 character Id and the link for the same is https://help.salesforce.com/apex/HTViewSolution?id=000005288&language=en_US