-1

Actualy I'm inserting data into custom object through REST api

I got some time fields like date begin and date end fields

these two fields from api response

        <date-begin>2017-12-15T03:30:00.000+14:00</date-begin>
        <date-end>2017-12-15T04:30:00.000+14:00</date-end>

if i'm inseting these two fields into string fields on custom object it saves successfully.

but if i'm using datetime fields for inserting the above two fields then not nothing is saved.

This is my apex class


    global class XMLparserCopy{

    public string XMLString1 {get;set;}
    private list<Webinar__c> lstevents{get;set;}
    LightiningEd__Webinar__c adobeevent;
    public String strdate1;
    public String strdate;

    public XMLparserCopy(String XMLString){
        lstevents = new list<Webinar__c>();
        XMLString1 = XMLString;
        //XMLString = '<?xml version="1.0" encoding="utf-8"?><my-events><event sco-id="1290617895" type="event" icon="event" permission-id="host"><name>Adobe connect demo</name><domain-name>meet64541292.adobeconnect.com</domain-name><url-path>/demo/</url-path><date-begin>2017-11-02T19:30:00.000+05:30</date-begin><date-end>2017-11-03T18:45:00.000+05:30</date-end><expired>true</expired><duration>23:15:00.000</duration></event><event sco-id="1290640959" type="event" icon="event" permission-id="view"><name>salesforce demo</name><domain-name>meet64541292.adobeconnect.com</domain-name><url-path>/dmeosfsf/</url-path><date-begin>2017-11-02T19:30:00.000+05:30</date-begin><date-end>2017-11-02T19:45:00.000+05:30</date-end><expired>true</expired><duration>00:15:00.000</duration></event><event sco-id="1290643314" type="event" icon="event" permission-id="view"><name>Test</name><domain-name>meet64541292.adobeconnect.com</domain-name><url-path>/testadobe/</url-path><date-begin>2017-11-02T18:45:00.000+05:30</date-begin><date-end>2017-11-02T20:00:00.000+05:30</date-end><expired>true</expired><duration>01:15:00.000</duration></event><event sco-id="1292076280" type="event" icon="event" permission-id="view"><name>test1</name><domain-name>meet64541292.adobeconnect.com</domain-name><url-path>/test1/</url-path><date-begin>2017-11-08T18:00:00.000+05:30</date-begin><date-end>2017-11-08T19:00:00.000+05:30</date-end><expired>true</expired><duration>01:00:00.000</duration></event><event sco-id="1292084866" type="event" icon="event" permission-id="host"><name>TestEvent</name><domain-name>meet64541292.adobeconnect.com</domain-name><url-path>/testevent/</url-path><date-begin>2017-11-08T17:45:00.000+05:30</date-begin><date-end>2017-11-09T18:45:00.000+05:30</date-end><expired>true</expired><duration>1d 01:00:00.000</duration></event><event sco-id="1292411456" type="event" icon="event" permission-id="view"><name>Salesforce Demo1</name><domain-name>meet64541292.adobeconnect.com</domain-name><url-path>/salesforcedemo1/</url-path><date-begin>2017-11-09T20:15:00.000+05:30</date-begin><date-end>2017-11-10T21:15:00.000+05:30</date-end><expired>true</expired><duration>1d 01:00:00.000</duration></event><event sco-id="1300207930" type="event" icon="event" permission-id="view"><name>Dreamforce Event</name><domain-name>meet64541292.adobeconnect.com</domain-name><url-path>/dreamforceevent/</url-path><date-begin>2017-12-05T18:00:00.000+05:30</date-begin><date-end>2017-12-05T19:00:00.000+05:30</date-end><expired>false</expired><duration>01:00:00.000</duration></event></my-events>';
        DOM.Document doc=new DOM.Document();
        try{
            doc.load(XMLString);
            DOM.XmlNode rootNode=doc.getRootElement();
            parseXML(rootNode);
            lstevents.add(adobeevent);
            insert lstevents;
            System.debug('List of Events'+lstevents);
        }catch(exception e){

            system.debug(e.getMessage());            
        }
    }

    private List<Webinar__c> parseXML(DOM.XMLNode node){

        if (node.getNodeType() == DOM.XMLNodeType.ELEMENT){

            if(node.getName()=='event'){
                if(adobeevent!=null)
                    lstevents.add(adobeevent);
                adobeevent = new Webinar__c();

            }
            if(node.getName()=='name')

                adobeevent.name=node.getText().trim();
            if(node.getName()=='domain-name')

                adobeevent.LightiningEd__Registration_URL__c=node.getText().trim();

            if(node.getName()=='date-begin')

                adobeevent.LightiningEd__date_begin__c=node.getText().trim();
            if(node.getName()=='date-end')
                 adobeevent.LightiningEd__date_end__c=node.getText().trim();

}

Here i'm using LightiningEd__date_begin__c and LightiningEd__date_end__c fields are string fields for inserting

if I take datetime fields then I am not able to insert the records

Anybody having idea.

1 Answer 1

1

use date.valueOf(LightiningEd__date_begin__c ).I think this will solve the problem

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .