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
Ami PandaAmi Panda 

How to insert date format while querying using apex class

 if(string.isBlank(searchKey)){
            lstOfGroup =  [select Id,Name,CreatedDate from Group where Id IN: lstOfGroupIds ORDER BY NAME ASC LIMIT 500];
            system.debug('GroupNames>>' + lstOfGroup);
            }

This "CreatedDate" should be in "dd-mm-yyy" format..
Raj VakatiRaj Vakati
Like this try 

 
if(string.isBlank(searchKey)){
            lstOfGroup =  [select Id,Name,FORMAT(CreatedDate) from Group where Id IN: lstOfGroupIds ORDER BY NAME ASC LIMIT 500];
            system.debug('GroupNames>>' + lstOfGroup);
            }

Reger this link

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_format.htm
Ami PandaAmi Panda
no this is not happening...
Raj VakatiRaj Vakati
try this
 
if(string.isBlank(searchKey)){
            lstOfGroup =  [select Id,Name,CreatedDate from Group where Id IN: lstOfGroupIds ORDER BY NAME ASC LIMIT 500];
            system.debug('GroupNames>>' + lstOfGroup.CreatedDate.format('dd-MM-yyyy'));
            }

 
Ajay K DubediAjay K Dubedi
Hi Ami,

Below Query can fulfill your requirements. Hope this will work for you.
List<Group> lstOfGroup = new List<Group>();
 if(string.isBlank(searchKey)){
        lstOfGroup =  [select Id,Name,CreatedDate from Group where Id IN: lstOfGroupIds ORDER BY NAME ASC LIMIT 500];
        for(Group grpObj : lstOfGroup)
        {
         System.debug('newdate----- '+ grpObj.CreatedDate.format('dd-MM-yyyy'));
        }
         system.debug('GroupNames>>' + lstOfGroup);
        }

Please mark this as best answer if this solves your problem.

Thank you
Ajay Dubedi