Wednesday, July 22, 2009

How to Calculate the Number of Days in a Month

Step 1: Create a Formula Field (Number)

Step 2: Paste this formula : DAY(DATE(YEAR(TODAY()),MONTH(TODAY())+1,1)-1)

Function :

Where MONTH(TODAY()) is the month for which you want to return the number of days, and YEAR(TODAY()) is the year. This function calculates the first day of the next month and subtracts 1, which equals the last day of the current month. The DAY function then gives you the day of the month.





Monday, July 20, 2009

Displaying Running Digital Clock

Scenario..

The technical support / customer service will raise a case on behalf the account user and follow up the case,
Whenver the technical support try to reach the case contact he/she want to know the current time of case contact.


So i have decided to display the running digital clock in case detail page:

some thing like this...

sceern shot of case detail page :



Step 1: Create a Picklist field in contact called
TimeZone__c with field values like ...
(GMT+05:30) India Standard Time (Asia/Calcutta)
(GMT-05:00) Eastern Daylight Time (America/New_York)
(GMT-11:00) Samoa Standard Time (Pacific/Pago_Pago)

Step 2: upload the clock images in static resources.

Step 3: Create a visualforce page


Apex Page :
<apex:page standardController="case" tabStyle="case" extensions="contact_clock">
<apex:form >

<table bgcolor="#c9c299">
<th><apex:image value="{!$Resource.hand}"/></th>
<th><apex:outputText value="Your Time " /></th>
<th width="5"></th>
<th>
<apex:image id="Uh1" value="{!h1}"/>
<apex:image id="Uh2" value="{!h2}"/>
<apex:image id="Um" value="{!$Resource.dgc}" />
<apex:image id="Um1" value="{!m1}"/>
<apex:image id="Um2" value="{!m2}"/>
<apex:image id="Us" value="{!$Resource.dgc}"/>
<apex:image id="Us1" value="{!s1}"/>
<apex:image id="Us2" value="{!s2}"/>
<apex:image id="Uampm" value="{!ampm}" />
<apex:actionPoller action="{!UserTime}"
rerender="Uh1,Uh2,Us1,Us2,Um1,Um2,Uampm,r1" interval="5" />
</th><th width="120" ><apex:outputText value="{!a}" id="r1" /></th>
<th><apex:image value="{!$Resource.hand}"/></th>
<th><apex:outputText value="Contact Time " /></th>
<th width="5"></th>
<th>
<apex:image id="Ch1" value="{!h1}"/>
<apex:image id="Ch2" value="{!h2}"/>
<apex:image id="Cm" value="{!$Resource.dgc}"/>
<apex:image id="Cm1" value="{!m1}"/>
<apex:image id="Cm2" value="{!m2}"/>
<apex:image id="Cs" value="{!$Resource.dgc}"/>
<apex:image id="Cs1" value="{!s1}"/>
<apex:image id="Cs2" value="{!s2}"/>
<apex:image id="Campm" value="{!ampm}" />
<apex:actionPoller action="{!ContactTime}"
rerender="Ch1,Ch2,Cs1,Cs2,Cm1,Cm2,Campm,Cr1" interval="5" />
</th><th width="120" ><apex:outputText value="{!a}" id="Cr1" /></th>
</table>
</apex:form>
</apex:page>





Apex Class:

