Solved

Salesforce.com extract Event Address

Posted on 2011-02-22
4
913 Views
Last Modified: 2013-11-24
I need to extract the address of events from Salesforce.com using the web service api.

Basically, I need to get all events tied to today's date and extract their addresses. (I realize some may not have addresses and I would filter for that).

C# or VB.NET example would be fine.
0
Comment
Question by:crandelj
  • 2
4 Comments
 
LVL 7

Expert Comment

by:EYoung
Comment Utility
Have you tried any of the developer services at SalesForce.com?  Here is a link: http://developer.force.com/
0
 
LVL 11

Expert Comment

by:techhealth
Comment Utility
When you say "Address", do you mean the Location field on Event?  If so, here's the SOQL query you'll need to retrieve the records you need.

SELECT Id, Location FROM Event WHERE ActivityDate=Today AND Location!=Null

You can certainly select more fields than just Id and Location, depending on your need.

How you actually make a call in the language of your choosing, be it C#, VB.NET, or Java, is really too long a topic to discuss here.  Check out the Web Services API Developer's Guide from SFDC.  Here's a piece of sample code from there (assuming you've done the WSDL importing, etc.):

using System;
using System.Collections
using System.Text;
using System.Web.Services.Protocols;
using Walkthrough.sforce;
namespace Walkthrough
{
class WalkthroughSample
{
private SforceService binding;
static private WalkthroughSample walkthroughSample;
[STAThread]
static void Main(string[] args)
{
walkthroughSample = new WalkthroughSample();
walkthroughSample.run();
}
public void run()
{
//Call the login call
if (login())
{
//Do a describe global
describeGlobal();
//describe an account object
describeSObject("account");
//retrieve some data using query
querySample();
}
}
private bool login()
{
Console.Write("Enter username: ");
string username = Console.ReadLine();
Console.Write("Enter password: ");
string password = Console.ReadLine();
// Create a service object
binding = new SforceService();
// Timeout after a minute
binding.Timeout = 60000;
// Try logging in
LoginResult lr;
try
{
Console.WriteLine("LOGGING IN NOW...");
lr = binding.login(username, password);
}
// ApiFault is a proxy stub generated from the WSDL contract when
// the web service was imported
catch (SoapException e)
{
// Write the fault code to the console
Console.WriteLine(e.Code);
// Write the fault message to the console
Console.WriteLine("An unexpected error has occurred: " + e.Message);
// Write the stack trace to the console
Console.WriteLine(e.StackTrace);
// Return False to indicate that the login was not successful
return false;
}
// Check if the password has expired
if (lr.passwordExpired)
{
Console.WriteLine("An error has occurred. Your password has expired.");
return false;
}
/** Once the client application has logged in successfully, it will use
* the results of the login call to reset the endpoint of the service
* to the virtual server instance that is servicing your organization
*/
binding.Url = lr.serverUrl;
/** The sample client application now has an instance of the SforceService
* that is pointing to the correct endpoint. Next, the sample client
* application sets a persistent SOAP header (to be included on all
* subsequent calls that are made with SforceService) that contains the
* valid sessionId for our login credentials. To do this, the sample
* client application creates a new SessionHeader object and persist it to
* the SforceService. Add the session ID returned from the login to the
* session header
*/
binding.SessionHeaderValue = new SessionHeader();
binding.SessionHeaderValue.sessionId = lr.sessionId;
// Return true to indicate that we are logged in, pointed
// at the right URL and have our security token in place.
return true;
}
private void describeGlobal()
{
//describeGlobal returns an array of object results that
//includes the object names that are available to the logged-in user
DescribeGlobalResult dgr = binding.describeGlobal();
Console.WriteLine("\nDescribe Global Results:\n");
//Loop through the array echoing the object names to the console
for (int i = 0; i < dgr.sobjects.Length; i++)
{
Console.WriteLine(dgr.sobjects[i].name);
}
Console.WriteLine("\n\nHit enter to continue...");
Console.ReadLine();
private void describeSObject(string objectType)
{
//Call the describeSObject passing in the object type name
DescribeSObjectResult dsr =
binding.describeSObject(objectType);
//The first properites we will echo are on the object itself
//First we will output some Descriptive info on the object
Console.WriteLine("\n\nObject Name: " + dsr.name);
if (dsr.custom) Console.WriteLine("Custom Object");
if (dsr.label != null) Console.WriteLine("Label: " + dsr.label);
//now the permissions on the object
if (dsr.activateable) Console.WriteLine("Activateable");
if (dsr.createable) Console.WriteLine("Createable");
if (dsr.deletable) Console.WriteLine("Deleteable");
if (dsr.queryable) Console.WriteLine("Queryable");
if (dsr.replicateable) Console.WriteLine("Replicateable");
if (dsr.retrieveable) Console.WriteLine("Retrieveable");
if (dsr.searchable) Console.WriteLine("Searchable");
if (dsr.undeletable) Console.WriteLine("Undeleteable");
if (dsr.updateable) Console.WriteLine("Updateable");
//Now we will retrieve meta-data about each of the fields
for (int i = 0; i < dsr.fields.Length; i++)
{
//Create field object for readability
Field field = dsr.fields[i];
//Echo some useful information
Console.WriteLine("Field name: " + field.name);
Console.WriteLine("\tField Label: " + field.label);
//This next property indicates that this
//field is searched when using
//the name search group in SOSL
if (field.nameField)
Console.WriteLine("\tThis is a name field.");
if (field.restrictedPicklist)
Console.WriteLine("This is a RESTRICTED picklist field.");
Console.WriteLine("\tType is: " + field.type.ToString());
if (field.length > 0)
Console.WriteLine("\tLength: " + field.length);
if (field.scale > 0)
Console.WriteLine("\tScale: " + field.scale);
if (field.precision > 0)
Console.WriteLine("\tPrecision: " + field.precision);
if (field.digits > 0)
Console.WriteLine("\tDigits: " + field.digits);
if (field.custom)
Console.WriteLine("\tThis is a custom field.");
//Output the permission on this field.
if (field.nillable) Console.WriteLine("\tCan be nulled.");
if (field.createable) Console.WriteLine("\tCreateable");
if (field.filterable) Console.WriteLine("\tFilterable");
if (field.updateable) Console.WriteLine("\tUpdateable");
//If this is a picklist field, we will show the values
if (field.type.Equals(fieldType.picklist))
{
Console.WriteLine("\tPicklist Values");
for (int j = 0; j < field.picklistValues.Length; j++)
Console.WriteLine("\t\t" + field.picklistValues[j].value);
}
//If this is a foreign key field (reference),
//we will show the values
if (field.type.Equals(fieldType.reference))
{
Console.WriteLine("\tCan reference these objects:");
for (int j = 0; j < field.referenceTo.Length; j++)
Console.WriteLine("\t\t" + field.referenceTo[j]);
}
Console.WriteLine("");
}
Console.WriteLine("\n\nHit enter to continue...");
Console.ReadLine();
}
private void querySample()
{
//The results will be placed in qr
QueryResult qr = null;
//We are going to increase our return batch size to 250 items
//Setting is a recommendation only, different batch sizes may
//be returned depending on data, to keep performance optimized.
binding.QueryOptionsValue = new QueryOptions();
binding.QueryOptionsValue.batchSize = 250;
binding.QueryOptionsValue.batchSizeSpecified = true;
try
{
qr = binding.query("select FirstName, LastName from Contact");
bool done = false;
if (qr.size > 0)
{
Console.WriteLine("Logged-in user can see "
+ qr.records.Length + " contact records.");
while (!done)
{
Console.WriteLine("");
for (int i = 0; i < qr.records.Length; i++)
{
Contact con = (Contact)qr.records[i];
string fName = con.FirstName;
string lName = con.LastName;
if (fName == null)
Console.WriteLine("Contact " + (i + 1) + ": " + lName);
else
Console.WriteLine("Contact " + (i + 1) + ": " + fName
+ " " + lName);
}
if (qr.done)
{
done = true;
}
else
{
qr = binding.queryMore(qr.queryLocator);
}
}
}
else
{
Console.WriteLine("No records found.");
}
}
catch (Exception ex)
{
Console.WriteLine("\nFailed to execute query succesfully," +
"error message was: \n{0}", ex.Message);
}
Console.WriteLine("\n\nHit enter to exit...");
Console.ReadLine();
}
}

Open in new window

Should be a good start to adapt it for your own use.
0
 

Accepted Solution

by:
crandelj earned 0 total points
Comment Utility
Thanks for your feedback.  What I was looking for was the address associated with the Contact/Lead associated with the event.  Of course there are multiple addresses associated with these objects so we had to standardize on one (we chose shipping for our purposes).  

It wasn't that tough once I figured out which WSDL to use. You just look at the event object, find the whoID of the contact/lead and then query that object to find the address.

0
 

Author Closing Comment

by:crandelj
Comment Utility
I solved this one myself so I hope this is the way to close it properly.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now