Wednesday, October 24, 2012

Display Inaccessible Objects to (Salesforce) Portal Users

This post was rescued from the cache for posterity.

Display Inaccessible Objects to (Salesforce) Portal Users

by Clint Lee on June 28th, 2011
It’s quite late, and I can’t think of anything particularly clever to say, so I’ll just get straight to the point.
If you’ve ever built a custom portal using Salesforce Sites then you’ve most likely had to navigate your way through the various portal licenses at some point. Let’s see, there’s a Customer Portal, a High Volume Customer Portal, an Authenticated Sites, and perhaps another one. Oh yeah, then there’s the Public Site profile.  Each license has its own nuances – object access, CRUD permissions, cost.  Inevitably you’ll need to decide on the license type that best fits what you’re trying to do, knowing that you might have to concede something down the road as you hit a gotcha! or two.
I came across a particular situation where I needed to display information from the Account object to the user.  The Site being built utilized the Authenticated Sites portal license (which provides user authentication but requires a lot of development since it requires only Visualforce pages).  Unfortunately, the Authenticated Sites license doesn’t provide the user with access to the Account object.  When I say no access I mean they can’t even read it.  So, a workaround ensued…
The following solution is not particularly mind-blowing, or really even that sophisticated, but it works for displaying data in what could be termed as “inaccessible” objects.  These are objects that Authenticated Sites licensees can’t read like Accounts, Opportunities, and Cases.  Enter….(drumroll, please)…the Wrapper Class.  Yes, folks, the Wrapper Class.  To most, this was probably obvious from the start but for me it took some noodling around.  Therefore, I decided to share in an effort to prevent others like me from noodling for too long.
Go ahead and create a wrapper class for your object, like so. Name it whatever you like. I call mine AccountToString b/c it sounds fancy.
public class AccountToString {
    private Account acct;

    public AccountToString(Account acct) {
           this.acct = acct;
    }

    public String getName() {
           return acct.Name;
    }

    public String getAddress() {
           return acct.BillingAddress;
    }

    public String getCity() {
           return acct.BillingCity;
    }

    public String getState() {
           return acct.BillingState;
    }

