Zip to City & State Integration – Proof of Concept

March 11, 2009 by David Schach · 2 Comments
Filed under: salesforce.com 

Zip to State & City - Proof of Concept

This is proof that our newest project, an integration to retrieve the State and City based on a postal code, works... sometimes. Obviously not ready for public consumption yet.

 

Ubiquity Plugin for developer.force.com

February 5, 2009 by David Schach · 3 Comments
Filed under: Development 

Inspired by Gina Trapani’s release of a Ubiquity plug-in to search Lifehacker via Google, I used her code as a base (thanks, Gina) and created a Ubiquity plug-in to search developer.force.com.

Because developerforce uses Google’s technology to search its own site, I wanted to display the search results within the developer.force.com site instead of using Google to search. This meant that I could not (in version 1) display results as the user types in a word. It is still a timesaver, though, as it opens the site and executes the search all-at-once.

To install the plug-in, make sure you have Ubiquity installed in Firefox, and then go to the project homeage at http://www.x2od.com/projects/ubiquity/index.xhtml. Install and you’re done! For more tips on using Ubiquity, visit Lifehacker.




Enjoy!

 

Project: Change Owner Button in Visualforce

Salesforce Labs has put out a series of Mass Action packages on the AppExchange. There is Mass Transfer Opportunity Owner (uses AJAX), Mass Update Contact Addresses (AJAX), Mass Update Opportunity Owner, Mass Update Opportunity Close Dates, etc. All of these are "thick client" tools, meaning that data must be loaded onto your computer, altered, and then uploaded back to Salesforce. Ron Hess released a super bit of code, found in the Visualforce documentation and elsewhere, to Mass Update Opportunity Stage and Close Date. It could, theoretically, be expanded to other fields as well. This got me thinking about doing so with other objects. A while ago, I took the code for the Mass Delete button and altered it to change the owner of the selected records to the User clicking the button. It was like an Accept button, but I could use it for any object. Actually, it wasn't as easy as that. I had to make one button for each object, and maintenance was a pain--whenever I created a new object, I needed to clone my code. Drawing upon some code I found in the Developers Guide, I have written a Visualforce page to mass-change the owner of all selected records to any active User in Salesforce. Yes, it only works with Contacts for now, but my next step will be to use Dynamic Apex to pass the sObject name to the page and its extension/controller, allowing me to reuse one bit of code for multiple objects. We'll see how it goes. But in the meantime, enjoy this page that lets you perform a search, check which records you want to transfer, and then input a User. I've tested it with 50 records at once, so that should suffice for most uses. VF Page:
<apex:page standardController="Contact" recordSetVar="Contacts" id="updateOwnerPage">
<apex:form>
<apex:sectionheader title="Change Owner for Contacts"/>
<apex:pageblock mode="edit">
<apex:pagemessages />
<apex:pageblocksection title="Change" columns="1">
<apex:pageblocksectionitem> 
<apex:outputlabel for="owner">New Owner</apex:outputlabel>
<apex:inputfield id="owner" value="{!Contact.OwnerId}"/>
</apex:pageblocksectionitem>
</apex:pageblocksection>
<apex:pageblocksection title="Selected Contacts" columns="1">
<apex:pageblocktable value="{!selected}" var="j" bgcolor="#F3F3EC" width="100%" 
styleClass="list" rowClasses="dataRow" onRowMouseOver="hiOn(this);" onRowMouseOut="hiOff(this);">
<apex:column>
<apex:facet name="header">Contact Name</apex:facet>
<apex:outputlink value="{!URLFOR($Action.Contact.View, j.id)}">
{!j.FirstName} {!j.LastName}</apex:outputlink>
</apex:column>
<apex:column>
<apex:facet name="header">Account Name</apex:facet>
<apex:outputlink value="{!URLFOR($Action.Account.View, j.Account.id)}">
{!j.Account.Name}</apex:outputlink>
</apex:column>
<apex:column>
<apex:facet name="header">Current Owner</apex:facet>
{!j.Owner.Name}
</apex:column>
</apex:pageblocktable>
</apex:pageblocksection>
<apex:pageblockbuttons location="bottom">
<apex:commandbutton value="Save" action="{!save}"/>
<apex:commandbutton value="Cancel" action="{!cancel}"/>
</apex:pageblockbuttons>
</apex:pageblock>
</apex:form>
</apex:page>
Button: Go to Setup -> Contact -> Buttons and Links Create a new button, set it to execute in the current window with sidebar and header, and set it to call a Visualforce page. Select the page you just created. Then add the button to Contact Search Layout and to any Contact related lists you like. Voila!
 

Project: Lookup to Picklist

November 11, 2008 by David Schach · Leave a Comment
Filed under: Apex, Visualforce 

In the first installment of post-Dreamforce projects, I present a mechanism to present the user with all available Lookup options in a picklist. This should simplify some Visualforce pages. (Credit to the Developers Guide from the new post-Dreamforce Library.)

The key to the code is the ability to customize the SOQL statement to focus as much, or as little, as the developer would like. Though the code I provide makes no limit on the number of records returned, I encourage developers to limit the select statement as seen fit.

VF Page:

<apex:page standardcontroller="Child__c" Extensions="ChildExtension">
<apex:messages />
<apex:form >
<apex:pageBlock mode="edit" id="thePageBlock">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageblockSection id="ParentList" title="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Parent" for="p"/>
<apex:selectList id="p" value="{!Child__c.Parent__c}" size="1" title="3">
    <apex:selectOptions value="{!ParentOptions}"/>
</apex:selectList>
</apex:pageBlockSectionItem>
</apex:pageblocksection>
</apex:pageBlock>
</apex:form>
</apex:page>

Extension:
Note the SOQL query in Line 12 (below) that defines which records are included in the picklist. You can include WHERE and LIMIT statements to get the picklist down to a manageable number of items.

public class ChildExtension {

    private final Child__c child;

    public ChildExtension(ApexPages.StandardController controller) {
        this.child = (Child__c)controller.getRecord();
        }
    
    public List<selectOption> ParentOptions {get 
        {
        List<selectOption> parents = new List<selectOption>();
        for (Parent__c prt : [select name from Parent__c pt])
            parents.add(new selectOption(prt.id, prt.name));
            return parents;
        }
    private set;
    }
}

Because the parents List in the extension sends an ID to the application, it can successfully create a record with the parent Name in the picklist, but the ID in the background. You can also substitute a different field for Name: If you prefer, put a contact's email address or anything else. Try it out!

One more thing: This is an easy segue into another project, which will be a way to use the traditional lookup interface but to pre-filter the records available in the lookup.

And because I put this in every post: There's a catch. (There always is.) I'm sure that somewhere in there, Salesforce would prefer that we not create a picklist of a few hundred items. So please feel free to test the limits of this visualforce method, but please be prepared to filter your SOQL query.

On a separate note, I just had lunch with John Rotenstein aka The Enforcer, who already put up a photo of our time in his office. (I think the pirate logo was an accident, but it does add to my sinister persona, no?)

 

« Previous PageNext Page »

  • Recent Posts

  • Subscribe

  • Post Categories