• Follow us on Twitter
  • Join our Facebook Group
  • Join me on Google Plus
  • Add me on Linkedin
  • RSS
Welcome to the Delivered Innovation blog! close

  • Home
  • Cloud Computing
  • Salesforce
  • DI News & Events
  • Force.com Tips

Tag Archive for: Apex

Force Feed 2-13-2012

0 Comments/ in Cloud Architecture / by Delivered Innovation
February 13, 2012

Force.com Streaming API and Chrome Desktop Notifications
@abhinavguptas
How to set up PushTopics and get real-time chrome desktop notifications.

REST API Cheat Sheet: It’s Only Cheating if You’re Taking a Test
@forcedotcom
Force.com added a REST API cheat sheet to their library of cheat sheets.

Tip: Using Decimal Class with Strings in Apex
@abhinavguptas
Try storing your queried number field as a specific Type(Decimal) in a local variable, which will save you from any accidental code API version upgrade from breaking the existing code.

Sinatra, Force.com and Heroku- In Perfect Harmony
@metadaddy
A cookbook recipe that shows how to call the REST API from a Ruby Sinatra app.

Advanced Reporting and Dashboards in Salesforce: Google Visualization with Visualforce
@sfunearthed
Get started with Google Visualization API’s.

Force Feed 1-16-2012

0 Comments/ in Cloud Architecture / by Delivered Innovation
January 16, 2012

Multiselect Picklist Jquery Plugin for iPad and Desktop Browsers
@abhinavguptas
How to develop a multi-row and multiselect picklist that looks similar in both a desktop and iPad browser.

Integrating Google Maps in Salesforce
@forceguru
How to show the location of your Account in Google Maps within Salesforce.

SOQL Offset in Spring ’12
@cloudysan
“OFFSET” clause in Spring ’12 allows you to paginate through your result set directly in SOQL.

Resolved: “Field is not writeable: Sobject_Share.RowCause”
@abhinavguptas
How to fix a problem that comes with Apex managed sharing.

Create a Custom Web Form Handler With Force.com Sites

0 Comments/ in Force.com Platform Tips / by Michael Topalovich
December 2, 2011

No doubt you’ve run into this also…we needed a form handler that captured data for sObjects other than Cases or Leads (e.g. custom objects), we did not want to redirect visitors to a new page upon form submission, and our functional requirements were more complex than what the standard Salesforce form handlers could support. The standard Salesforce Web-to-Lead and Web-to-Case form handlers were not an option, so we had to create our own custom web form handler. And because we wanted to keep everything on Force.com, we decided to build this solution using VisualForce pages and an Apex controller served by Force.com Sites. We developed an alternative solution and wanted to share it with the community in the event it could help others.

Use case

You want to capture form data directly in Salesforce from either a VisualForce page served Force.com Sites or from an externally hosted page, but the standard Web-to-Lead or Web-to-Case web handlers do not meet your exact requirements. You may also be using custom JavaScript forms that post data using AJAX, and do not want to blindly pass data to a form handler that will not provide a return to indicate success or exceptions.

Ultimately, we wanted to expose our form handler so it could also be accessed by any of our forms on the web (Force.com Sites as well as others such as our WordPress blog, which uses an HTML / PHP-based form to collect data).

So, here’s what we did

To begin, you need to ensure that Force.com Sites is setup correctly if it is not already.  You can find information on creating and maintaining Force.com Sites here or here.  In our case, we created a “utility” Force.com Site so that we could keep the pages separate from our main Force.com Sites web pages.  We also concealed the Force.com Sites utility subdomain in our custom Site.URLRewriter implementation to avoid AJAX cross-domain issues, but that is a discussion for a future post.

You will need to code up a VisualForce Page and an Apex class to serve as a custom controller to capture the form data and cast values to specific fields in the target sObject.  The VisualForce page itself is very simple in its construct…essentially it will serve two purposes:

  1. Perform a specific Action that calls a PageReference method in the custom controller when the page is invoked.
  2. Return a value in a format that the process calling the form handler is expecting.  In our case, our AJAX method is expecting a JSON object with the result of the form submission (success or otherwise).

This is what the VisualForce page for the form handler that we use for www.deliveredinnovation.com looks like:

<apex:page cache="false" controller="formHandlerSample" action="{!processForm}"  showheader="false" contentType="application/jsonrequest" >
 { success: {!success} }
 </apex:page>

