function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RohitRohit 

Unabe to capture valid leads

Hi, I am relatively new to sforce, so maybe I am missing something obvious here. I am trying to retrive Lead details(through the lead ID).


Question : How do I check to see if a valid lead corresponding to that ID is returned. Checking for sobjects !=null && sobjects.Length > 0 does not seem to be doing the trick. 


The code is as follows....


private sforce.Lead getLead(string LeadID)


{


String[] ids = null;


sforce.Lead lead = null;


try


{


ids = new string[] {LeadID};



sforce.sObject[] sobjects = binding.retrieve("City, Company, Country, Email, FirstName, OwnerId, Phone, Salutation, State, Street, Title, Website","lead",ids);


if (sobjects != null && sobjects.Length > 0)


{


lead = (sforce.Lead)sobjects[0];


CompanyName = lead.Company;


return lead;


}


else


{


// Can I capture the errors returned by sobject collection here???


return null;


}


}


catch(Exception ex)


{


throw new ApplicationException(" Error in retriving Lead information :" + ex.Message );



}


}


 


Cheers,


 


Rohit

Gareth DaviesGareth Davies
If it is only one lead you may be better using

QueryResult qr = null;
qr = binding.query("select The,Attributes,That,You,Want From Lead where ID ='"+YOURID+"'");
if (qr.size > 0 )
{
Then you have what you want
}
else
{
You dont
}

Good luck
Gareth
SuperfellSuperfell
for retrieve the returned array will always be the same size as the array of Ids you passed in, so all you have to do in this case is check if the first sobject in the array is null.

if (sobjects[0] != null)
{
// do some stuff
}
DevAngelDevAngel
In general, if the only criteria for a SOQL statement to be used in the query method is "Id = something", you would be better served using the retrieve command. There is less overhead since the query does not need to be parsed and an optimized query is used.
Gareth DaviesGareth Davies
That's cool - I'll use that (we have one place in our code where we could use the performance increases)

Are there any other good practices like that - especially for handling bulk data?

Thanks
Gareth.
SuperfellSuperfell
see http://blog.sforce.com/sforce/2006/02/data_loading_ma.html
and
http://blog.sforce.com/sforce/performance/index.html
Gareth DaviesGareth Davies
Thanks
G

PS Was trying to rate your replies at 5 = but can't find the rating button. Where did it go?
RohitRohit
Thanks guys,

Cheers,

Rohit