Category: Apex
Attach a PDF to a Record in Salesforce
July 14th, 2010, 7 Comments
Salesforce.com makes it extremely easy to generate PDF documents on the fly by simply using the renderAs=”pdf” attribute for the <apex:page> component. It’s also a snap to attach these PDFs to records as Attachments. Below is a small Visualforce page and Controller that generates a PDF and saves it to an Account. Note: there is [...]
Building a Dynamic Search Page in Visualforce
July 13th, 2010, 50 Comments
I brushed this code off and thought it might be useful to someone as a starting point for a dynamic search page. It has some cool functionality including passing search criteria via Javascript to the controller, search as you type, sorting of results by clicking on the column header plus much more. Hope you find [...]
Using RSA-SHA1 with Salesforce Crypto Class
July 6th, 2010, 6 Comments
This is a rather obscure post but it will definitely come in handy to someone trying to use the RSA-SHA1 algorithm with the Salesforce Crypto class. I’m spent the past two days trying to hook up OAuth using Apex and various Google Services. The standard HMAC-SHA1 algorithm is fairly straight forward with OAuth and Google [...]
Testing Salesforce.com Controller Extensions
June 2nd, 2010, 2 Comments
One thing that salesforce.com is working on is providing developers with a better testing environment. Salesforce.com requires you to write test cases to deploy your code to production but sometimes the process can be painful. Given the lack of something like jUnit you have to implement your own setup and test procedures. You’ll need to [...]
Uploading an Attachment using Visualforce and a Custom Controller
April 28th, 2010, 7 Comments
This is a follow up post to Uploading a Document using Visualforce and a Custom Controller showing an example for uploading an attachment for a Contact. The Visualforce page and Controller is very similar with a few exceptions. Attachments are different than documents and are only available for the following objects: Account Asset Campaign Case [...]
Create a New Record in Force.com Sites
April 27th, 2010, 10 Comments
So someone asked me yesterday for some code to allow external users to create contact records in Salesforce.com. They needed a simple form where people could enter the details and once submitted receive a confirmation of what information was entered. Here’s what the final page that was developed looks like. You can try the code [...]
Uploading a Document using Visualforce and a Custom Controller
April 22nd, 2010, 8 Comments
The Salesforce docs for the inputFile Visualforce component has an example of uploading a document using the Standard Controller. Here is a quick example of using a Custom Controller in case you want to make the upload process part of a larger transaction. Make sure you take a look at the finally block in the [...]
Enforcing Apex Security With Sharing Keywords
April 21st, 2010, 2 Comments
Security is a major foundation of the Force.com platform. Not only is security available declaratively but it is also baked into the Apex language itself. Most Apex scripts run in system context without respect to the current users permissions, sharing rules and field level security. This ensures that triggers and web services have access to [...]
Using AggregateResult in Salesforce.com SOQL
April 12th, 2010, 5 Comments
In Spring ‘10, Salesforce.com released new Apex functionality for aggregate functions in SOQL. These queries return an AggregateResult object which can be somewhat confusing at first. I’ve noticed quite a people searching my blog for this topic so I thought I’d throw some examples together. So the functions count(fieldname), count_distinct(), sum(), avg(), min() and max() [...]
Easily Search and Edit Records with Visualforce
April 7th, 2010, 15 Comments
I tend to over think Visualforce development sometimes and make it harder than it should be. Development with Force.com is surprisingly easy, elegant and quick. For example I recently needed to develop a way for the users to search for records and update specific values. Users should be able to search for records by keyword [...]












