I had to calculate number of week of the year based on a date field so i came across this and thought of sharing it
I saw this Salesforce community forum and got idea from there. The solution is for formula field.
I have used that in Apex using math methods and date methods
Formula: MOD(FLOOR( (Date__c -DATEVALUE("2006-01-01" ))/7),52)+1
I had to calculate number of week from the start date of year.
For the substraction part we cannot directly substract two dates so need to prepare instance of two dates and use daysbetween to find the difference.
Date todaydate = date.today();
Date todaydateinstance = date.newinstance(todaydate.year(), todaydate.month(), todaydate.day());
Integer currentyear = todaydate.year();
Date startDate = date.newinstance(currentyear, 01, 01);
integer numberDaysDue = startDate.daysBetween(todaydateinstance);
so by using this formula we can calulate in Apex
Integer numberOfWeek = math.MOD(math.FLOOR( ( numberDaysDue )/7),52)+1;
Salesforce, Cloud Computing, Force.com, salesforce.com, Apex and visualforce tips and tricks. Also some cool rocking fundas for your life, some management lessons, inspirational and motivational stories.
Monday, April 4, 2011
Saturday, March 26, 2011
How to show help text on Visualforce Page?
Just came across this so thought of sharing it
When we use or tag in visualforce page then the help text comes automatically but when you are using or then use the following to get the help text :
When we use
<apex:pageBlock>
<apex:pageBlockSection>
<apex:pageBlockSectionItem helpText="{!$ObjectType.objectName__c.Fields.fieldName__C.inlineHelpText}" >
<apex:outputLabel> FieldName </apex:outputLabel>
<apex:inputText> FieldName__c </apex:inputText>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
Wednesday, February 2, 2011
Attitude!!!!
1) Heavy rains remind us of challenges in life. Never ask for a lighter rain. Just pray for a better umbrella. That is attitude.
2) When flood comes, fish eat ants & when flood recedes, ants eat fish. Only time matters. Just hold on, God gives opportunity to everyone!
3) Life is not about finding the right person, but creating the right relationship, it's not how we care in the beginning, but how much we care till ending.
4) Some people always throw stones in your path. It depends on you what you make with them, Wall or Bridge?
Remember you are the architect of your life.
5) Every problem has (n+1) solutions, where n is the number of solutions that you have tried and 1 is that you have not tried. That’s life.
6) It’s not important to hold all the good cards in life. But it’s important how well you play with the cards which you hold.
7) Often when we lose all hope & think this is the end, God smiles from above and says, `relax dear its just a bend. Not the end. Have Faith and have a successful life.
8) When you feel sad, to cheer up just go to the mirror and say, `Damn I am really so cute` and you will overcome your sadness. But don’t make this a habit coz liars go to hell.
9) One of the basic differences between God and human is, God gives, gives and forgives. But human gets, gets, gets and forgets. Be thankful in life!
10) Only two types of persons are happy in this world. 1st is Mad and 2nd is Child. Be Mad to achieve what you desire and be a Child to enjoy what you have achieved! cheers.............!!!
2) When flood comes, fish eat ants & when flood recedes, ants eat fish. Only time matters. Just hold on, God gives opportunity to everyone!
3) Life is not about finding the right person, but creating the right relationship, it's not how we care in the beginning, but how much we care till ending.
4) Some people always throw stones in your path. It depends on you what you make with them, Wall or Bridge?
Remember you are the architect of your life.
5) Every problem has (n+1) solutions, where n is the number of solutions that you have tried and 1 is that you have not tried. That’s life.
6) It’s not important to hold all the good cards in life. But it’s important how well you play with the cards which you hold.
7) Often when we lose all hope & think this is the end, God smiles from above and says, `relax dear its just a bend. Not the end. Have Faith and have a successful life.
8) When you feel sad, to cheer up just go to the mirror and say, `Damn I am really so cute` and you will overcome your sadness. But don’t make this a habit coz liars go to hell.
9) One of the basic differences between God and human is, God gives, gives and forgives. But human gets, gets, gets and forgets. Be thankful in life!
10) Only two types of persons are happy in this world. 1st is Mad and 2nd is Child. Be Mad to achieve what you desire and be a Child to enjoy what you have achieved! cheers.............!!!
Sunday, January 23, 2011
Why it is necessary to know your weakness and guard it
No matter what our many strengths, just one weakness can prove more powerful than all of them!
A person’s single weakness is stronger than all his strengths! so true! Think about it. Just as a chain is only as strong as its weakest link, our strength is defined by our vulnerabilities, not our strong points. Not all the preparation in the world or intelligence can help you with any exam if you have an indecipherable handwriting that the examiner cannot figure out! Here your handwriting rather than your intelligence and hard work decide your future.
Similarly, you may have worked out a superb project with deep research and smart inputs, but if your timelines are not worked out and you cross the deadline, it is those couple of hours of delay that become the decisive factor! Similarly, you may be a great worker and a superb professional, but your loose tongue at an inappropriate moment may put paid to the rest of your capabilities! You will always find plenty of people around you not just willing, but eager to exploit your negative potential as displayed through that one weak link, that one vulnerability!
There is a category of people who get info after putting you at ease and assuring you they are totally with you. Most of us have in office a pseudo sympathizer who always emerges soon as he smells your moment of insecurity or misery. He always knows, for he is on the lookout. And sure enough, there he appears with oodles of sympathy and a smile, pumping you subtly for information. He gives subtle hints and encourages you to speak up. In a moment of weakness, you are most prone to let go and spill it all out. Satisfied, he runs back where he came from and uses the information to his own advantage before you realise! It is only later you realise he got you to bare all but never ever shared any of his or her own troubles! Your one weak moment could have done you a lifetime of harm!
Consider the power of weakness! Even the power of a relationship it is rightly said, lies with the one who cares less…never with the one who cares more and so has more at stake! So the weaker your love, the more powerful you are to mould or manoeuvre the relationship and your partner as and how you wish to! And yet, what a miserable power when the partner’s weakest link, his/her strong love for you, would be the biggest weapon you would use against them!
It is indeed our moments of weakness and weak points that we need to guard. It’s when you are most comfortable that you should be most guarded too. We are born with strengths that we can at best hone and understand, but an equally important task is to understand our weaknesses and work hard upon those. For these, our greatest weaknesses, if guarded and worked upon, have the potential of becoming our greatest strengths! Remember, the great Achilles was only as strong as his weak heel! Had that not been known, who could have killed him?
A person’s single weakness is stronger than all his strengths! so true! Think about it. Just as a chain is only as strong as its weakest link, our strength is defined by our vulnerabilities, not our strong points. Not all the preparation in the world or intelligence can help you with any exam if you have an indecipherable handwriting that the examiner cannot figure out! Here your handwriting rather than your intelligence and hard work decide your future.
Similarly, you may have worked out a superb project with deep research and smart inputs, but if your timelines are not worked out and you cross the deadline, it is those couple of hours of delay that become the decisive factor! Similarly, you may be a great worker and a superb professional, but your loose tongue at an inappropriate moment may put paid to the rest of your capabilities! You will always find plenty of people around you not just willing, but eager to exploit your negative potential as displayed through that one weak link, that one vulnerability!
There is a category of people who get info after putting you at ease and assuring you they are totally with you. Most of us have in office a pseudo sympathizer who always emerges soon as he smells your moment of insecurity or misery. He always knows, for he is on the lookout. And sure enough, there he appears with oodles of sympathy and a smile, pumping you subtly for information. He gives subtle hints and encourages you to speak up. In a moment of weakness, you are most prone to let go and spill it all out. Satisfied, he runs back where he came from and uses the information to his own advantage before you realise! It is only later you realise he got you to bare all but never ever shared any of his or her own troubles! Your one weak moment could have done you a lifetime of harm!
Consider the power of weakness! Even the power of a relationship it is rightly said, lies with the one who cares less…never with the one who cares more and so has more at stake! So the weaker your love, the more powerful you are to mould or manoeuvre the relationship and your partner as and how you wish to! And yet, what a miserable power when the partner’s weakest link, his/her strong love for you, would be the biggest weapon you would use against them!
It is indeed our moments of weakness and weak points that we need to guard. It’s when you are most comfortable that you should be most guarded too. We are born with strengths that we can at best hone and understand, but an equally important task is to understand our weaknesses and work hard upon those. For these, our greatest weaknesses, if guarded and worked upon, have the potential of becoming our greatest strengths! Remember, the great Achilles was only as strong as his weak heel! Had that not been known, who could have killed him?
Thursday, January 13, 2011
Salesforce Spring 11 Release

