You need to sign in to do that
Don't have an account?
MJR
Error: Compile Error: Illegal assignment from String to SOBJECT:Account at line 37 column 9
my code is
Map<Id,Account> newmp = new map<Id,Account>([Select Id,Name from Account limit 10]);
for(Account acc : newmp.values())
{
string codesId = newmp.get('United Oil & Gas, UK');
system.assertEquals(codesId,'0019000000PCwb9AAD');
system.debug('account:'+codesId);
}
HI,
try this,
string codesId = newmp.get(acc.Id).Id;
system.assertEquals(codesId,'0019000000PCwb9AAD');
not working
Well doing it all wrong!
First of all this
Map<Id,Account> newmp = new map<Id,Account>([Select Id,Name from Account limit 10]);
Code creates a map of Id and Account.
So Map has
Id(not the name) as Key
Sobject Account as Value
So you have to actually do something like this
Map<String,Id> newmp = new Map<String,Id>();
for(Account acc : [SELECT Id,Name FROM Account LIMIT 10]){
newmp.put(acc.Name,acc.Id);
}
PS : From direct query you can only generate map of Id and Sobject. For anything other then this you have to iterate through the records to generate the map