1

Aim/ count how many times the field "first name"is populate on the account object

Aim: count the number of Account records which have the First Name field populated.

Anyone got any ideas how I can do this ?

Looking forward to your response

Daniel

8
  • First name? As in, person accounts or contacts on each account? And do you mean when it changes?
    – sfdcfox
    Jun 6 '14 at 17:13
  • Hi sfdcfox. - I want to count how many times the "first name" on the account object is not blank. To be fair it can a field like website, just want to understand the logic to use.
    – Masond3
    Jun 6 '14 at 17:16
  • @Masond3 are you trying to get a total count of the number of Account records which have the First Name field populated?
    – Mark Pond
    Jun 6 '14 at 17:18
  • @ mark pond - yes , you hit it on the head
    – Masond3
    Jun 6 '14 at 17:19
  • 1
    There's a handy and free tool on the app exchange called Field Trip which does what you're looking for: appexchange.salesforce.com/… (Disclaimer, this is not my app or company)
    – kbentsen
    Jun 6 '14 at 17:36
2

Use the count(fieldname) SOQL function to count records for which the field is not null:

select count(firstname) from Account

This also lets you filter further. For example, if you only want to count how many Calfornia accounts have firstname populated:

select count(firstname) from Account where BillingState = 'California'
2
  • Anyway I can make it dynamic so instead of hard coding the field name/api names it knows when a new field is added
    – Masond3
    Jun 6 '14 at 18:21
  • You can use Dynamic SOQL (salesforce.com/us/developer/docs/apexcode/Content/…) to construct your query string at run time, allowing you to check any field if you know the fieldname; you can use SObject describe information (salesforce.com/us/developer/docs/apexcode/Content/…) to enumerate fields on an object. However, this is a technique for counting the number of records where a single field is populated. If you have further requirements, you should refine your question. Jun 6 '14 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.