68 Results

RecordType Utility Apex Class

I like to group Apex methods by the object to which they apply. I find that this supports troubleshooting of code and ultimately reduces the amount of code in a given Salesforce organization. For example, every Salesforce developer that works in an Enterprise level organization or higher will find that more often than not they need to know the record types for a given object. [...]

Pass Values to New Opportunity Using Apex

Last year I wrote a post describing how to pass values to a new opportunity using the URL. This post is simply an alternative to accomplish the same goal of auto-populating values to a new record except using Visualforce and an Apex Class controller. For the purposes of our demonstration we will make some general assumptions about the values we want to pass to the new record. To keep it simple we plan on populating the Name, Stage and Close Date of the new opportunity. We will also make the logic flexible enough so that if Salesforce happens to pass additional information we will be able to include those key value pairs as well. [...]

Locale Aware DateTime Component

I am working with a client that is deploying some existing Visualforce pages to international Users. The Visualforce includes some Date and DateTime values so I checked them to make sure they would render appropriately for people accessing the logic internationally. It turns out that the original Visualforce code uses the <apex:outputText> tag to drive formatting for much of the Date/DateTime values within the pages. Therefore, I am converting the occurrences of each <apex:outputText> tag to the Visualforce component I built for rendering. [...]

UNABLE_TO_LOCK_ROW Error Message

I was recently developing some Apex logic and encountered the UNABLE_TO_LOCK_ROW error while running my Apex unit tests for the new code. This UNABLE_TO_LOCK_ROW error message can happen when unit tests update the same record(s) at the same time or when unit tests try to create records with duplicate index field values. One way to avoid this UNABLE_TO_LOCK_ROW error is to simply turn off parallel test execution. This can be accomplished via Setup > Develop > Apex Test Execution. [...]

Edit Link Override Visualforce Page

I just built a Visualforce application that people can use to associate a number of "child" records to a single "parent" record. Let's say that the application uses the Account object as the standard controller and then we extend the logic so that we can find, manipulate and link many Contact records. The functionality of the application is not important for this post but how we access the application is important. [...]

Error Handling in Visualforce with <apex:pageMessages>

A big part of building Visualforce pages is making sure that the human has a good experience while interacting with the page(s) you've designed. This means that you need to have a good way of handling errors when and if they occur. In this post I will highlight one of the simplest ways to handle an error by utilizing the apex:pageMessages tag within your Visualforce page. [...]

Pass Values to New Opportunity Using URL

Pass values to a new Opportunity via a custom button using nothing but the URL. This can be useful if you want to default some values on the detail page when new records are being created. It can save your Users some time so they don't need to fill out every field. It will also allow you to provide some guidance for values you want provided when new records are created in your organization. [...]

Apex Trigger Status Made Simple

Have you ever needed to deactivate a trigger for some maintenance activities on records or for a code deployment? At a high level, the act of activating/deactivating a trigger is simple. Go to your Salesforce sandbox, modify the status of the trigger and deploy the code. Depending on your unit test coverage for the trigger you may have to tweak the test class and include that in the deployment. [...]

Prevent Calendar Display When Page is Loaded

We've all seen those edit pages in Salesforce when you access the page and a date or date/time field calendar widget immediately pops up. Sometimes that's okay but sometimes we would like to prevent that from happening because we would prefer the focus to be on some other element of the page. As a Visualforce developer you can accomplish this with a very simple snippet of JavaScript. [...]

Contact Edit Visualforce Page

I was coaching a beginner developer recently and she had a simple question. "Why doesn't my Contact Edit Visualforce page look like the standard Contact Edit page?" She was trying to format the Salutation and First Name fields so that they were on a single line and in one column of a two column layout. The screenshot below illustrates the standard layout, which she was trying to mimic in her Visualforce page. [...]

Modify Profile Permissions Using Enhanced List Views

Often times developers will move an object from a Salesforce sandbox to a Salesforce production org using tools like Ant, change sets or the Eclipse IDE. Developers may not always include Profile permissions when they move their objects from org to org. This means that any Create, Read, Write or Edit (CRUD) settings for an object will be unspecified for all Profiles except their own when the object gets created in the target organization. [...]

Update to Partner Contact by Community User

Businesses that utilize Salesforce Communities for partners instead of the standard partner portal may find that partners have the ability to search for and find the Contact record that corresponds to their Community User record. It would be nice if salesforce.com did not allow for this visibility because the Partner User is technically unable to make updates to the Partner Contact record. If they click the "Edit" button for the Contact they will receive the Insufficient Privileges message. [...]

