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
Rishabh Patel 1Rishabh Patel 1 

Constructor not defined: [CustomFields].<Constructor>(String, Date)

How do I define a Date field  in the class to call in a Constructor

Here is my  class - 

public class CustomFields {
            public String fieldName;
            public String stringValue;
           
            public CustomFields(String fieldName, String stringValue){
                this.fieldName = fieldName;
                this.stringValue = stringValue;
            }
 

Here is the constructor 

jo.customFields = new List<CustomFields>();
            jo.customFields.add(new CustomFields('CX.LEADS360ID', currentOpp.Opportunity_ID__c));
            jo.customFields.add(new CustomFields('CX.LEADS360CAMPAIGN', currentOpp.Lead_Source_Name__r.Name));
            jo.customFields.add(new CustomFields('Date.CX.LEAD.CREATE.DATE', currentOpp.Legacy_Lead_Date_Added__c));
            jo.customFields.add(new CustomFields('CX.CRM.OWNER.EMAIL', currentOpp.Owner.Email));
 

I cannot add 

jo.customFields.add(new CustomFields('Date.CX.LEAD.CREATE.DATE', currentOpp.Legacy_Lead_Date_Added__c));

Because Opp.Legacy_Lead_Date_Added__c is a date field . How do I add a date variable in my class and call it in the constructor
       

Error I am getting 

Constructor not defined: [CustomFields].<Constructor>(String, Date) 

Best Answer chosen by Rishabh Patel 1
Harish DHarish D
Hi Rishabh,

How about converting the Date value to a string before adding the Legacy_Lead_Date_Added__c to list, something like this:

jo.customFields.add(new CustomFields('Date.CX.LEAD.CREATE.DATE', string.valueof(currentOpp.Legacy_Lead_Date_Added__c)));



 

All Answers

Harish DHarish D
Hi Rishabh,

How about converting the Date value to a string before adding the Legacy_Lead_Date_Added__c to list, something like this:

jo.customFields.add(new CustomFields('Date.CX.LEAD.CREATE.DATE', string.valueof(currentOpp.Legacy_Lead_Date_Added__c)));



 
This was selected as the best answer
Rishabh Patel 1Rishabh Patel 1
Perfect! thats what I was looking for! Thanks a lot