Tuesday, March 30, 2010

Salesforce - Using a Custom Link Button to pass Multi-Record Selection Id's to an external URL

My objective is to allow the user to select Leads from a view using the check-boxes and then pass the Id's of these leads to a third party site.

The GETRECORDIDS(object_type) function is the key part but I can't get it to work in a URL. See GetRecordIds() with a custom button

So far the best solution I've found is to use Javascript (where GETRECORDIDS does work) with the custom link button to pass the Id's to a Visualforce page that uses a Custom Controller. The custom control reads the id's from the query string and then passes them on to an iframe in the visual force page.

See also: List Buttons with VisualForce

Tuesday, March 23, 2010

Salesforce API Calls Made Within Last 7 Days Report

Just received an email notification along the lines of:

Subject: Salesforce.com API usage exceeded threshold of 25% This is an automated notification sent to you at your request by salesforce.com. Your organization has made 1251 API calls within the last 24 hours. This is 25% of your organization's 24-hour API call limit of 5000 calls. You will receive this notice once every 24 hours until your organization's API usage drops below 25% of your 24-hour call limit (1250 calls). For more detail on your organization's API usage, please review the API Usage Report under the Reports tab. If you wish to review or change your notifications, the settings can be found in Setup under Administration Setup > Monitoring > View API Usage Notifications.

The report can be found here (you may need to change from the na5 server):
Reports > Administrative Reports > API Usage Last 7 Days

Thursday, March 18, 2010

Secure ASP.NET Session Cookies

How to check for insecure cookies

Install the Firecookie extension for Firebug so you can examine the cookie security settings.

Before

Set requireSSL to true.

  <system.web>
    <!-- ... -->
    <httpCookies requireSSL="true"/>
    <!-- ... -->
    <authentication mode="Forms">
      <forms name=".ASPXAUTH"
      loginUrl="~/Login.aspx"
      defaultUrl="~/Default.aspx"
      protection="All"
      timeout="30"
      path="/"
      requireSSL="true"
      slidingExpiration="true"
      cookieless="UseCookies"
      enableCrossAppRedirects="false" />
    </authentication>
    <!-- ... -->
  </system.web>

After

See Also:

Wednesday, March 17, 2010

Moving the ASP.NET Global.asax code from a script tag to a class

Global.asax

<%@ Application Language="C#" Inherits="Global" %>

Global.asax.cs

public class Global : System.Web.HttpApplication
    {

        void Application_Start(object sender, EventArgs e)
        {
                //...
        }
    }

See Also:

Tuesday, March 16, 2010

Nelson .NET User Group Presentation - Microsoft Community Road Show - Showcasing MIX10 - 12th of April

Upcoming presentation

Ryan Tarak will be giving a presentation on Monday the 12th of April.

Title:
Microsoft Community Road Show - Showcasing MIX10

Abstract:
With MIX10 around the corner, it’s no better time for Microsoft to get on the road and showcase some of the highlights from this year’s conference held in Las Vegas. Join us at your local Community User Group where we will focus on some of the key highlights including; the future of Mobile™, Silverlight™, Internet Explorer®, Expression®. Ryan Tarak, from Microsoft New Zealand will be travelling all over NZ spreading the good word and also be getting everyone ready for the launch of Visual Studio 2010 by giving the first 30 members at each event a retro Microsoft t-shirt. We will also be providing content from MIX on DVD’s and also the usual pizza and drinks, so make sure you block out the date below.

Useful links:

When:
Monday 12th April 2010
Gather at 11:50 am, starting at 12:00 pm.
Approximately 1 hour plus pizza afterward.

Where:
FuseIT Ltd,
Ground Floor,
7 Forests Rd,
Stoke,
Nelson
(Off Nayland Rd and behind Carters)

http://local.live.com/default.aspx?v=2&cp=-41.299774~173.236231&style=r&lvl=16&alt=-1000
or
http://maps.google.com/?ie=UTF8&om=1&z=17&ll=-41.299774,173.236231&spn=0.005239,0.010042&t=h

If you are parking on site, please use the parks marked FuseIT that are at the back of the site.

Giveaways:
Retro Microsoft t-shirt

Catering: Pizza & Drinks
Door Charge: Free

RSVP to me if you are going to attend so I can guesstimate the food and drink requirements.

However, feel free to turn up on the day though if you can't commit at the moment.

Please feel free to invite anyone who may be interested in attending.

Tuesday, March 9, 2010

Visual Studio 2008 text-encoding iso-8859-1 versus UTF-8

I ran into an issue with ASP.NET pages coming back with the wrong character encoding for text processed through controls.
In the code I specified UTF-8, but when I checked the properties in Firefox the encoding was ISO-8859-1 (Western European (ISO) 28591).
One result of this was that a &nbsp; that had been encoded through a control, such as a LinkButton, was appearing as  (U+00C2 Latin Capital Letter A With Circumflex Alt+0194) followed by the actual non-breaking space.

  • non-breaking space character in ISO-8859-1 is byte 0xA0
  • non-breaking space character in UTF-8 is byte 0xC2,0xA0
  • character bytes 0xC2,0xA0 viewed as ISO-8859-1 comes out as " " (where the second character is a non-breaking space).
<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title> 
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpContext.Current.Response.ContentType = "Content-Type: text/html; charset=UTF-8";
            lnkTest.Text += "1";
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <p>Before&nbsp;After</p>
        <asp:LinkButton ID="lnkTest" runat="server" Text="Before&nbsp;After" />
    </div>
    </form>
</body>
</html>

Try changing the content type line as follows:

HttpContext.Current.Response.ContentType = "text/html; charset=UTF-8";

See Also:

Wednesday, March 3, 2010

Setting properties from a dictionary of strings

A code snippet that can be used to set an objects properties via reflection.

See Also:

using System.ComponentModel;
using System.Collections.Generic;

///...

/// 
/// Set Properties on this instance using key value pairs from a dictionary
/// 
/// Dictionary of keys (property names) and values (value to set property to)
public void FromTemplateData(Dictionary<string, string> templateData)
        {
            PropertyDescriptorCollection propertyDescriptors = TypeDescriptor.GetProperties(this);

            foreach (string key in templateData.Keys)
            {

                //Find the property, ignore case.
                PropertyDescriptor propertyDescriptor = propertyDescriptors.Find(key, true);//propertyDescriptors[nodeName];
                if (propertyDescriptor != null)
                {
                    propertyDescriptor.SetValue(this, propertyDescriptor.Converter.ConvertFromInvariantString(templateData[key]));
                }
                else
                {
                    throw new ApplicationException("No property matching name: " + key);
                }
            }
        }