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
Christopher PezzaChristopher Pezza 

Convert String Date to Date in Apex Class to insert to Object Field Type Date

public void SaveTheNewWebinars(){
        system.debug('**It Worked**');
        Webinar_nRichment_Attendees__c webinars = new Webinar_nRichment_Attendees__c();

        Date newestwebDate = Date.parse(newwebDate);
        String newestwebType = newwebType;

            webinars.Name__c = newwebName;
            webinars.Activity_Date__c = newestwebDate;
            if (newestwebType == 'Webinar') {
                webinars.Webinar_Attendees__c = newwebAttendees;
            } else {
                webinars.nRichment_Attendees__c = newwebAttendees;
            }


        insert(webinars);

    }
Ho do i convert "newwebDate" from 12/20/2014 to a Date format to insert to a object with a field with date type?
Best Answer chosen by Christopher Pezza
Christopher PezzaChristopher Pezza
I Ended up getting this to work needed to set the format to string in apex class before outputing it to a string/text field so that when it came back it new what to do and would parse everytime

All Answers

srlawr uksrlawr uk
You appear to already have it in your code? using the parse method from the date library
http://www.salesforce.com/us/developer/docs/dbcom_apex230/Content/apex_methods_system_date.htm

if newwebDate is a string of value '12/20/2014' and you are in the correct (US?) localle, newestWebDate should be a valid date field to pass into your object.

Does the above code not work for you though? If not, what errors are you getting? Are you sure the field is a Date, and not a DateTime?
Christopher PezzaChristopher Pezza
I Ended up getting this to work needed to set the format to string in apex class before outputing it to a string/text field so that when it came back it new what to do and would parse everytime
This was selected as the best answer