You need to sign in to do that
Don't have an account?
Devendra_07
time is not converted on salesforce custom site
Hello,
I have created a custom site for guest users, and I'm displaying a VF page. On that VF page, I'm doing a conversion of different timezones on the basis of selected timezone. Ex: Org follows Asia/Kolkata timezone, on the UI I'm displaying all the timezones. So, when a customer selects the date and timezone, it is converting the org timezone to the selected timezone. The problem I'm facing is: It is working fine when VF page is previewed but doesn't work on a custom site. Time is not converted as expected.
Ex: On VF page :
Date selected --> 10 June 2020
Time Zone selected --> Asia/Tokyo.
After conversion --> 8AM (IST) is converted to 11:30 (Asia/Tokyo).
But on the custom site:
Date selected --> 10 June 2020
Time Zone selected --> Asia/Tokyo.
After conversion --> 8AM (IST) is converted to 13:30(Asia/Tokyo).
P.S - I have given all the required permissions to the guest user profile.
Snippet used:
BusinessHours bh = [SELECT ID,SundayStartTime,SundayEndTime FROM BusinessHours WHERE IsDefault = TRUE LIMIT 1];
Date dt = Date.newInstance(year,month,datez);
Timezone tz = Timezone.getTimeZone(selectedtimezone);
Datetime gmt = DateTime.newInstance(dt,bh.SundayStartTime);
Datetime convertedTime = gmt.addSeconds(tz.getOffset(gmt)/1000);
Please let me know the reason/explanation.
Thanks.
I have created a custom site for guest users, and I'm displaying a VF page. On that VF page, I'm doing a conversion of different timezones on the basis of selected timezone. Ex: Org follows Asia/Kolkata timezone, on the UI I'm displaying all the timezones. So, when a customer selects the date and timezone, it is converting the org timezone to the selected timezone. The problem I'm facing is: It is working fine when VF page is previewed but doesn't work on a custom site. Time is not converted as expected.
Ex: On VF page :
Date selected --> 10 June 2020
Time Zone selected --> Asia/Tokyo.
After conversion --> 8AM (IST) is converted to 11:30 (Asia/Tokyo).
But on the custom site:
Date selected --> 10 June 2020
Time Zone selected --> Asia/Tokyo.
After conversion --> 8AM (IST) is converted to 13:30(Asia/Tokyo).
P.S - I have given all the required permissions to the guest user profile.
Snippet used:
BusinessHours bh = [SELECT ID,SundayStartTime,SundayEndTime FROM BusinessHours WHERE IsDefault = TRUE LIMIT 1];
Date dt = Date.newInstance(year,month,datez);
Timezone tz = Timezone.getTimeZone(selectedtimezone);
Datetime gmt = DateTime.newInstance(dt,bh.SundayStartTime);
Datetime convertedTime = gmt.addSeconds(tz.getOffset(gmt)/1000);
Please let me know the reason/explanation.
Thanks.
Can you try checking if the issue is specific to a browser or a specific site?
If possible can you try posting the code so that I can check in my dev org as well.
Regards,
Anutej
Below is some code that is being used for timezone conversion. I'm just trying to show the business hours according to the selected timezone. Business hours have been set between 8AM - 4PM (IST).
Everything is working fine on lightning component but when we embed comp. into VF page and use it on a custom site, time conversion doesn't work as expected.
Custom Site --> https://tmmeetingschedular-developer-edition.ap17.force.com/schedulemeeting/
@AuraEnabled
global static timezoneConvWrapper getBusinessHours(Date selectedDate, String selectedtimezone){
DateTime myDateTime = (DateTime) selectedDate;
String day = myDateTime.format('EEEE');
System.debug('It is: '+day);
List<DateTime> businessHours = new List<DateTime>();
Map<String,String> timeMap = new Map<String,String>();
List<Holiday> holidays = [SELECT activityDate FROM Holiday];
Boolean isHoliday = false;
Integer year = selectedDate.year();
Integer month = selectedDate.month();
Integer datez = selectedDate.day();
Date dt = Date.newInstance(year,month,datez);
Timezone tz = Timezone.getTimeZone(selectedtimezone);
timezoneConvWrapper wrapper = new timezoneConvWrapper();
if(holidays.size() != NULL || holidays.size() >0){
for(integer i=0;i<holidays.size();i++){
if(holidays[i].activityDate == selectedDate){
isHoliday = TRUE;
}
}
}
if(!isHoliday){
if(day == 'Sunday'){
BusinessHours bh = [SELECT ID,SundayStartTime,SundayEndTime FROM BusinessHours WHERE IsDefault = TRUE LIMIT 1];
if(bh.SundayStartTime == null){
return null;
}else{
Datetime gmt = DateTime.newInstance(dt,bh.SundayStartTime);
Datetime convertedTime = gmt.addSeconds(tz.getOffset(gmt)/1000);
String a = string.valueOfGmt(convertedTime);
String b = String.valueOf(bh.SundayStartTime);
timeMap.put(a,b);
businessHours.add(convertedTime);
for(integer i=0;bh.SundayStartTime<bh.SundayEndTime;i++){
convertedTime = convertedTime.addHours(1);
a = string.valueOfGmt(convertedTime);
businessHours.add(convertedTime);
bh.SundayStartTime = bh.SundayStartTime.addHours(1);
b = String.valueOf(bh.SundayStartTime);
timeMap.put(a,b);
}
system.debug('businessHours Sunday : '+businessHours);
wrapper.dateTimeMap = timeMap;
wrapper.dateTimeList = businessHours;
}
}else if(day == 'Monday'){
BusinessHours bh = [SELECT ID,MondayStartTime,MondayEndTime FROM BusinessHours WHERE IsDefault = TRUE LIMIT 1];
if(bh.MondayStartTime == null){
return null;
}else{
Datetime gmt = DateTime.newInstance(dt,bh.MondayStartTime);
Datetime convertedTime = gmt.addSeconds(tz.getOffset(gmt)/1000);
String a = string.valueOfGmt(convertedTime);
a = a.substring(11, 16);
String b = String.valueOf(bh.MondayStartTime);
timeMap.put(a,b);
businessHours.add(convertedTime);
for(integer i=0;bh.MondayStartTime < bh.MondayEndTime;i++){
convertedTime = convertedTime.addHours(1);
a = string.valueOfGmt(convertedTime);
a = a.substring(11, 16);
businessHours.add(convertedTime);
bh.MondayStartTime = bh.MondayStartTime.addHours(1);
b = String.valueOf(bh.MondayStartTime);
timeMap.put(a,b);
System.debug('time in string: '+a + ', convertedtime: '+convertedTime);
}
system.debug('businessHours Monday : '+businessHours);
wrapper.dateTimeMap = timeMap;
system.debug('wrapper.dateTimeMap: '+wrapper.dateTimeMap);
wrapper.dateTimeList = businessHours;
return wrapper;
}
}
//// Upto saturday
else if(day == 'Saturday'){
BusinessHours bh = [SELECT ID,SaturdayStartTime,SaturdayEndTime FROM BusinessHours WHERE IsDefault=TRUE LIMIT 1];
if(bh.SaturdayStartTime == null){
return null;
}else{
Datetime gmt = DateTime.newInstance(dt,bh.SaturdayStartTime);
Datetime convertedTime = gmt.addSeconds(tz.getOffset(gmt)/1000);
String a = string.valueOfGmt(convertedTime);
a = a.substring(11, 16);
String b = String.valueOf(bh.SaturdayStartTime);
timeMap.put(a,b);
businessHours.add(convertedTime);
for(integer i=0;bh.SaturdayStartTime<bh.SaturdayEndTime;i++){
convertedTime = convertedTime.addHours(1);
businessHours.add(convertedTime);
bh.SaturdayStartTime = bh.SaturdayStartTime.addHours(1);
a = string.valueOfGmt(convertedTime);
a = a.substring(11, 16);
b = String.valueOf(bh.SaturdayStartTime);
timeMap.put(a,b);
}
system.debug('businessHours Saturday : '+businessHours);
wrapper.dateTimeMap = timeMap;
wrapper.dateTimeList = businessHours;
return wrapper;
}
}
}
return null;
}
2. Log while using VF page on Salesforce custom site: [EXTERNAL]|0052x00000286HY|schedulemeeting@tmmeetingschedular-developer-edition.ap17.force.com|(GMT+00:00) Greenwich Mean Time (GMT)|GMTZ
Can you please explain why i'm getting different GMT while using VF page and Salesforce Custom site ??