REST service for getServerTimestamp

How do i know the server timestamp using the salesforce REST services ?
Simialr to SOAP getServerTimestamp service, do we have any REST service ?

Answer

There is no such REST API available out of box for the same i guess .I had to implement my own custom REST API class for the same as below

@RestResource(urlMapping='/currentservertime')

 global with sharing class GetCurrentServerDateTime {

global class ResponseWrapper{
    public String currentServerTime;
}

@HttpGet
global static ResponseWrapper returnCurrentServerTime(){    

    dateTime newDate=system.now();      
    String dateInFormat = newDate.formatGMT('yyyy-MM-dd HH:mm:ss');
    ResponseWrapper resWrap=new ResponseWrapper();
    resWrap.currentServerTime=dateInFormat;

    system.debug('Server time being sent:'+dateInFormat);
    return resWrap;
}
}

The urI would be /services/apexrest/currentservertime

Attribution
Source : Link , Question Author : Azee Md , Answer Author : Mohith Shrivastava

Leave a Comment