The elements of this page to take note of:
  1. The ‘controller’ attribute is the custom Apex class that contains the logic that will process the contents of the web form
  2. The ‘action’ attribute is the PageReference method contained in the Apex class that will process the form data and generate the required return string
  3. Because our AJAX script is looking for a JSON object to be returned, we declared the contentType of ”application/jsonrequest.” You may find that you need to return XML, HTML, or other text, so update this attribute to suit your specific requirements.

The form handler code:

public class formHandlerSample {
public Map<String, String> urlParams;
public String Error {get; set;}
public Lead formLead = new Lead();
   
public formHandlerSample() {
urlParams = ApexPages.currentPage().getParameters();
}
public Boolean Success {
get { 
if(Success == null) { 
Success = false;
}
return Success; 
} 
set;
}
public void processLead(Map<String, String> formFields) {
if(formFields.size() > 0) {
try {
for(String fieldKey : formFields.keySet()){
if(fieldKey != null && fieldKey != 'null'){
if(fieldKey == 'FirstName'){
formLead.FirstName = formFields.get(fieldKey);
}
if(fieldKey == 'LastName'){
formLead.LastName = formFields.get(fieldKey);
}
if(fieldKey == 'Title'){
formLead.Title = formFields.get(fieldKey);
}
if(fieldKey == 'Company'){
formLead.Company = formFields.get(fieldKey);
}
if(fieldKey == 'Phone'){
formLead.Phone = formFields.get(fieldKey);
}
if(fieldKey == 'Email'){
formLead.Email = formFields.get(fieldKey);
}
if(fieldKey == 'Description'){
formLead.Description = formFields.get(fieldKey);
}
}
}
upsert formLead;
Success = true;
}
catch(System.Exception e) {
System.debug('Houston, you have a problem: ' + e);
Success = false;
Error = String.ValueOf(e);
}
}
else {
Success = false;
Error = 'No form fields received';
}
}
public PageReference processForm(){
processLead(urlParams);
return null;
}
}

Questions?  Suggestions?  Leave us a comment or email us directly at Blog [at] DeliveredInnovation.com.


Force Feed 11-21-2011

0 Comments/ in Cloud Architecture / by Delivered Innovation
November 21, 2011

Happy Thanksgiving week! Before you begin your holiday travels, make sure you catch up on all the latest Salesforce and Force.com news below.

Working Smarter with the New Developer Console
@quintonwall
The Developer Console is a much quicker way to navigate objects, triggers, and code than the traditional Setup menu.

Force.com ESAPI v0.5 & Death of Apex-CRUD-FLS-Validator API
@abhinavguptas
Apex-CRUD-FLS-Validator project is no longer available.

Insanely Simple Python REST Script
@joshbirk
Code for a command line application that opens a browser to handle OAuth, grabs the tokens, does a SOQL query in REST and displays the results.

Email AutoComplete (using jQuery)
@arrowpointe
Q&A for using Email to Case Premium email application.

Weekend Projects: Force.com Arduino, Ruby & Trains
@ReidCarlberg
Digging deeper into “The Internet of Things” and experimenting with Arduino.

XCollections- Use Custom Apex Classes in Map & Set
@abhinavguptas
From now on, XCollections will be available as “collections” in Apex-commons.

A Database.com/Force.com Foreign-Data Wrapper for PostgreSQL
@metadaddy
Patterson writes his first Python script, “a Multicorn foreign-data wrapper for database.com.”

Force Feed 11-14-2011

0 Comments/ in Cloud Architecture / by Delivered Innovation
November 14, 2011

Self Explanatory Naming Convention for Your Apex Classes
@abhinavguptas
Special naming convention suggestions for your Apex classes.

Winter ’12 Release Notes- Updates for the Weeks of October 31 and November 7th
@forcedotcom
Major updates include delayed release of customers in private Chatter groups, free Chatter data storage, and two new tipsheets.

Know Your Limits
@forcedotcom
The Salesforce Limits Quick Reference Guide is updated when new limits are added after a new release, and has two main sections: Salesforce Application Limits and Force.com Platform Limits.

Calling the Force.com APIs from Google OAuth 2.0 Playground
@metadaddy
A short video on how to get OAuth 2.0 Playground to work with Force.com.

A Real Controller for Visualforce Charting
@Alderete_SFDC
A realistic method for assembling your data to feed to a Visualforce chart.

Bending Salesforce.com Quotes to Your Will
@DarthGarry
How to get the most out of your salesforce.com Quotes.

Decoding Salesforce: Part 3
@MikeGerholdt
Third part of the “Decoding Salesforce” series on how to decode links in Salesforce.

Force Feed 9-26-2011

0 Comments/ in Cloud Architecture / by Delivered Innovation
September 26, 2011