    public String getZip() {
           return acct.BillingPostalCode;
    }

}
Write a controller method to turn your accounts into AccountToStrings. I needed a table with Account data so I populated a class variable with a list of AccountToStrings. Here’s an example.
// This method could run in the controller's constructor.
public void findAccounts() {
           List accts = [select Id, Name, BillingAddress, BillingCity, BillingState, BillingPostalCode from Account];
           for(Account a : accts) {
                 AccountToString aString = new AccountToString( Name = a.Name, BillingAddress = a.BillingAddress, BillingCity = a.BillingCity, BillingState = a.BillingState, BillingPostalCode = a.BillingPostalCode);
                 aStringList.add(aString); // aStringList is a public class variable
           }
Finally, in your Visualforce page, this is one way that you could access your list of AccountToStrings.

    
        
             
                  Account Name
                  
             
             
                  Address
                  
             
             
                  City
                  
             
             
                  State
                  
             
             
                  Zip
                  
             
          
     

I hope this makes sense and perhaps saves you some time. As always, I look forward to any comments or feedback.

Wednesday, September 26, 2012

Controlling Quote Acceptance Information

Salesforce Quote Templates have a non-customisable section on them called Quote Acceptance Information which doesn't show in the edit view, only in the preview and final output.

I noticed that this section was missing on some templates and after some trial and error I found that:

The Quote Acceptance Information disappears if I put an image in the header!

I haven't experimented thoroughly so I don't know if the image has to be a particular size or shape. Something to save for a less busy day.

Tuesday, August 7, 2012

Default a repeating pageBlockSection to closed

To default a Salesforce.com pageBlockSection to closed in a Visualforce page, you can use the Salesforce twistSection javascript function.

However this won't work if you have a pageBlockSection inside a repeat tag, because this solution requires a literal reference. So I used the magic of jQuery to call the function for each repeated pageBlockSection.

Example

For the page snippet below:

<apex:repeat value="{!thisList}" var="thisItem">
    <apex:pageBlockSection title="{!thisItem.Name}" id="thisPBS">

         Some text in here
    </apex:pageBlockSection>
</apex:repeat>

Add the following to the page:

<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" />

<script>
$(document).ready(function() {
    $('img[id*="thisPBS"]').each(function() {
        twistSection(this);
    });
});
</script>


Explanation

The jquery function executes on page load, loops through all the images with a name ending in thisPBS, and calls the twistSection function to close them.

This works because the rendered page has the id you specified via Visualforce on the end of the rendered ids of the pageBlockSections in the repeat tag, i.e.

img_j_id0:wholeForm:thisPB:j_id127:0:thisPBS
img_j_id0:wholeForm:thisPB:j_id127:1:thisPBS
img_j_id0:wholeForm:thisPB:j_id127:2:thisPBS

Monday, August 6, 2012

Salesforce intra-day scheduled job

Via UI apex classes can be scheduled to run at a maximum of once per day. To run more frequently, use the Developer Console.

e.g. to schedule a job every hour, execute the following:


System.schedule('Name of the batch job', '0 0 1-23 * * ?', new YourBatchClass());

Saturday, July 28, 2012

Installing Bazaar for PC

Bazaar for PC is the easiest way to side-load apps onto your windows phone if you don't have a homebrew marketplace installed on your phone. I had a really painful time getting this up and running so for the benefit of myself in future and possibly others, I thought I would list my set of most reliable steps to getting Bazaar for PC working.

Install steps

 1. Most people will have done this, but if you haven't - download and install the Zune software http://www.microsoft.com/windowsphone/en-us/apps/zune-software.aspx

2. Download Windows Phone SDK 7.1 ISO
http://go.microsoft.com/fwlink/?LinkID=226694

3. Use your ISO mounting tool to mount the ISO (If you don't have a tool already, Virtual Clone Drive is free and easy to use)
http://static.slysoft.com/SetupVirtualCloneDrive.exe

4. Run setup.exe in the root folder of the ISO

5. Download and install the Windows Phone SDK 7.1.1 Update
http://www.microsoft.com/en-us/download/details.aspx?id=29233

6. Download and install Bazaar for PC
http://wp-bazaar.com/Bazaar/Bazaar/Releases/BazaarForPC.application

Usage steps


1. Start up the Zune software and connect your phone

2. Start up B4PC and enjoy

Yes that's right, for best results you should have the Zune software running at the same time as B4PC.

Why this approach?


Bazaar for PC has some dependencies such as Dot Net Framework 4.0 Full, and the install will fail if your PC doesn't have these installed. You can waste a lot of time hunting down and installing these dependencies individually, but they are all already packaged in the Windows Phone SDK 7.1 (which is also a Bazaar dependency), so you can just install this and you should have all the Bazaar dependencies.

Unfortunately there are many ways that the Windows Phone SDK 7.1 install can fail, so I strongly recommend downloading the ISO rather than the web bootstrap, otherwise if you have repeated installation attempts you will be spending a lot of time waiting for the SDK files to download.

Probably the first thing you would want to install is a homebrew marketplace so you can immediately cut the cord and install apps directly on your phone. However the marketplace apps aren't available on Bazaar for PC for some reason! This means you will have to install the marketplace apps via XapHandler. Check this app out on Bazaar for PC for instructions.

Troubleshooting the Windows Phone SDK 7.1 install

 MS instructions say to look at your %temp%\dd_install_vm_xcor2_100.txt file. You can find out where your temp folder is by opening Windows Explorer, clicking in the address bar, typing %temp% and hitting Enter.


Reading this txt file I found that the install decided to extract some files to an external drive, but was then was unable to access the files during the install. So I had to disconnect the external drive temporarily.

Friday, July 13, 2012

SQL Server date format for Salesforce upload

convert(nvarchar,datefield,126)

produces yyyy-mm-ddThh:mm:ss.mmmZ

e.g. 2008-10-02T10:52:47.513Z

(Must also set date format and time zone in Data Loader)

Friday, May 25, 2012

Formatting a date in Visualforce


%LT;apex:outputText value="{0,date,dd-MMM-yy}"%GT;
 
%LT; apex:param value="{!inv.Invoice_Date_Sent__c}"/ %GT;
  %LT;/apex:outputText
%GT;

 


I forgot it once, I'll forget it again...