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

Please suggest me getting the record count from contact and update the fields in contact


Please see the below Trigger

trigger CountFemales1 on Contact (after insert,after update,after delete) {

  List<Contact> contacts = Trigger.isdelete ? trigger.old :;
  Set<Id> accountIds = new Set<Id>();

  for (Contact c : contacts) {
     if (c.lastname!= null) {

list<Contact> FemaleList = [select id from contact where  id In :accountIds AND Customer_status__c ='buyer broker'];

 for(Contact a :FemaleList)  {
   a.No_of_Converted_Contacts__c= FemaleList .size();
 update FemaleList ;

when I try edit and save the record iam getting below error

Error: Invalid Data. 
Best Answer chosen by krish@123
Change this :
for(Contact a :FemaleList)  {
         a.No_of_Converted_Contacts__c= FemaleList .size(); 
With this :
for(Contact a :FemaleList)  {
         a.No_of_Converted_Contacts__c = integer.ValueOf(FemaleList .size()); 

this field "No_of_Converted_Contacts__c" msut be a Nmber.