Showing posts with label formula field. Show all posts
Showing posts with label formula field. Show all posts

May 30, 2012

Update Record From Formula Field

Recently an interesting implementation forced me to write this post, and may be many of you are already aware of this. There is a related list where I need to show a formula field, and on click of that field I need to change the status of that record.

Say case is related to account, and they are displayed in a related list on account. Now I want to change the status of any case which is related to an account. One way is to click on the case "edit", change the status and save it. I don't want to do this as it takes time and more button clicks. Another way is to provide a formula field as a hyperlink, and when that link is clicked status should be changed.

So for this create a formula field on Case ("UpdateStatus" for the reference) which will be a hyperlink and it will execute an visualforce page like this :

HYPERLINK("/apex/UpdateStatus?RecId=" + Id ,"Click To Change Status","_top")


Now add this formula field in case related list on account page layout, like this :



Now it's time to write a Visualforce page, so here is the code :


    
    
    
    



I know this is not the best approach to go with, and am open for any other solutions or findings.

May 27, 2011

Calculating Age From Birth Date

It looks very simple but a bit complicated question, what if I need to calculate the age from birth date in formula field whose return type is text?


Answer for Calculating Age From Birth Date :


Just copy paste this in your formula field, it will provide you the exact age calculated from birth date.
IF(MONTH(TODAY())>MONTH(DOB_API),YEAR(TODAY())-YEAR(DOB_API),IF(AND(MONTH(TODAY())=MONTH(DOB_API),DAY(TODAY())>=DAY(DOB_API)),YEAR(TODAY())-YEAR(DOB_API),(YEAR(TODAY())-YEAR(DOB_API))-1))
First simply if the month of present year is greater than date of birth than age will be calculated as the difference between present year and year of birth.


Secondly if the first scenario fails two options comes in my mind, if the month of present year is same then is day of birth is same or not so if day of birth is greater than or equals to day of birth than age is calculated as we have done in the first scenario.


Thirdly if above both scenarios fails that means month of present year and month of birth date is same but day of birth is smaller than day of present day. So age is calculated as the difference between present year and year of birth -1


See I told you it looks simple but bit complicated.


Cheers