You need to sign in to do that
Don't have an account?
George Laird 39
Map Question
I'm trying to create a class based on files, which is ContentDocument object. I'm trying to create a map where the key is the ID of the ContentDocument and the value is a list of LinkedEntityId that are related to the key.
I'm not sure how to do this. I took a shot here but I don't think it's correct.
I'm thinking that the key is correct, but I don't know how to get the values for each key. Each key will have a few Ids for the value.
***I'm passing a list called 'docs' from a trigger. The list is essentially all of the docs that were passed from trigger.new
public static void ProcessFiles(List<ContentDocument> docs){
Map<Id,List<ContentDocumentLink>> FilesMap = New Map<Id,List<ContentDocumentLink>>();
List<ContentDocumentLink> l = [SELECT LinkedEntityId FROM ContentDocumentLink WHERE ContentDocumentId IN : docs];
for(ContentDocument c : docs){
FilesMap.put(c.Id,l);
}
}
Any help would be awesome!
I'm not sure how to do this. I took a shot here but I don't think it's correct.
I'm thinking that the key is correct, but I don't know how to get the values for each key. Each key will have a few Ids for the value.
***I'm passing a list called 'docs' from a trigger. The list is essentially all of the docs that were passed from trigger.new
public static void ProcessFiles(List<ContentDocument> docs){
Map<Id,List<ContentDocumentLink>> FilesMap = New Map<Id,List<ContentDocumentLink>>();
List<ContentDocumentLink> l = [SELECT LinkedEntityId FROM ContentDocumentLink WHERE ContentDocumentId IN : docs];
for(ContentDocument c : docs){
FilesMap.put(c.Id,l);
}
}
Any help would be awesome!
Greetings to you!
This code will help you to create map correctly.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com
All Answers
Please try out this way
public class ContactUpdateHandler {
public static void updateContact(List<Account> accounts) {
Map < Id, Account > mapAccount = new Map < Id, Account >();
List<Contact> listContact = new List<Contact>();
for(Account acct : accounts)
mapAccount.put(acct.Id, acct);
listContact = [ SELECT MailingStreet, MailingCity, AccountId FROM Contact WHERE AccountId IN : mapAccount.keySet() ];
if ( listContact.size() > 0 ) {
for ( Contact con : listContact ) {
con.MailingStreet = mapAccount.get(con.AccountId).BillingStreet;
con.MailingCity = mapAccount.get(con.AccountId).BillingCity;
}
update listContact;
} } }
Try to follow the similar approach for your map condition.
Please let me know if still having doubt
thanks
Greetings to you!
This code will help you to create map correctly.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com