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
John Daly 3John Daly 3 

Unbale to get sObject id

I am new to Sales force API integration with .NET and came accross this issue - can't seem to get the sObject id from QueryResult - the id is null, even though a valid record is returned, and I can see the Name field. Any suggestions?
See my query below:

  string queryStr = $"SELECT id, Name FROM Account Where Name = '{name}'";
                QueryResult qResult = _service.query(queryStr);
                bool done = false;

                if (qResult.size > 0)
                {
                    while(!done)
                    {
                        sObject[] records = qResult.records;

                        for(int i = 0; i < records.Length; i ++)
                        {
                            accountId = records[i].id; // record id is null here
                        }

                        if (qResult.done)
                        {
                            done = true;
                        }
                        else
                        {
                            qResult =
_service.queryMore(qResult.queryLocator);
                        }
                    }            
                }
Best Answer chosen by John Daly 3
Alain CabonAlain Cabon
@John Daly 

Just try with "Id" instead of "id"

accountId = records[i].Id;

( upper-case for the "I" )

All Answers

Alain CabonAlain Cabon
@John Daly 

Just try with "Id" instead of "id"

accountId = records[i].Id;

( upper-case for the "I" )
This was selected as the best answer
John Daly 3John Daly 3
Upper-case 'I' doesn't work - sObject has no definition for 'Id'
John Daly 3John Daly 3
Just came accross this comment to a similar question - "The internal Id of the custom object definition is not exposed anywhere in the API", looks like object's Id cannot be accessed through the API?
John Daly 3John Daly 3
@ Alain Cabon - I just removed and added again the Enterprise wsdl reference to my project and Id field is now accessible in the API query! 
Alain CabonAlain Cabon
The problem with the upper-case and the very specific field Id existed for a VFP but it is not your problem perhaps ( not just that ).

Old problem with id and Id :
https://developer.salesforce.com/forums/?id=9060G0000005aB1QAI
 
John Daly 3John Daly 3
Thanks @Alain Cabon - reinstalling the wsdl seems to have solved the reference issue, but not sure why 'Id' wasn't available the first time
Alain CabonAlain Cabon
Excellent your feedback in your last comment because these problems are among the worst ones ( all seems correct and should work perfectly )

All is case insensitive in Apex/VFP by default excepted for the specific field Id (sometimes).

Best regards
Alain
Alain CabonAlain Cabon
Above I posted a problem with Id and id in javascript (so case sensitive) but the real terrible old problem in Apex was this one with Id and id:

getting System.ListException: Row with null Id at index 0 error with my Map AggregateResult
https://developer.salesforce.com/forums/?id=9060G000000XhsvQAC

 Given that apex is case insentitive, id and Id should be the same.