Friday, December 29, 2017

Deep study on Salesforce count() vs count(fieldName)

Some useful links that related with count :

"Count is used to discover the number of rows that a query returns. "
You will notice , there two versions of syntax for COUNT():

  • count()
  • count(fieldName)

I experienced using both but I am not really deep into WHY COUNT() and WHY COUNT(fieldName) until today I did some reading and testing.I found the differences is quite interesting.

Difference in Query Editor result :

No field return.It directly say Total Rows:17
Total Rows:1 and it returns field which 17.

Difference in Apex code :

Can be assigned to Integer directly.

Integer count =[SELECT COUNT() FROM Contact WHERE Account.Name Like 'Test%' ];
system.debug('count '+ count);

You cannot assigned it to Integer or object, you must assign it to AggregateResult.It will throw error if you try to assign it Integer or object.

List countWithFieldName =[SELECT COUNT(Name) FROM Contact WHERE Account.Name Like 'Test%' ];
system.debug('countWithFieldName '+ countWithFieldName);

Extra use and limitation :


  • It is simple, JUST TO RETURN THE NUMBER OF ROW.That's it.The ability to be assigned directly to Integer make it better for that purpose.
  • It cannot be used with other field in query example
Select COUNT(),Name from Account will throw error.
  • It cannot be used with ORDER BY.
  • It cannot be used with GROUP BY for API version 19.0 later
  • Database.countQuery also serves the same purpose
1String QueryString =
2    'SELECT count() FROM Account';
3Integer i =
4    Database.countQuery(QueryString);


  • It provide extra benefit if we want to generate reports for analysis by adding GROUP BY.
  • ORDER BY need to be used together with GROUP BY.
  • As you can see, you can have other field together with COUNT in SELECT statement.

Useful for reporting

What do you think?
Let me know.

Tuesday, December 12, 2017

Salesforce Certified Platform App Builder

On 4th Dec 2017 Malaysia time, I am officially certified as Salesforce Platform App Builder.Honestly I don't feel it easy due to tricky question.

TopicPercentage Correct
Data Modeling and Management83%
Salesforce Fundamentals80%
User Interface50%
App Deployment80%
Business Logic and Process Automation56%

Personally I believe working in Salesforce will not be enough if we have no idea how the questions will be asked in exam.Sometimes I get confuse with the sentences and easily fall into the trap.The feeling is like taking Science exam in Malay language and although I am Malay I still need to be careful with keyword and how tricky it could be.

Once you plan to sit for exam, I highly advice you to check out how the question being asked.This can be done by check out the Exam Guide, quizes or mock up questions.Be careful on mockup question's answer because it might not 100% accurate.Usually I will read the question and directly check out the topic to compare with the answer.Please do not memorize the answer but find WHY the answer was given.

Here I would like to share of the topic/question that I faced during the exam.I am not able to recall 100% the exact question but I believe some of content maybe helpful for you.

  1.  There one object that all employee should able to see it, Sales department should be able to edit based on regional.How you going to setup for this scenario
  2. The organization would like to share the record to all employee but only HR can view certain field.
  3. System admin try to convert master detail field to lookup field but fail to do so? Why?
  4. System admin try to convert Lookup field to Master detail field.Select how.It will give you the list of options.
  5. A company has custom object Interview and Candidate. How to know how many candidates for one interview ?
  6. Many to Many relationships 
  7.  Self relationships
  8. Which sandbox we can use Sandbox Template?
  9. The Sales Manager would like to use Visual Flow in creating guide for Sales rep, how to make Visual Flow accessible to the user?It can be tricky question because it might list all options to launch Visual Flow. You might want to check how Visual flow can be run at back end and how it can be deployed as wizard.
  10. The criteria of external id
  11. Is it possible? Will changes  cause data loss? Picklist to Multipicklist, Text to Rich Text?

Also please focus on the questions that will be asked the most first.You can check out the percentage here .I am participating in Trailhead a lot, I believe it helps.There one Trailmix that dedicated to Salesforce Platform App Builder Credential

All the Best