You need to sign in to do that
Don't have an account?
How to assign an Relation Object data to a variable
Hi Devs...
My soql query
soqlQuery = "select id,name, SF__Sa_Ord__r.SF__acc__r.id, SF__Sa_Ord__r.SF__acc__r.name from SF_Account__c";
sObject[] records = null;
qResult = SFService.query(soqlQuery);
SF_Account__c SFAccount = new SF_Account__c();
SF__Sa_Ord__c SO = new SF__Sa_Ord__c();
if (qResult.size > 0)
{
MessageBox.Show("Total Number of records Present in Salesforce:"
+ qResult.size);
records = qResult.records;
for (int i = 0; i < records.Length; i++)
{
Acc= (SF_Account__c )records[i];
SA = (SF__Sa_Ord__c)records[i]; ---- Unable
var1 = Acc.Id;
var2 = Acc.Name;
var3 = SA.SF__acc__r.Id;
var4 = SA.SF__acc__r.Name;
}
Exception :
Unable to cast object of type
'WindowsFormsApplication1.SFDC.o2bc__Order_Line__c' to type
'WindowsFormsApplication1.SFDC.o2bc__Sales_Order__c'.
Can anybody know the solution ?
God I wish SF would elminate the whole underscore craze! That stuff is so very hard to read.
/rant
Unfortunately, I don't know if you are posting the incorrect code for where the error is or what; there is no mention of Order_Line__c or Sales_Order__c in your code, so there is no way for us to say what could be causing the exception.
If you're saying the line SA = (SF__Sa_Ord__c)records[i]; is where the exception happens, I would say that you might be running into the problem of selecting 'SF_Account__c' records and are trying to convert them to 'SF__Sa_Ord__c'...they cannot be.
If your query is this:
SELECT Id, Name, Parent__r.Id, Parent__r.Name FROM Child__c
You would access the named objects like this: