• About
  • Contact me!

Salesforce Everywhere

~ Blog on Salesforce Dev and admin stuff

Salesforce Everywhere

Category Archives: Salesforce Configuration

Tip#17 – Accessing “User License” field on User Object

07 Monday Dec 2015

Posted by Mani in Salesforce Configuration

≈ Leave a comment

Tags

UserLicense

If you want to access User license field which determines the type of license that user is on(ex: Salesforce, Salesforce Platform etc), you can access it in apex  as follows:

User.Profile.UserLicense.Name

Suppose, you want to create a validation rule in User object to make a custom field mandatory based on the license, it could be as follows,substitute Customfield with the actual field name(API name):

AND(ISNEW(),ISBLANK(Customfield), OR(Profile.UserLicense.Name=’Salesforce’,Profile.UserLicense.Name=’Salesforce Platform’)

Advertisement

Flow creates duplicate records during bulk update!

24 Tuesday Nov 2015

Posted by Mani in Salesforce Configuration

≈ Leave a comment

Tags

Duplicate records, Flow

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# 15 – Matching Rule

27 Tuesday Oct 2015

Posted by Mani in Salesforce Configuration

≈ Leave a comment

Tags

duplicate management, matching rule, matching rule criteria

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.

Validating accounts

09 Friday Oct 2015

Posted by Mani in Salesforce Configuration

≈ Leave a comment

Tags

Account Validation, Validate accounts

In this post, I will explain about Validating accounts in Salesforce and how I have implemented it using Process Builder.

Requirement:

Accounts need to be validated by Sales Manager(Office Manager) once the account is created by Sales Rep.
There should be 2 custom fields created: Validated(Checkbox) and Validated by(Lookup to User). Validated flag need to be editable only by Sales Manager, Validated by should be read only and auto populated by the system(with the user who is checking Validated checkbox).

Implementation:

I created the custom fields as mentioned above in Accounts Object.I have given view access to those fields at the profile level only for System admin, but in Sales Manager/Office Manager permission set, I have provided R/W access for Validated checkbox and Read access for Validated by fields.

Once the user tick the Validated flag, process will be called and it will update the lookup field Validated by. Screenshots are attached below:

Process

First step

Process should be called only when Validated flag is updated and ticked:

second step

Update Validated by field using Update Records action and update Validated by field using Reference with LastModifiedbyId field:
third step

If the Validated flag is unchecked, clear the Validated by field:
Fourth stepLast step

Also, we created a list view in Accounts object for the Sales Manager which will show all the accounts that are not validated.

Moreover, we have updated Validated flag to Y and Validated by to the Sales Manager user Id for all the existing account records by using Dataloader.io tool. We inactivated the process when we ran the update else process would throw the error “Too many SOQL queries: 101”. I have discussed about this error in the post https://getintosalesforce.wordpress.com/2015/10/09/tip13-process-builder-bulkfied/.

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

22 Tuesday Sep 2015

Posted by Mani in Salesforce Configuration

≈ Leave a comment

Tags

15to18 character Id, CASESAFEID

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

Tip#8 : Troubleshooting “cannot create a new Master-Detail relationship” error

21 Monday Sep 2015

Posted by Mani in Salesforce Configuration

≈ Leave a comment

Tags

Master Detail relationship error

To demonstrate the case, let’s say that we have a custom object called “RateCard” and it has got a lookup field “Account”. We want to convert the lookup relationship to Master – detail, as we can have more than 1 Rate Card per account(1:M relationship). I tried changing the lookup to Master Detail for the account field and got the error “cannot create a new Master-Detail relationship”.

This is due to the reason that the lookup field(Account) in all RateCard records did not have a value. Once I populated the value for Account field in the records that didn’t have it, I could convert the Account relationship to Master – Detail. Please note that Master – Detail relationship requires Detail Record (Child) ALWAYS have a Master (Parent) record since the detail record inherits security and ownership from the parent record.

Let me know your comments.

Tip#7: Adding Hyperlink in the flow

16 Wednesday Sep 2015

Posted by Mani in Flow, Salesforce Configuration

≈ 16 Comments

Tags

Adding Hyperlink in the flow, Flow

UPDATE:

Thanks Evan for your comments!!

In more recent versions of Flow, you can simply have your URL point to /{!RecordId} and Salesforce will correctly navigate to the record. Obviously, RecordId variable in the flow should hold the Id of the record. I did a quick check on this in my Dev edition org and it worked.

Here is how you can do it in the new flow builder:

Create a screen element with the Display text as Link(or whatever you name the text) and give the hyperlink as /{!RecId} where RecId is the flow variable which holds the Id of the created record or the Id of the record to be navigated to, after the user clicks on the Display text(Link). Screenshot is given below for your reference:

Link screenshot2

How to achieve this in Old Flow Builder:

For example, there is a flow which gets inputs from user and creates a RateCard(Custom object) record, if it doesn’t exist in the system. Once created, it should show the URL(clickable) of the record created.

This is possible by editing the screen(which is the last step in the flow) and the Display text field there is a little button which shows T(marked in yellow colour in the screenshot below) with what looks like a selection box around it. Type the text you want (View the RateCard record here). Highlight it, and in one of the fields that showed up you can put in the url,something like https://cs5.salesforce.com/{!RateCardIdcreated}

Adding Hyperlink in the Flow

Clickable link
P.S: RateCardIdcreated holds the Id of the RateCard record created.

Please let me know your comments.

Adding months to a Date field

19 Wednesday Aug 2015

Posted by Mani in Adding months to a date using Salesforce formula, Salesforce Configuration

≈ Leave a comment

Tags

Adding months

Requirement:

In my current project, based on Commencement Date of Resource, I need to send out email notification to several departments(HR, Payroll etc) and I need to do it if Resource completes 6, 12, 24 and 36 months. Basically, I had to add 6, 12,24 and 36 months to Commencement Date field and based on that date, I need to trigger Workflow notification(Time Trigger).

Analysis:

Salesforce help site https://help.salesforce.com/HTViewHelpDoc?id=formula_examples_dates.htm has a formula and it is as follows, but unfortunately it throws compilation error(Compiled formula is too big to execute (5,503 characters). Maximum size is 5,000 characters) when tried:

IF(
MOD( MONTH( Commencement_Date__c ) + 6, 12 ) = 2,
IF(
DAY( Commencement_Date__c ) > 28,
DATE( YEAR( Commencement_Date__c ) + FLOOR( ( MONTH( Commencement_Date__c ) + 6 ) / 12 ), 3, 1 ),
DATE( YEAR( Commencement_Date__c ) + FLOOR( ( MONTH( Commencement_Date__c ) + 6 ) / 12 ), 2, DAY( Commencement_Date__c ) )
),
IF(
OR(
MOD( MONTH( Commencement_Date__c ) + 6, 12 ) = 4,
MOD( MONTH( Commencement_Date__c ) + 6, 12 ) = 6,
MOD( MONTH( Commencement_Date__c ) + 6, 12 ) = 9,
MOD( MONTH( Commencement_Date__c ) + 6, 12 ) = 11
),
IF(
DAY( Commencement_Date__c ) > 30,
DATE( YEAR( Commencement_Date__c ) + FLOOR( ( MONTH( Commencement_Date__c ) + 6 ) / 12 ),
MOD( MONTH( Commencement_Date__c ) + 6, 12 ) + 1, 1 ),
DATE( YEAR( Commencement_Date__c ) + FLOOR( ( MONTH( Commencement_Date__c ) + 6 ) / 12 ),
MOD( MONTH( Commencement_Date__c ) + 6, 12), DAY( Commencement_Date__c ) )
),
IF(
MOD( MONTH( Commencement_Date__c ) + 6, 12 ) = 0,
DATE( YEAR( Commencement_Date__c ) + FLOOR( ( MONTH( date ) + 6 ) / 12 ) – 1, 12, DAY( Commencement_Date__c ) ),
DATE( YEAR( Commencement_Date__c ) + FLOOR( ( MONTH( Commencement_Date__c ) + 6 ) / 12 ),
MOD( MONTH( Commencement_Date__c ) + 6, 12), DAY( Commencement_Date__c ) )
)
)
)

Solution:

Thanks to Chris (http://www.salesforceweek.ly/author/chris) and the link http://www.salesforceweek.ly/2015/01/how-to-formula-add-months-to-date.html gives a good post about adding months to a Date.

As per the above link, I tried the following formula which adds n months(6,12, 24 and 36 month) works perfectly fine(including leap years) where n means :

DATE (  /*YEAR*/  

YEAR(Commencement_Date__c) + FLOOR((MONTH(Commencement_Date__c) + n - 1)/12), 

 /*MONTH*/  
 
CASE(MOD(MONTH(Commencement_Date__c) + n, 12 ), 0, 12, MOD(MONTH(Commencement_Date__c)+ n, 12 )),  

/*DAY*/  

MIN(DAY(Commencement_Date__c),  CASE(MOD(MONTH(Commencement_Date__c) + n,12), 9, 30, 4, 30, 6, 30, 11, 30, 2,  

/* return max days for February dependent on if end date is leap year */  

IF(MOD(YEAR(Commencement_Date__c) + FLOOR((MONTH(Commencement_Date__c) + n)/12), 400) = 0 || (MOD(YEAR(Commencement_Date__c) + FLOOR((MONTH(Commencement_Date__c) + n)/12), 4) = 0 && MOD(YEAR(Commencement_Date__c) + FLOOR((MONTH(Commencement_Date__c) + n)/12), 100) <> 0  ), 29,28), 31))  )

Please let me know your comments as always.

SFDC Developer interview questions

26 Sunday Apr 2015

Posted by Mani in Salesforce Configuration, Salesforce interview questions

≈ 2 Comments

Tags

Salesforce Dev questions, Salesforce Developer interview questions, SFDC developer interview questions, SFDC interview questions

Recently, I took the interview with a Consulting company and it was a pure technical round of interview. I thought of sharing the questions and please find them below:

1. What is Cloud computing and salesforce?
2. 3 Best practices of SOQL
3. Whats the difference between 15 and 18 digit Id?
4.  What is without sharing option and why is it given by SF?
5. Purpose of static resource
6. Suppose there is a field called priority in accounts and if its greater than 5, we need to update associated contact records. how will you do it?
7. Following the previous question, what will happen if you write the trigger on before update?
8. What is Cross object workflow and its limitations?
9. Can you check null pointer exception in try catch block?
10. Can you check DML governor limits in try catch block?
11. Is apex always run in system mode?
12. What are standard controllers, controller extensions and custom controllers?
13. What’s the issue in the below code :

for (Account a : trigger.new) {

for (Contact c : [select id,otherphone from contact where accountid =:a.id]) {

c.OtherPhone= a.Phone; 

update c;

}

}

14.  Given the following Force.com page markup and assuming the controller and each extension include an action method named “go,” which class method will be invoked when the user clicks on the commandButton? 

Screen Shot 2015-04-26 at 10.06.29 pm

15. A Force.com page has a command button that directly calls the doSomething() method shown below, where the MyCustomException is a class that extends the System.Exception class

 public void doSomething(){
} throw new MyCustomException(‘An error message.’);
Where would the exception be displayed to the user?

16. How do you make a Web service callout(outbound)?
17. How do you call a method in the class asynchronously in SFDC?
18. What is @isTest(SeeAllData=true)?
19. How do you make sure that your test class covers +ve and -ve scenarios?
20. Whats the advantage of using inline CSS?
21. If there is a trigger on account object and if you insert data through data loader lets say 200 records and on 200th record, the trigger fails, will it roll back or will it commit 199 records?
22. How do you get the contact name from accounts when you write SOQL?
23. Force.com has already provided functionalities OOB, so when you get the requirement, how do you approach it?
24. W
hat is SaaS, PaaS and IaaS?
26. What is the action attribute in command button signifies in VF page?
27. What is batch apex, apex scheduling?

Incorrect User Name/Password error

07 Tuesday Apr 2015

Posted by Mani in Salesforce administration, Salesforce Configuration

≈ Leave a comment

Tags

Invalid username or password, Username or password error

Issue:

Last week, I faced a strange issue when I worked for one of the client and 2 of their users were not able to login into Salesforce. They were getting incorrect user id/password error though they tried with the correct user name and password.

Analysis:

Raised Reset Password request and they changed the password by following the instructions given in the email sent by Salesforce. Then, they logged out and tried log back in with the correct user name & password, system didn’t allow them to get into it. It has thrown incorrect user id/password error.

Strangely, the login history didn’t show anything for userid/password error (the login attempts user tried after the password reset).

I tried logging into Salesforce using their logins in my machine and I have got the same user id/password error even with the correct credentials.

Solution:

I raised a case with Salesforce and they have shared the following Knowledge article:

https://help.salesforce.com/apex/HTViewSolution?urlname=Troubleshoot-log-in-issue-Invalid-username-or-password&language=en_US

The issue in our case was that the user name created for those 2 users in question were having trailing spaces at the end of the username. After we corrected the username and set the new password, they were able to login into Salesforce successfully.

Your comments are most welcome.

← Older posts
Newer posts →

Blog Stats

  • 114,771 hits

Archives

Recent Posts: Salesforce Everywhere

How to get field values on onLoad in lightning-record-edit-form in LWC?

Using Dynamic Actions

How to check if the logged in user is a Guest user or not in APEX class?

How to Close Quick action in LWC

Lightning component to filter Products and display results in lightning data table

Connect with me

  • View @manibalan_s’s profile on Twitter
  • LinkedIn

Developer links

  • Salesforce Developer website
  • Salesforce Success Community

Enter your email address and click on Follow us (below) to follow this blog and receive notifications of new posts by email.

Website Powered by WordPress.com.

  • Follow Following
    • Salesforce Everywhere
    • Already have a WordPress.com account? Log in now.
    • Salesforce Everywhere
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar