Skip to content

Using Perl to Import Products into Opportunities

December 24, 2009

Believe it or not I am in sales… Didn’t start out like that, but as some techies would say sold my soul the devil 🙂
Anyway one task that I get to do too often these days is creating, and approving opportunities from my customers. They usually send me an Excel file with their proposed purchase order, I need to upload it to so I can get the discounts approved.

Adding every single part number by hand is tedious, boring work, especially at the end of the quarter when the pressure to “make the numbers” builds up and we have no time to waste. So I revived some of my old Perl memories and wrote a little script that imports all the products at once into an already created opportunity.

If this is useful to you just follow these steps:

  1. Create opportunity, and save it
  2. Copy the last part of the URL (that is your opportunity ID).
    Example: the ID is 0068000000K32EA
  3. Run import-products with your product file, credentials and opportunity ID

You are set!

The product file is just an Excel with 2 columns, the first being the SKU or part number, and the second the desired quantity. Save the file in CSV format (you can do this by selecting CSV as the save type in Excel). Now use this file to import your products.

Script usage:

import-products --csv=product.csv  --opportunity=OpportunityID
                    --user=UserName --pass=Password

            MUST be a Comma Separated file with two columns (SKU, Quantity).
            No header line.

            MUST be an existant Salesforce Opportunity to which you want to add
            the products from the product.csv to.

        user, pass
   user name and password.

            Delete all of the opportunity's products before adding any new ones.



  • Perl 5.8 or higher

CPAN modules

  • WWW::Salesforce::Simple
  • Getopt::Long;
  • Text::CSV_XS;
  • Scalar::Util

You can get the source code from here. Hope you can use it and that it saves you some time as well!


From → Perl

One Comment
  1. Francois Labelle permalink

    Could you post the Perl script again? The link does not seem to work.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: