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
TerminusbotTerminusbot 

Apex Map: SOQL Query - Data Retrieval at Index

I have created an Apex Map that I populated with a SOQL query. I am on the rerieving end, but getting an error that the index is not valid. 

Here is what I am doing: 
 
Map<ID, SagittaInfo__c> sagLogin = new Map<ID, SagittaInfo__c>([Select Id, Name, Account__c, Username__c, Password__c, Serverpool__c from SagittaInfo__c where Name = 'MAIN']);
                authHeader.Account        = string.ValueOf(saglogin.get('Account__c'));
                authHeader.Username       = string.ValueOf(saglogin.get('Username__c'));
                authHeader.Password       = string.ValueOf(saglogin.get('Password__c'));
                authHeader.Serverpool     = string.ValueOf(saglogin.get('Serverpool__c'));

What am I doing wrong? When I debug the map to the logs here is what is in the Map. 
 
09:16:28:041 USER_DEBUG [2]|DEBUG|Map{a068A000000ZOcDQAW=SagittaInfo__c:{Id=a068A000000ZOcDQAW, Name=MAIN, Account__c=gemdata, Username__c=wksmt, Password__c=adminwk, Serverpool__c=websvc}}

Thanks for any tips and advice! 
Prateek Singh SengarPrateek Singh Sengar
Your map saglogin is of type <Id, CustomObject> when you retrive the value of the map using get method you need to pass the records id and you will get an Sobject. You then need to use the Sobject and use dot (.) operator to refer to the fields.
It should be something like

SagittaInfo__c sObj = sagLogin.get(SFDCID);
if(sObj != null)
{
authHeader.Account = sObj.Account__c;
//remaining statements.
}