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
Abhinav GuptaAbhinav Gupta 

Does convertTimezone function ever works ?

I tried calling this function from both APEX and WS API, with a simplest soql fragement mentioned in salesforce docs itself i.e. 

 

SELECT convertTimezone(CreatedDate) FROM Opportunity

 

I always got this error : MALFORMED_QUERY: Invalid aggregate function: convertTimezone

 

How does this guy works ?

Best Answer chosen by Admin (Salesforce Developers) 
Mark SFMark SF

Hi,

 

The doc indicates that you can only use convertTimezone() in a date function, such as HOUR_IN_DAY.

 

For example:

 

SELECT HOUR_IN_DAY(convertTimezone(CreatedDate)), SUM(Amount)
FROM Opportunity
GROUP BY HOUR_IN_DAY(convertTimezone(CreatedDate))

 

The query you mention is mentioned as a query that does not work. From doc:

 

The following query doesn't work because there is no date function.

 SELECT convertTimezone(CreatedDate) FROM Opportunity

 

All Answers

Mark SFMark SF

Hi,

 

The doc indicates that you can only use convertTimezone() in a date function, such as HOUR_IN_DAY.

 

For example:

 

SELECT HOUR_IN_DAY(convertTimezone(CreatedDate)), SUM(Amount)
FROM Opportunity
GROUP BY HOUR_IN_DAY(convertTimezone(CreatedDate))

 

The query you mention is mentioned as a query that does not work. From doc:

 

The following query doesn't work because there is no date function.

 SELECT convertTimezone(CreatedDate) FROM Opportunity

 

This was selected as the best answer
Abhinav GuptaAbhinav Gupta

Thanks Man, I was in super hurry that time. So just copied to the SOQL snippet and tried running it :)