Monthly Archives: November 2009

Salesforce – VisualForce Pagination with Apex

Following are two posts from Jeff Douglas and Richard Vanhook nicely illustrating with sample code on how to develop the pagination using Apex.

Salesforce.com introduced the StandardSetController in Winter ‘09 and Jeff documents the new pagination feature as pretty powerful and easy to use with standard as well as custom objects. Read More @
http://blog.jeffdouglas.com/2009/07/14/visualforce-page-with-pagination/

Pagination in VisualForce is a frequently occurring requirement for force.com developers. While the platform includes a native api for pagination in the StandardSetController class, it’s fairly inflexible; especially for complex pagination. And just as important, the native api supports pagination with sObjects only, so if you want to show pages of “plain old apex objects”, you’re out of luck. In his blog entry, Richard introduces us to pagination in apex-lang via a concept called “paginators. Read More @
http://richardvanhook.wordpress.com/2009/08/03/visualforce-pagination-with-apex-lang/

Salesforce – Dreamforce Google Wave Invite

Attended the Dreamforce Google Wave sessions, and guess what got an Google Wave Invite.

Here’s your chance to give Wave a try for yourself. Enter your email address below and the last five digits of your Dreamforce badge below and we’ll send you an invite to give Wave a ride.

http://bit.ly/dreamforcewaveinvite

Submit a Form in Internet Explorer with Enter

Ran into an (other) interesting Internet Explorer bug. Seems that if you have a form with only a single text input, hitting the enter button will not submit the form in IE.

<form action="" method="post">
<fieldset>
<label for="user_name">User Name</label>
<input type="text" name="user_name" id="user_name" />
</fieldset>
<fieldset class="button">
<button type="submit" name="submit" id="submit" title="Verify User Name">Verify User Name</button>
</fieldset>
</form>

The solution is to hide an additional disabled input for IE to find, using IE conditional Comments and hiding it from view with some CSS.

<form action="" method="post">
<fieldset>
<!--[if IE]><input type="text" style="display: none;" disabled="disabled" size="1" /><![endif]-->
<label for="user_name">User Name</label>
<input type="text" name="user_name" id="user_name" />
</fieldset>
<fieldset class="button">
<button type="submit" name="submit" id="submit" title="Verify User Name">Verify User Name</button>
</fieldset>
</form>

Workbench in a Web Tab inside Salesforce.com for single sign-on

The Workbench has exposed an API to allow users to automatically log in to the Workbench by providing their Server URL and Session Id in the URL arguments. This can be to integrate the Workbench into a Web Tab directly in Salesforce for single sign-on into the Workbench.

To integrate the Workbench into your org, follow the instructions below:

  1. Login to Salesforce
  2. Setup | Create | Tabs | Web Tabs | New
  3. Choose Tab Layout (Full page width is recommended)

Define Content and Display Properties

  1. Tab Type: URL
  2. Tab Label: Workbench
  3. Tab Tab Style: Choose a style
  4. Content Frame Height (pixels): Choose the maximum amount available for your screen (you may have to edit this value to find the correct value for your screen)

Button or Link URL

  1. Button or Link URL (replace "<your_server>" with the web server the Workbench in installed): https://<your_server>/workbench/login.php?serverUrl={!API_Partner_Server_URL_150}&sid={!API_Session_ID}
  2. Encoding: Unicode UTF-8

Save

Salesforce – Steps to Schedule/Reschedule Apex (Apex Scheduler)

