function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
suji srinivasansuji srinivasan 

how to count the number of custom field in apex class?

I have LOP__c field in Leaverequest__c object .
I need to  count this field in  records.

Thanks in advance
 
Best Answer chosen by suji srinivasan
Shiraz HodaShiraz Hoda

Hi Suji,

If I am not wrong you want count of records where LOP__c is not blank. Please run below query that will give you required result. Please hit a like if this answers your question.

select count(id) from LeaveRequest__c where LOP__c != '' AND LPO__c != null;

All Answers

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Suji,

Can you ellobrate it. What do you meant by you want to count? Do you want to count no of records which has some value in that field?

Thanks,
 
Shiraz HodaShiraz Hoda

Hi Suji,

If I am not wrong you want count of records where LOP__c is not blank. Please run below query that will give you required result. Please hit a like if this answers your question.

select count(id) from LeaveRequest__c where LOP__c != '' AND LPO__c != null;
This was selected as the best answer
mukesh guptamukesh gupta
Hi Suji, 

Just simple

quickest way was to copy all fields from the field page to an excel doc an count the lines :So works accurately

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh
suji srinivasansuji srinivasan
Hi, 
I need to get LOP__C field from custom object Leave_Request__c for previous month (to calculate salary). 
Then  i need to count LOP__C field in salary__c object.  in batch apex.

Thanks in advance