Do not create a new opportunity upon Lead conversion using Apex and Visualforce

My client has a use case where they want to convert a Lead but not create an Opportunity at time of conversion. The standard Lead conversion page is fine with the business owners but they want the "Do not create a new opportunity upon conversion" checkbox selected when the page is accessed by the Users in their org. This will allow Users to create an Opportunity in certain cases but default the option to false otherwise. [...]

Daily Processing For Permission Set Access

I came across a use case earlier this month where a Salesforce business owner needed to be able to role out some functionality in a series of waves. Basically, the business was planning on running a pilot with a subset of users for a period of time and then at some interval they planned on granting access to additional users. The business owners wanted to be able to maintain that access and they wanted to be able to turn it on easily. [...]

View Activities in Salesforce Communities

Here's the backstory... we customized a partner portal. Salesforce.com offers us access to the Communities pilot program in order to meet the immediate business needs regarding customization of the application that partners use. Salesforce.com indicates that Communities is an adequate yet superior product to partner portal and allows us to do some customizations, which were not possible in partner portal. Salesforce.com surprises us with licensing and functionality limitations, which were not evident during pilot. [...]

Salesforce Communities: Allow Partners to Delete

Salesforce releases Communities, which is a much needed improvement to the stoned-aged partner portal user interface. I took part in the pre-release and found that the new functionality comes with some positives and some negatives. One big negative that I found was the inability for Community Users to delete records. Salesforce.com provided a long list of reasons why partners should not be deleting records and why this basic functionality is not provided. But let's be serious... I am not going to field calls from partners because they need me or another admin in the org to remove records that they no longer need. After a week of taking these requests during the pilot, I decided to make the functionality available to Community Users - just because it would save me and those same partners some frustration. [...]

VLOOKUP Validation Example

As a Salesforce ISV partner I get leads dropped into my Salesforce org whenever someone on the AppExchange installs one of my applications. That automated process also creates a license record, which is a custom object (sfLma__License__c) that was installed via Salesforce's License Management Application. Anyway, the fact that Salesforce does this for my ISV is great but the only downside to this is that the standard workflow rule and email notification functionality does not fire when license records are updated or created via this AppExchange integration. [...]

Apex Test Method for Removing Scheduled Batches

Don't you really dislike when you go to deploy some code to a production Salesforce org and it fails because you forgot to unschedule a batch class? This is especially frustrating in a larger org where there is lots of code running and the deployment takes a long time due to the large number of @isTest methods that need to be run. I thought I would share some code that I wrote, which will remove any scheduled batch jobs and, therefore, avoid any issues with deployments in your orgs. Besides, who doesn't want to see more examples of @isTest Apex methods? [...]

Wrapper Class Example for Visualforce Page

I must admit that when I first heard about using a wrapper class in a Visualforce page I did not really grasp the concept. Reading the developer docs and reading other blogs didn’t really help either. It was only when I came across a practical use case that the concept really sunk in and I thought I would share that here for any other developers trying to make sense of the idea. [...]

Avoid Heap Size Limits in Visualforce Pages

I built this great Visualforce page where I display and allow for editing of many records at once. The initial business requirement was for only a few hundred records to be used in this application but, as usual, requirements morphed and now the business wants to be able to use this app for thousands of records. So guess what... we now encounter the "System.LimitException: Apex heap size too large" governor limit. WTF! [...]

Salesforce Unit Test Tip for Checking Trigger Status

Anyone with a lot of Apex code in their production Salesforce org knows that the more code you have the more tedious deploying new code to that org becomes. One of the orgs I work in has some triggers that get turned off and on for reasons that only the business owners understand. As any developer understands turning off a trigger is much easier than an Apex class, which is where we often encounter deployment issues. [...]

Clone Salesforce Records Using a Custom Button Or Link

Almost four years ago I wrote the first post for this blog. That post had to do with passing field values in a URL in order to populate those values on an edit page. What's interesting is that the original post still gets a ton of traffic. So I'd like to expand on that topic again in this post and illustrate how you can build on that original logic in order to do something useful. In this case, I want to create a custom button that will clone a User record and remove certain fields so that I don't have to fill out so much information when I create new Users. [...]

Salesforce Apex Code for DateTime Duration