A snapshot of all the Force.com and Salesforce related articles from the previous week.

Validation Rules Using ‘AND’ ‘OR’ Functionality Within Salesforce.com
How to use ‘and’ and ‘or’ functionality within the Validation rule.

Adding More CRUD FLS Security to Your Salesforce Apps with New “Validator” API
@abhinavguptas
Gupta discusses the a new Apex API, “Apex CRUD FLS Validator.”

Is Apex System.runAS() Not Resetting the Context for CRUD/FLS Changes in Profile?
@abhinavguptas
A possible bug in System.runAS().

Video-Connect Your Clouds with Force.com from Dreamforce 11
@jeffdonthemic
A video of Jeff Douglas’s Dreamforce presentation about integrating Force.com apps with other cloud platforms.

Dependency Injection for Ease in Testing Apex WebService Callouts
@abhinavguptas
If you use Http Restful classes, testing the callouts is not allowed in Apex. Here are some ways to handle the restriction.

SF Uploadify- A Cool Way to Upload Multiple Files in Salesforce
@sfunearthed
Uploadify is a great way to upload multiple files in Salesforce.

Search Suggestions Available Now on the Force.com Discussion Boards
@forcedotcom
New search feature on the Force.com Discussion Board.

Oh the Weather Outside… hmm, Not Quite Frightful…
@sfdc_nerd
A quick overview of new features in the Winter ’12 release.

Using OAuth 2.0 with Visualforce in Winter ’12
@cloudysan
Important OAuth 2.0 changes in Winter ’12.

Salesforce.com Sustainability Named in 2011 Carbon Disclosure Leadership Index
@sue_amar
Salesforce received a score of 85 after reporting their carbon emissions to the Carbon Disclosure Project, and as a result were highlighted as a leader in mitigating climate change.

Developing Visualforce with Your Browser
@joshbirk
How to create a Visualforce page using just your browser.

Page 1 of 212

Salesforce CRM, Force.com, Cloud Computing: Application and System Design

Latest Posts

  • Doing Business in the CloudApril 10, 2012, 12:22 pm
  • Delivered Innovation Co-Hosts ITA “State of the Cloud” EventFebruary 22, 2012, 1:30 pm
  • Force Feed 2-20-2012February 20, 2012, 1:21 pm
  • Cloudup 2-17-2012February 17, 2012, 9:45 am
  • State of the Cloud Event RecapFebruary 16, 2012, 4:37 pm

Topics

  • Cloud Architecture (173)
  • Delivered Innovation News & Events (30)
  • Force.com Platform Tips (6)
  • Salesforce Architecture (32)

Follow us on Twitter

Follow @twitter

Latest Tweets

  • Up 38% from a year ago, http://t.co/JEY1hGq5 continues to grow. http://t.co/e7q7MztA
    May 17, 2012 - 3:24 PM
  • RT @Benioff: Congrats salesforce on an amazing quarter. The fastest growing software company of our size! 38%! $3B guide! http://t.co/L ...
    May 17, 2012 - 3:05 PM
  • We have a couple new Apps coming; look forward to giving you a peek soon.
    May 17, 2012 - 12:44 PM
  • Cloud is a corporate strategy, not a tactical solution http://t.co/QltTfDFz
    May 10, 2012 - 7:45 AM
  • Chicago #cloudforce - how fast the day goes... http://t.co/YjRI1vp3
    May 4, 2012 - 9:47 AM

Force.com VAR: Value Added Reseller Partner

Salesforce.com Consultant: Registered Consulting Partner

Salesforce.com ISV: Independent Software Vendor Partner

Tags

#df11 Amazon Apex AppExchange Appirio Chatter cloud Cloud Computing Cloudforce cloud security Coghead Delivered Innovation News Dreamforce ExtJS facebook Force.com Gartner Google heroku IaaS IBM Interop ITA IT service delivery Jonathan Sapir Marc Benioff Michael Topalovich Microsoft Oracle PaaS Platform as a Service public cloud SaaS Salesforce Salesforce.com Sencha SOA Social Media Software as a Service Spring '12 the cloud twitter VisualForce Vmware Winter '12

Salesforce CRM, Force.com, Cloud Computing: Application and System Design


View Larger Map

Delivered Innovation
688 N. Milwaukee Ave #202
Chicago, IL 60642
888.645.2604

Delivered Innovation

  • Delivered Innovation Home
  • DI on AppExchange
  • DI on Facebook
  • DI on Google+
  • DI on LinkedIn
  • DI on Tumblr
  • DI on Twitter
© Copyright - Delivered Innovation Blog - Wordpress Theme by Kriesi.at