You need to sign in to do that
Don't have an account?
JonSimmons
Invalid Cast Problem
I am querying for a list of Opportunities based upon lastmodifieddate and a couple of other fields, I would like to return an array of Opportunities from my function. I can get the data but when I try to cast the resulting array into an array of Opportunities I get the "Specified Cast is Invalid" error. I have tried updating the WSDL with no joy.
Any help is greatly appreciated.
My Code:
Any help is greatly appreciated.
My Code:
private Opportunity[] GetUpdatedClosedOpportunities(SqlDateTime startTime, SqlDateTime endTime)
{
Opportunity[] thegoods = null;
QueryResult qr = null; //storage location for returned data
binding.QueryOptionsValue = new sforce.QueryOptions(); //define the query specifications
binding.QueryOptionsValue.batchSize = 450; //number of records to return.
binding.QueryOptionsValue.batchSizeSpecified = true; //specify that the above item is supplied
string startTimeString = "2005-12-15T21:43:31.000Z"; //temporarily hard coded for testing
string sqlStatement = "SELECT id, name FROM Opportunity WHERE isclosed = TRUE AND lastmodifieddate > " + startTimeString;
try
{
qr = binding.query(sqlStatement);
thegoods = (Opportunity[]) qr.records; //Cast Invalid error here!!
return thegoods;
}
catch (Exception ex)
{
Console.WriteLine ("Failed to get Opportunity: " + ex.Message);
}
return thegoods;
}
Message Edited by JonSimmons on 01-05-2006 07:20 AM
You'll have to walk the array to create an Opportunity array.
Seems odd to me really, I would think that .NET could just throw and exception if the conversion failed, doesn't seem like Microsoft to avoid a potential problem as minor as that and limit the capabilities of the language so drasticly. I would expect MS to make it up to me to ensure that the conversion is going to go correctly and if not throw and appropriate exception. Oh well.
Thanks
Jon