public with sharing class contact_clock {
public contact_clock(ApexPages.StandardController controller) { }
String idr = System.currentPageReference().getParameters().get('id');
string urlr = 'https://na5.salesforce.com/resource/1246944823000/dg';
DateTime tall; Boolean flag; String temp,tempw,temph,tempm,sDate,ap,s1,s2,m1,m2,h1,h2,dt;
Public PageReference UserTime() {
flag = false; geta(); return null;
}
Public PageReference ContactTime() {
flag = true; geta(); return null;
}
public string geta() {
tall = Datetime.now();
if(flag == true){
contact con2 = [select TimeZone__c from contact where id in (select contactid from case where id=:idr)];
tempw = con2.TimeZone__c.substring(4,5);
if(tempw == '+'){temph = con2.TimeZone__c.substring(5,7);}else{
temph = con2.TimeZone__c.substring(4,7);
}
integer addh = integer.valueof(temph);
tempm = con2.TimeZone__c.substring(8,10);
integer addm = integer.valueof(tempm);
datetime newDateh = tall.addHours(addh);
datetime newDatem = newDateh.addminutes(addm);
sDate = newDatem.formatgmt('hh:mm:ss a MM-dd-yyyy');}else{
sDate = tall.format('hh:mm:ss a MM-dd-yyyy');}
s2 = sDate.substring(7,8);
s1 = sDate.substring(6,7);
m2 = sDate.substring(4,5);
m1 = sDate.substring(3,4);
h2 = sDate.substring(1,2);
h1 = sDate.substring(0,1);
ap = sDate.substring(9,11);
dt = sDate.substring(11);
return dt;
}
public string gets1() {
return urlr+s1;
}
public string gets2() {
return urlr+s2;
}
public string getm1() {
return urlr+m1;
}
public string getm2() {
return urlr+m2;
}
public string geth1() {
return urlr+h1;
}
public string geth2() {
return urlr+h2;
}
public string getampm() {
return urlr+ap;
}
}

Monday, June 15, 2009

Understand the structure of all the URLs in Salesforce

Important notes on the URLs in Salesforce:

Instances:

Salesforce’s organizations reside on multiple instances,

To find out what instance you’re on, once you logged into Salesforce, have a look at the address bar;

You’ll notice the URL starts with something like:

na1 - North America #1

na2 - North America #2

na3 - North America #3

na4 - North America #4

na5 - North America #5

emea - Europe, Middle East, Africa

ap - Asia, Pacific

cs2 - Sandbox #1

cs3 - Sandbox #2

https://xyz.salesforce.com

Where xyz is the name of the instance your organization is on.

Objects Objects’ code
Accounts 001
Contacts 003
Users 005
Leads 00Q
Cases 500
Solutions 501
Reports 00O
Opportunities 006
Campaigns 701
Products 01t
Setup Objects’ code
Setup
Apps 02u
Custom Labels 101
Packages 033
Workflow Rules 01Q
Tasks 01V
Email Alerts 01W
Field Updates 04Y
Outbound Messages 04k
Apex Classes 01p
Static Resources 081
Sites 0DM/o
S-Controls 01N
Home Page Layouts 02T
All Custom Report Types 070
Visualforce Pages 066
Email Templates 00X
Letterheads 016
Mail Merge Templates 01H
Analytic Snapshots 0A0
Approval Processes p/process/ProcessDefinitionSetup?
Email Services email/admin/listEmailServicesFunction.apexp?
Visualforce Components apexpages/setup/listApexComponent.apexp?
Roles setup/user/roleSplash.jsp?
Profiles setup/ui/profilelist.jsp?
Public Groups p/own/OrgPublicGroupsPage?
Queues p/own/OrgQueuesPage?
Sharing Settings p/own/OrgSharingDetail?
Company Information your org id
Storage Usage setup/org/orgstorageusage.jsp?id=your org id
Debug Logs p/setup/layout/ApexDebugLogEdit?
Triggers p/setup/layout/ApexTriggerList?type=Account
Contact Page Layout ui/setup/layout/PageLayouts?type=Contact
Search Layouts ui/setup/layout/ListLayouts?type=Account
Record Types ui/setup/rectype/RecordTypes?type=Account

Basic action URLs

Use the following URLs to perform the listed operations on a specific object. Note this is fundamental to then understand how to create internal custom links.

Object’s overview page

https://[instance].salesforce.com/[Objects’ code]/o

ie: https://emea.salesforce.com/001

Create a new record

https://[instance].salesforce.com/[Objects’ code]/e

ie: https://emea.salesforce.com/001/e

Edit a record

https://[instance].salesforce.com/[recordID]/e

ie: https://emea.salesforce.com/0037000000g9mK4/e

Clone a record

https://[instance].salesforce.com/[recordID]/e?clone

Delete a record

https://[instance].salesforce.com/setup/own/deleteredirect.jsp?delID=[recordID]

Followers