Steps to Schedule Apex

  1. Define Scheduled Apex Class
  2. global class scheduledMerge implements Schedulable{
    global void execute(SchedulableContext SC) {
    mergeNumbers M = new mergeNumbers();
    }}

  3. Run the system.schedule Anonymous Code to Schedule the Apex Class (Read More on System.Schedule @ http://tinyurl.com/yg2d7qj)
  4. Setup | Monitoring | Scheduled Jobs to list the above Scheduled Job

Steps to Update Scheduled Apex Code

  1. Delete the Scheduled Job from Setup | Monitoring | Scheduled Jobs
  2. Edit/Update the underlying Apex Class. (Save will result in “the class has pending jobs” error, if you haven’t deleted the Scheduled Job i.e., STEP1 is prerequisite for this STEP2)
  3. Run the Anonymous Code to Schedule the Apex Class (system.schedule)
  4. Setup | Monitoring | Scheduled Jobs to list the above Scheduled Job

HTML Email Tracking in Salesforce

Outbound HTML emails are tracked by default if your organization uses HTML email templates. You can select or deselect this setting at Setup | Customize | Activities | Activity Settings to control email tracking. If you disable email tracking, email tracking information for your organization is no longer stored. However, the HTML Email Status related list remains on page layouts and email tracking reports remain on the Reports tab.

After sending an HTML email, you can track the date it was first opened, the number of times it was opened, and the date it was most recently opened.

Salesforce.com – Apex Web Service Callout Using @future

Jeff

The addition of asynchronous Web service callouts to external services is a feature that developers have been requesting for quite awhile in Salesforce.com. Using the new @future annotation, your methods execute the callout when Salesforce.com has resources available. One of the great benefits is that it allows you to perform callouts during trigger executions.

Today, I developed the callouts from trigger. There are many limitations which I came across and which are documented very well by Jeff on his blog post http://blog.jeffdouglas.com/2009/03/16/restful-web-service-callout-using-post/

I kept on trying to use complex data types, unless i reached Jeff post and found that only primitive data types are supported in future methods. To paraphrase, following are the points to be taken note of when using the future annotation:

  • No more than 10 method calls per Apex invocation
  • No more than 200 method calls per Salesforce license per 24 hours
  • The parameters specified must be primitive dataypes, arrays of primitive datatypes, or collections of primitive datatypes.
  • Methods with the future annotation cannot take sObjects or objects as arguments.
  • Methods with the future annotation cannot be used in Visualforce controllers in either getMethodName or setMethodName methods, nor in the constructor.

Also good note of points about asynchronous call outs can be read at Salesforce Blog

  • Like any asynchronous method. the callout must be in a static method and return a void type.
  • The system executes the asynchronous call when it has available resources – this means that you can’t assume anything about when the call will be executed.
  • The asynchronous method executes in a different transaction context than the trigger. A failure of the callout will have no effect on the transaction controlling the trigger (i.e. changes will not be rolled back). You will have to build in suitable compensation logic yourself to account for any exceptions in the callout.
  • Keep the governor limits in mind when making callouts. We are constrained by the interface provided by the remote web service. If the remote web service were to provide any kind of batch processing interface, choose that instead of making individual calls. It helps avoid hitting the governor limits and will be more performant as well since there are fewer round trips to make.

Salesforce – Schedule Apex to run at any time interval

Following is the snippet of anonymous code which will help you to schedule your apex for any interval. The Time parameter is not well structured and because of it I had to put in efforts in compiling the time parameter.

Update (@23 Nov 2011) – Use below code to schedule apex class 10mins (change it as per your need) from now

String str = system.now().addMinutes(10).format(‘ss mm HH dd MM ? yyyy’);
System.schedule(‘Registration Report’, str , new scheduledApexClassName());

  

I am documenting all the parameters neatly, which will help you to schedule apex to run at any time interval even minutes. Below code executes Apex every 10 minutes.

scheduledApexClassName m = new scheduledApexClassName();

String seconds = ’0′; //Execute at Zero Seconds
String minutes = ’10,20,30,40,50′; //Execute at every 10th minute of hour
String hours = ‘*’; // Execute Every Hour
String dayOfMonth = ‘*’; // Execute Every Day of the Month
String month = ’11′; //Execute only in November(11)
String dayOfWeek = ‘?’; //Execute on all 7 days of the Week
String year = ’2009′; //Execute only for year 2009

//Seconds Minutes Hours Day_of_month Month Day_of_week optional_year
String sch = seconds + ‘ ‘ + minutes + ‘ ‘ + hours + ‘ ‘ + dayOfMonth + ‘ ‘ + month + ‘ ‘ + dayOfWeek + ‘ ‘ + year;
//String sch = ’0 10,20,30,40,50 * * 11 ? 2009′;

system.schedule(‘Registration Report’, sch, m);

Execute above code in system log i.e., execute above annonymous code and it will schedule your Apex Class.

For More Information on how to define a Schedule Apex Class refer http://na1.salesforce.com/help/doc/en/salesforce_winter10_release_notes.pdf#rn_162_apex_scheduler

Indian Animation Industry

In possible good news for a faltering animation industry in India, NASSCOM has forecasted that the industry will grow to USD 1 billion by 2012 from an estimated USD 494 million in 2008.

The report, released at the NASSCOM Animation & Gaming Summit 2009 in Hyderabad, outlines the key challenges for the animation and vfx markets. Noteworthy among them are: ‘the limited demand for animation due to limited promotional budgets and restricted theatrical distribution, scarcity of long-term financing for animated films, competition from foreign animation and restricted use of vfx in Bollywood.’

Interestingly, the animation entertainment segment (which includes feature films, direct-to-DVD, advertising and TV) accounted only 22% of the total market in 2008; while vfx accounted for a mere 13% of the pie. As of today several animation films are in the pipeline for release next year. Biren Ghose, Chairman of NAGFO, who recently joined Paprikaas as General Manager, said, “Not many of the 15 or so animation films that have been announced will release next year.”

On a positive note, he said, “Visual effects (vfx) is an emerging market. About 8-12% of a movie’s budget is spent on vfx. Despite questions raised about the failure of vfx-heavy movies, it has to be noted that Aladin’s vfx budget was only 16% (10-20 crores) of the total cost. In other countries, box-office revenues are small chunk of total profit made by a feature, but in India box-office collection plays a major part in the revenues.”

He also added that animation industry should adapt to Bollywood’s example of having restructured to a higher profitability model, post recession.

Salesforce – Adobe Flash Builder for Force.com Webinar

Force.com Adobe Flash Builder is a  jointly developed integrated development environment (IDE) that gives developers a single, powerful tool for building cloud-based rich Internet applications (RIAs).

:: View the recorded webinar on Force.com Adobe Flash Builder
http://wiki.developerforce.com/index.php/Tech_Talk:_Adobe_Flash_Builder_for_Force.com

:: Reference other resources
http://developer.force.com/flashbuilder
http://www.adobe.com/devnet/salesforce/index.html