I've been developing a lot of batch Apex routines lately. The nature of batch Apex is that it can run whenever resources are available and process many records while being more flexible with platform governor limits. So I might schedule a job to run and it could take anywhere from a few minutes to many hours. Many variables impact the run time of a batch routine. Things like the number of records being processed or platform resource availability. [...]

Apex Code Sample Illustrating How to Drop Leading Zeros

Here is an example regarding the use of the pattern and matcher methods in an Apex class. For this particular code sample I am using the methods to check a passed text string for the occurrence of leading zeros in the string and removing them when they exist. The code I have written here was actually used on a project where I had to validate that User records contained a valid EmployeeNumber value. And, as you probably know, this particular field is editable by users and is stored as text in the database. Rather than go through the trouble of creating another Number type field on the User object I thought it would be easier and less disruptive to simply check the value when I needed to reference it in any Apex logic. [...]

Apex Unit Test: SOQL Filter

Today I participated in an online meeting, which discussed some of the "best practices" for testing Apex code, Visualforce pages, etc. One of the topics that was pretty much skipped but came up during the Q&A portion of the meeting was regarding how to ensure that the test code you write refrains from grabbing any actual live production data and only grabs the records created to facilitate the test. They discussed one way to do this but I have another and I thought it could be useful to other developers. [...]

Yahoo! Modal Dialogs in Visualforce

I found this great post/tutorial (Modal Dialogs in Visualforce using the Yahoo! User Interface Library) regarding the use of the Yahoo! User Interface (YUI) Library within Visualforce pages. But what if you work for a business that uses Internet Explorer (IE) as the standard / supported browser across the enterprise? You get the security warnings dialog when accessing the Visualforce page, of course. [...]

Dynamic Salesforce Report from Custom Button

I recently attended the Buffalo Salesforce User Group meeting. During the session a guest speaker conducted a demo of some development he did for his company's production Salesforce org. One of the items he touched on that spurred a lot of discussion was a custom button he built to pass a value to a report from a detail page of a given record. The resulting discussion was surprising because I really didn't know that so many admins were unaware of the benefits of creating these custom buttons. And, after participating in the discussion, I thought that this would be a great topic for a blog post because there is so much that you can do if you understand this relatively simple trick. [...]

Visualforce Component for Locale Based DateTime Display

Sometimes, I really dislike Visualforce... Last week I spent a ton of time troubleshooting a display issue for a page that was built by another developer. The issue was that the DateTime field for an object was not displaying properly. It was showing the value in GMT and not the timezone of the user. After spending way too much time reviewing everything I decided to build a custom Visualforce component to eliminate the problem altogether. [...]

sObject Describe Result for Visualforce Picklist

More than a while ago, I wrote about populating query results to a picklist for use in a Visualforce page. That post receives a lot of traffic and I get some additional emails regarding that topic. So I thought I would put together another post similar to that one but with a bit of a twist. In the sample I will cover in this post I am going to show you how to use the methods for the Describe Result sObject in order to create picklists within Visualforce pages. [...]

Custom Salesforce Button to Execute JavaScript

I make everyone on my team track their time using a custom Time_Card__c object in our Salesforce org. At the end of each pay period I have to update the Status field on these Time_Card__c records to something and most often the status is set to 'Paid.' Since it can be frustrating to update many records repeatedly to the same value and some folks don't like using the Excel Connector or Data Loader to perform mass updates, I thought that it would be easier to create a custom button where I could select the records from a Time Card list view or Project Detail page related list and then click a button and have Salesforce update the records in mass via JavaScript. [...]

Create Custom Report Type for Salesforce Ideas

Have you rolled out the Ideas functionality for your Salesforce org? If so, do you have the need to report on the Ideas by profile or role or some other field? An administrator at one of the businesses I support contacted me and asked why he couldn't create a report to show the number of votes by specific Users in his org. The management team decided that they would hold a competition to see who is using the Ideas functionality the most and they weren't able to create a report to provide the details they were seeking. [...]

Pre-popoulate Salesforce Lookup Fields Using URL Parameters

A few years ago I wrote a post about how to populate information into Salesforce fields by navigating the User from page to page. I received a lot of good feedback on that post and the logic for it pretty much remains unchanged today. The intent of that original post was to identify how an administrator could use button overrides to get a User from one page to another and still auto-fill some of the details for the next page on behalf of the User. Go here to see my original post. [...]

Salesforce Apex Trigger to Reassign Contacts and Open Opportunities

