You need to sign in to do that
Don't have an account?
Waqar Hussain SF
How to access values from Map
I am mapping accout with a custom object In a trigger. how can I access custom object fields from Account.
Here is my code..
Map<ID, Account> mapaccounts = new Map<ID, Account>([SELECT Id, Name, phone FROM Account]);
List<custom_object__c> RecodList = new List<custom_object__c>();
RecodList.add( new custom_object__c(Name=mapaccounts.get().Name, Phone__c =mapaccounts.get().Phone, custom_field__c =mapaccounts.get().account_field__c ))
Here is my code..
Map<ID, Account> mapaccounts = new Map<ID, Account>([SELECT Id, Name, phone FROM Account]);
List<custom_object__c> RecodList = new List<custom_object__c>();
RecodList.add( new custom_object__c(Name=mapaccounts.get().Name, Phone__c =mapaccounts.get().Phone, custom_field__c =mapaccounts.get().account_field__c ))
You have to pass the id of account in the map to get the record. For Example:
When you pass account id in get method this will return the account record and then your corresponding field.
Please mark it best if this helps you.
Regards,
Grazitti Team
www.grazitti.com
Map<Id, Account> mapaccounts = new Map<Id, Account>([SELECT Id, Name, phone FROM Account]);
List<custom_object__c> recodList = new List<custom_object__c>();
for(String accId : mapaccounts.keySet()){
recodList.add( new custom_object__c(Name=mapaccounts.get(accId).Name, Phone__c =mapaccounts.get(accId).Phone);
}
"Try this code."
Map<Id, Account> accmap= new Map<Id, Account>([SELECT Id, Name, phone FROM Account]);
List<customobject__c> customList = new List<customobject__c>();
for(String accId : mapaccounts.keySet()){
customList.add( new customobject__c(Name=accmap.get(accId).Name, Phone__c =accmap.get(accId).Phone);
}
If you find your Solution then mark this as the best answer.
Thank you!
Regards
Suraj Tripathi