Map<ID,Target__c> mapTargets = new Map<ID,Target__c>([
Select Id, Name From Target__c Where Account__c in:TargetAccountIDs]);
for(Target__c target : mapTargets.values()) {
System.debug('*************** Current Target: ' + target.Name);
}
Map<ID,Target__c> mapTargets = new Map<ID,Target__c>([
Select Id, Name From Target__c Where Account__c in:TargetAccountIDs]);
for(Target__c target : mapTargets.values()) {
System.debug('*************** Current Target: ' + target.Name);
}
In your same code, what if I want to check a field value from opportunity records. Let say, I need to check status of each opportunity stored in lit childOpportunities. How we can do that without nested for loop.
i have to write trigger and update the records if i have more than 50000 record in contact object as per gobvernor limit 100 it will throw error how will i achive this senario
If you are planning to protect your computer using an internet security program, then you must visit webroot.com/safe (https://webr4oot.com) to learn about Webroot security programs. It is a unique security system developed for computers to fight against viruses and internet attacks. Whoever uses Webroot gets the benefit of secured privacy and encrypted data on their computers.
You Can use this way: Map<Id,Account> accMap = new Map<Id,Account>([Select Id,Name From Account Limit 10]); for(Account acc : accMap.values()) { System.debug('Account Id :'+acc.Id+' '+'Account Name : '+acc.Name); }
You can also use the values method:
Map<ID,Target__c> mapTargets = new Map<ID,Target__c>([ Select Id, Name From Target__c Where Account__c in:TargetAccountIDs]); for(Target__c target : mapTargets.values()) { System.debug('*************** Current Target: ' + target.Name); }
(The returned list is also in arbitrary order)
All Answers
I don't think you can iterate through the contents of a Map directly. You can put the Map contents into a Set or List and then do your loop.
Schema.DescribeSObjectResult objSchema = Account.sObjectType.getDescribe();
Map<String, Schema.SObjectField> fieldMap = objSchema.fields.getMap();
for (String fieldName : fieldMap.keySet()){
System.debug('field name is ' + fieldName);
}
Hope that helps.
Thanks. I'll use that method.
Appreciate the response.
Ma<String,Account> mapAccounts = new Map<String,Account>();for(String key:mapAccounts.keySet()){ System.debug(mapAccounts.get(key));}
THis does not gurantee the order in which the keys would be returned.
You can also use the values method:
Map<ID,Target__c> mapTargets = new Map<ID,Target__c>([ Select Id, Name From Target__c Where Account__c in:TargetAccountIDs]); for(Target__c target : mapTargets.values()) { System.debug('*************** Current Target: ' + target.Name); }
(The returned list is also in arbitrary order)
mapName.values() is what works.
thanks for the help.
list<account> myAccounts = new list<account>();
myAccounts = [Select ID, Name from Account limit 10];
map<id, string=""> myAMap = new map<id, string="">();
for ( Account a : myAccounts ){
myAMap.put(a.ID, a.Name);
}
for ( ID aID : myAMap.keySet() ){
system.debug(loggingLevel.debug, myAMap.get(aID));
}
Taken from: http://www.sundoginteractive.com/sunblog/posts/apex-why-maps-are-your-friend
In your same code, what if I want to check a field value from opportunity records.
Let say, I need to check status of each opportunity stored in lit childOpportunities. How we can do that without nested for loop.
These posts will cover about list,set,map usage and methods available and how to use map in lightning components,
https://www.sfdc-lightning.com/2018/09/collection-in-salesforce.html
https://www.sfdc-lightning.com/2018/09/how-to-use-map-in-lightning-component.html
i have to write trigger and update the records
if i have more than 50000 record in contact object as per gobvernor limit 100 it will throw error how will i achive this senario
Map<Id,Contact> result=new Map<Id,Contact>([select Name from Contact limit 10]);
System.debug(result);
for(Contact c:result.values()){
System.debug(c);
}
We can use get method like as follows
Map<String,Integer> mapper=new Map<String,Integer>();
mapper.get(key);
Map<Id,Account> accMap = new Map<Id,Account>([Select Id,Name From Account Limit 10]);
for(Account acc : accMap.values())
{
System.debug('Account Id :'+acc.Id+' '+'Account Name : '+acc.Name);
}