Check out the features of Spring 11 here
one of the most exciting feature is Revised Apex Governor limit. I am looking forward to it.
Some of the features going to be are:
Automated Process for chatter posts using Chatter triggers
Private chatter File sharing
Customizable error messages
Closer look at code's performance - System Log console execution summary
Revised Apex governor Limits
Visual workflows
Criteria based sharing - Data dependent sharing using clicks
Visual force page inline editing and Dynamic binding
I am very excited about Revised Apex Governor Limits:
2 important increase in limits are:
150 DML updates for a process
50000 records can be retrieved instead of 10000 records using SOQL query
Also Criteria based sharing is a feature I am looking forward to.
To refer to the release notes click on Release Notes Spring 11
Thursday, January 6, 2011
Remove the date link (beside input field)
When you use input field for date field then along with the input date picker box it also provides a link of today's date on the right side of input field.
This occupies the space and at times does not look good on your beautifully designed visualforce page.
We can remove that date link. I saw a post on cookbook about that and thought of sharing it.
They have used a component which removes the link using css.
Here's the link for that and its clearly explained in it:
Hide the Current Date Link on an Inputfield
This occupies the space and at times does not look good on your beautifully designed visualforce page.
We can remove that date link. I saw a post on cookbook about that and thought of sharing it.
They have used a component which removes the link using css.
Here's the link for that and its clearly explained in it:
Hide the Current Date Link on an Inputfield
Saturday, January 1, 2011
Scheduling Apex Class using System.schedule method
To schedule an Apex class, implements the Salesforce.com-provided interface Schedulable in your Apex class
example
now use the following system.schedule method for above class
open system log (click Your Name | Setup) and execute the below mentioned method so it will get scheduled.
here string s is in following pattern:
seconds, minutes, hours, dayofMonth, month, dayofWeek, year(optional)
The special characters are defined as follows:
Special Character Description
, Delimits values. For example, use JAN, MAR, APR to specify more than one month.
- Specifies a range. For example, use JAN-MAR to specify more than one month.
* Specifies all values. For example, if Month is specified as *, the job is scheduled for every month.
? Specifies no specific value. This is only available for Day_of_month and Day_of_week, and is generally used when specifying a value for one and not the other.
/ Specifies increments. The number before the slash specifies when the intervals should begin, and the number after the slash is the interval amount. For example, if you specify 1/5 for Day_of_month, the Apex class runs every fifth day of the month, starting on the first of the month.
L Specifies the end of a range (last). This is only available for Day_of_month and Day_of_week. When used with Day of month, L always means the last day of the month, such as January 31, February 28 for leap years, and so on. When used with Day_of_week by itself, it always means 7 or SAT. When used with a Day_of_week value, it means the last of that type of day in the month. For example, if you specify 2L, you are specifying the last Monday of the month. Do not use a range of values with L as the results may be unexpected.
W Specifies the nearest weekday (Monday-Friday) of the given day. This is only available for Day_of_month. For example, if you specify 20W, and the 20th is a Saturday, the class runs on the 19th. If you specify 1W, and the first is a Saturday, the class does not run in the previous month, but on the third, which is the following Monday. Tip: Use the L and W together to specify the last weekday of the month.
# Specifies the nth day of the month, in the format weekday#day_of_month. This is only available for Day_of_week. The number before the # specifies weekday (SUN-SAT). The number after the # specifies the day of the month. For example, specifying 2#2 means the class runs on the second Monday of every month.
you can monitor the scheduled Apex job by going to
click Your Name | Setup | Monitoring | Scheduled Jobs
for more info:
Salesforce link
example
global class newScheduledClass implements Schedulable
{
}
now use the following system.schedule method for above class
open system log (click Your Name | Setup) and execute the below mentioned method so it will get scheduled.
newScheduledClass m = new newScheduledClass();
String s = '1 30 1 10 2 ?';
system.schedule('Job Name', s, m);
here string s is in following pattern:
seconds, minutes, hours, dayofMonth, month, dayofWeek, year(optional)
| Name | Values | Special Characters |
| Seconds | 0–59 | None |
| Minutes | 0–59 | None |
| Hours | 0–23 | , - * / |
| Day_of_month | 1–31 | , - * ? / L W |
| Month | 1–12 | , - * / |
| Day_of_week | 1–7 | , - * ? / L # |
| optional_year | null or 1970–2099 | , - * / |
The special characters are defined as follows:
Special Character Description
, Delimits values. For example, use JAN, MAR, APR to specify more than one month.
- Specifies a range. For example, use JAN-MAR to specify more than one month.
* Specifies all values. For example, if Month is specified as *, the job is scheduled for every month.
? Specifies no specific value. This is only available for Day_of_month and Day_of_week, and is generally used when specifying a value for one and not the other.
/ Specifies increments. The number before the slash specifies when the intervals should begin, and the number after the slash is the interval amount. For example, if you specify 1/5 for Day_of_month, the Apex class runs every fifth day of the month, starting on the first of the month.
L Specifies the end of a range (last). This is only available for Day_of_month and Day_of_week. When used with Day of month, L always means the last day of the month, such as January 31, February 28 for leap years, and so on. When used with Day_of_week by itself, it always means 7 or SAT. When used with a Day_of_week value, it means the last of that type of day in the month. For example, if you specify 2L, you are specifying the last Monday of the month. Do not use a range of values with L as the results may be unexpected.
W Specifies the nearest weekday (Monday-Friday) of the given day. This is only available for Day_of_month. For example, if you specify 20W, and the 20th is a Saturday, the class runs on the 19th. If you specify 1W, and the first is a Saturday, the class does not run in the previous month, but on the third, which is the following Monday. Tip: Use the L and W together to specify the last weekday of the month.
# Specifies the nth day of the month, in the format weekday#day_of_month. This is only available for Day_of_week. The number before the # specifies weekday (SUN-SAT). The number after the # specifies the day of the month. For example, specifying 2#2 means the class runs on the second Monday of every month.
you can monitor the scheduled Apex job by going to
click Your Name | Setup | Monitoring | Scheduled Jobs
for more info:
Salesforce link
Subscribe to:
Posts (Atom)