Standard Salesforce functionality allows for the reassignment of Contacts and open Opportunities when the Account to which these records are associated is reassigned to a new User. Clicking the "[change]" link next to the Account Owner field on the Account detail page will allow you to step through a process by which you select a new Account owner and save the changes. Once the changes are made the system will go out and reassign all Contacts and all open Opportunities owned by the old Account Owner to the new Account Owner. This is useful and so automatic that you may not even be aware that it happens. [...]

Avoiding Salesforce Web-to-Lead Spam

Earlier this week I attended the Denver Salesforce User Group meeting. One of the attendees was a new user and asked the group if others were using the web-to-lead functionality. Some were capitalizing on this functionality but, to my astonishment, not everyone. Many of the folks that began discussing this topic expressed frustration over how to implement and concerns about spam. One of the respondents indicated that they went live with the functionality on one of their web forms but had to pull it down because they were receiving way too many spam leads. [...]

Enabling the Bulk API with the Salesforce Data Loader

Part of the Salesforce Winter '10 release was something that the release notes and folks at salesforce.com refer to as the Bulk API. Also, you may have read that the 'Bulk Loader' is now available and it will now take longer to count the records than it will to load them, blah, blah, blah... Since I work with customers that have large numbers of records I thought I would look into getting the 'Bulk Loader' and using it to tweak some 3 million account records in a Sandbox. [...]

Custom Picklist in Visualforce Page

Let's say that you're building a Visualforce page and you want to provide a picklist option for your users on the page. If the field where you want to store the selection is a picklist then you have no issue because the field definition will define that the page display a picklist when the Visualforce page is rendered. However, let's say that you want to display a picklist option based on a query from another object. How would you do that? [...]

Salesforce Extended Mail Merge

I was on a call today with a client that constantly uses the Mail Merge functionality of Salesforce. It is important for their business to send out a lot of direct mail pieces. Anyway, they were unaware of the Extended Mail Merge capability of Salesforce and it surprised me because they have been Salesforce subscribers for many years now. So I took a few moments to demonstrate the Extended Mail Merge features and I also thought that this would be a good topic to write about on the site. [...]

Whitelisting Trusted IP Ranges

As you know, salesforce.com has taken many steps to ensure that their app is secure. The primary security features call for the use of a security token appended to the standard Salesforce login credentials or a confirmation message to enable login from specific computers/laptops. For most Salesforce customers these security features were a welcomed addition but to developers these security features caused some headaches. [...]

Hiding & Displaying Buttons in the Page Layout using sControls

Lately I've been seeing more and more postings on many of the Force.com message boards around the use of buttons inside the Salesforce application. Primarily people are interested in passing information using buttons and in some cases hiding buttons when certain criteria are met. Since this seems to be a hot topic lately I thought I would share with you a simple way to accomplish the goal of displaying a button when certain criteria is met and otherwise hiding the button. [...]

Salesforce Custom Colors and Icons

I recently was asked about the custom colors and icons that we use for our Link Management Application and the person was wondering how they could incorporate the use of those colors into their sControls. Since I had to put all of that information together for our App, I decided why not share that with everyone as some type of reference? So here's a little background on why this information is useful. [...]

Mimic Task Subject Lookup in sControl

From time to time, there may be a need to mimic the lookup functionality from standard salesforce.com edit pages into a custom sControl. In this example, I am going to show you how to mimic the lookup field for "subject" that you would normally find on the Task edit page. The concepts covered in this example are built off some other concepts I've already done examples for on this site so please feel free to review some of our other examples prior to trying this one. [...]

Pre-populate Fields Using URL Parameters

For my example I am going to pre-populate some fields on the contacts object. Now the contacts object (like all salesforce objects) has what salesforce sometimes refers to as a front door for the URL. Quite simply the front door for the contacts tab is "/003/o". The front door for a new contact would be "/003/e". If you want to see what the front door is for any object simply click the tab for the object. The front door is the three characters directly following the ".salesforce.com/" portion of the URL while you are on the tab's "home" screen. Further examples; Opportunities home is "/006/o", Accounts home is "/001/o". If you want to add a new record for the object you simply change the "o" portion of the front door to an "e". I know I wrote that the front door was three characters but I think you get my drift here. [...]

Automated Exchange Rates in Salesforce.com

Reduce Repetitive Tasks, Eliminate Errors & Free Up Your Administrators.

Birthday Reminders for Salesforce.com

It might lead to a sale. Or it might make you feel good.