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
Nazeer AhamedNazeer Ahamed 

Week Number

How can we find find the week number of the given date.

 

Thanks.

werewolfwerewolf

How do you define "week number?"  If a year starts on a Wednesday, is that week 0 until Sunday?  Week 0 until the following Wednesday?  Week 1 until the following Wednesday?

 

"Week number" is not a well-defined term.

youcyouc

what data type you are using to define the "given date"? You'd better convert it to Date type.

 

If you set the date with Date type, then create a Canlendar, and set time to this date. Afterwards you can get either week number in month or week in year through Calendar.

 

The code looks like

 

 Calendar cal;
 cal = Calendar.getInstance();
 cal.setTime(date);
 week = cal.get(Calendar.WEEK_OF_MONTH); or week = cal.get(Calendar.WEEK_OF_YEAR);

shankhan22@gmail.comshankhan22@gmail.com

Is calendar a custom object or a standard object ?


 

youcyouc

Calendar is neither standard object nor custom object. It is a data type, like string, boolean, etc.

 

 

shankhan22@gmail.comshankhan22@gmail.com

Thanks for your response .

 

My organization needs to increase the day of  SLA  breach if there is a holiday set on the company calendar on that day.

For e.g... If the desired completion date of a task comes on a weekend (say Saturday) , then it should be extended by two days, i.e... The desired completion date should be that of Monday .

So how do I get hold of the calendar days or company's working days so that I can compare that in a workflow .

Is it possible through point n click (by creating a workflow or we need to do custom coding ?)

youcyouc

If you only need this function when creating the SLA or updating SLA, not real time, then you can actually create a trigger, compare it is saturday or sunday, then update the completion date field with added 1 day or 2 days. In the way, it won't work if your company also set nation holidays or some special free days. You need code in that case.

 

 

shankhan22@gmail.comshankhan22@gmail.com

That's true ... We have to consider the national holidays also .

So if we code , how do we capture calendar events ...

coz in your previous response u told that Calendar is a data type while I couldn't find that while coding or in any of the supporting docs .

werewolfwerewolf

OK, time to stop and do a fact check.

 

You're attempting to manage SLAs.  You don't have to write all of this from scratch!

 

Salesforce.com has a built-in Entitlement, Service Contract and SLA Process capability included with the Service Cloud license:

 

Getting Started With Entitlement Processes

 

You should definitely consider using this.  It respects Business Hours and holidays using Salesforce.com's built-in Business Hours capability, which you also should be looking at. If you have questions as to what license you have, ask your Salesforce.com account executive, but I assure you this is the most robust way to manage your SLAs in Salesforce.com.

 

If you need to perform some kind of custom arithmetic that respects your Business Hours and holidays, you should still use Salesforce.com's built-in Business Hours capability (Setup | Administration Setup | Company Profile | Business Hours), and use the built-in Apex class called BusinessHours to perform the math for you.  It will take any holidays into account.  Note that the Case object has a standard lookup field to Business Hours, but you can add a lookup to Business Hours from any object.