Tuesday, August 14, 2012
Large Collection of Microsoft eBooks
I came across Eric Ligman Blog where in one of his blogs he has shared a large collection of Microsoft eBook. In his blog, he has also shared a second link to even more books!
Thank you for sharing.
Happy Reading
Tuesday, July 3, 2012
Convert 15 Digit Salesforce ID to 18 Digit
There are many articles on the internet that provides you with formulas on how to convert a 15 digit Salesforce ID to 18 digit. However when I was looking for online tool to actually do this conversion, I couldn't find one. So I created my own tool that allows me to do just that. If anyone else is interested in using this tool I've made it available at:
http://www.magentrix.com/aspx/ConvertSFID
Happy Converting
Friday, May 25, 2012
Converting C# DateTime to Salesforce.com DateTime
One of the most common tasks I need to do when dealing with Salesforce.com Partner or Enterprise WSDL is that I need to convert Microsoft DotNet Framework date & time to format that it is understood by Salesforce.com; whether it be using it in a query or using it with Partner API to create a record that has a date & time field. To make my own life easier, I've created a very simple one liner method to do this job for me:
I find that sometime creating simple one liner methods can make life so much easier.
Happy Coding
1: public static string ConvertToForceDateTime(DateTime dateTime)
2: {
3: dateTime = DateTime.SpecifyKind(dateTime, DateTimeKind.Utc);
4: return dateTime.ToString("yyyy-MM-ddTHH:mm:ssZ");
5: }
I find that sometime creating simple one liner methods can make life so much easier.
Happy Coding
Sunday, May 20, 2012
How to Query all the fields in your Salesforce Object using Partner WSDL
In my previous blog I showed you how you can query any object in Salesforce without having to write all the fields in the object using the Enterprise WSDL. In this post, I'm going to re-write the same method using the Partner WSDL. The method signature will be a little different using the Partner WSDL, the most noticeable one will be that I will not be able to make use of Generic like I did with Enterprise WSDL.
Although this make querying Salesforce objects very easy, there is one big drawback; that is the describeSObject will count toward an API calls. This means that every query to Salesforce will have one additional API call. My suggestion is if you are making too many query calls, try to cache the objects fields. This will result in less API call and faster execution since there is one less trip to Salesforce.
Also same restrictions to the query length apply here too. Make sure you stay within the 10K characters when building your query string.
Happy Coding
1: public static IEnumerable<sObject> QueryObject(string sObjectName, SforceService binding)
2: {
3: List<sObject> result = new List<sObject>();
4: // Get more information about the object
5: DescribeSObjectResult describeResult = binding.describeSObject(sObjectName);
6: if (describeResult.queryable)
7: {
8: // Get all the sObject's fields in an array
9: IEnumerable<string> fields = describeResult.fields.Select(a => a.name);
10: string query = string.Format("SELECT {0} FROM {1}", string.Join(", ", fields), sObjectName);
11: if (binding != null)
12: {
13: // Send the query to Salesforce
14: QueryResult qResult = binding.query(query);
15: if (qResult.records != null && qResult.records.Length > 0)
16: result.AddRange(qResult.records);
17: // Keep querying until we have all the records
18: while (!qResult.done && !string.IsNullOrEmpty(qResult.queryLocator))
19: {
20: qResult = binding.queryMore(qResult.queryLocator);
21: if (qResult.records != null && qResult.records.Length > 0)
22: result.AddRange(qResult.records);
23: }
24: }
25: }
26: return result;
27: }
Although this make querying Salesforce objects very easy, there is one big drawback; that is the describeSObject will count toward an API calls. This means that every query to Salesforce will have one additional API call. My suggestion is if you are making too many query calls, try to cache the objects fields. This will result in less API call and faster execution since there is one less trip to Salesforce.
Also same restrictions to the query length apply here too. Make sure you stay within the 10K characters when building your query string.
Happy Coding
Friday, May 18, 2012
How to Query all the fields in your Salesforce Object using Enterprise WSDL
Welcome to ForceIO blog. I’m hoping that this will be the first of many blogs to come. In my blogs I will try to focus on development of Salesforce.com solutions using Microsoft .NET (C#). I may deviate from time to time, but I will try to mostly keep it relevant.
Did you ever wish that you could just query all your Salesforce Object fields without writing the name of all the fields in the query one by one? SQL give you ability to query all the fields as such:
SELECT * FROM EntityName
But this is simply not possible when querying Salesforce Objects. To get around this minor setback, I’ve created a utility method that queries any force object with all its fields.
1: public static IEnumerable<T> QueryObject<T>(SforceService binding) where T : sObject
2: {
3: List<T> result = new List<T>();
4: Type sObjectType = typeof(T);
5: IEnumerable<string> sObjectProperties = sObjectType.GetProperties().Where(a =>
6: /* Property must be accessible */
7: a.CanRead &&
8: /* Property cannot have base type of sObject to avoid querying related objects */
9: a.PropertyType.BaseType != typeof(sObject) &&
10: /* Ignoring the properties that are of type QueryResult */
11: a.PropertyType != typeof(QueryResult) &&
12: /* Let's make sure we don't query fieldsToNull property */
13: a.Name != "fieldsToNull" &&
14: /* We want to also ignore all boolean related fields that end with "Specified" */
15: !(a.PropertyType == typeof(bool) && a.Name.EndsWith("Specified"))
16: ).OrderBy(a => a.Name).Select(a => a.Name);
17: // Format the query string
18: string query = string.Format("SELECT {0} FROM {1}",
19: string.Join(", ", sObjectProperties), sObjectType.Name);
20: if (binding != null)
21: {
22: // Send the query to Salesforce
23: QueryResult qResult = binding.query(query);
24: if (qResult.records != null && qResult.records.Length > 0)
25: result.AddRange(qResult.records.Cast<T>());
26: // Keep querying until we have all the records
27: while (!qResult.done && !string.IsNullOrEmpty(qResult.queryLocator))
28: {
29: qResult = binding.queryMore(qResult.queryLocator);
30: if (qResult.records != null && qResult.records.Length > 0)
31: result.AddRange(qResult.records.Cast<T>());
32: }
33: }
34: return result;
35: }
Now you can query any Salesforce Object as such:
1: IEnumerable<Account> accounts = QueryObject<Account>(binding);
Of course the world is not black and white, and you don’t always want to retrieve all the records in an Object. I’m sure you can be creative enough to modify the method to suite your need. Just keep in mind that Salesforce limits you to 10K characters for your query string, so if you have way too many fields on your object with very long names, this method will not works.
In my next blog post, I will rewrite the above method so that it works with the Partner WSDL.
Happy Coding
Subscribe to:
Posts (Atom)