You need to sign in to do that
Don't have an account?
@ M Coder
Simple Trigger on Maps
Hello Folks ,
Need help in implementing using maps , Not understanding how to do it . Can anyone please help me with code
If I have Account1 and Contact1 and Contact2 are related to Account1. Then, in account object detail page, i have a text box named Account.ContactName__c = Contact1, Contact2 etc . i need to diaplay the related contact names on Account . i did it in list but not able to do it in maps .
Using List :
for(Account a:acclist )
{
String contactName = '';
for(contact c :a.contacts )
{
contactName = c.name+',' ;
}
a.ContactName__c = contactName;
}
update acclist;
Need help in implementing using maps , Not understanding how to do it . Can anyone please help me with code
If I have Account1 and Contact1 and Contact2 are related to Account1. Then, in account object detail page, i have a text box named Account.ContactName__c = Contact1, Contact2 etc . i need to diaplay the related contact names on Account . i did it in list but not able to do it in maps .
Using List :
for(Account a:acclist )
{
String contactName = '';
for(contact c :a.contacts )
{
contactName = c.name+',' ;
}
a.ContactName__c = contactName;
}
update acclist;
The below will help to update the account field 'contactMembers' with the contacts name related to that account using map
All Answers
To do the same thing through map, we will create a Map of Parent Account id with child contact name. In case of first contact we will put simply, next time when contact inserted with same parent then we will put comma then contact name.
Once this map gets ready we will update those account whose Id we stroed in map with string which we have of contact name belongs to that account, so based on that Id we will update account. Here is the code:
Mark answer as solved if it does helps you.
Thanks,
Rahul
The below will help to update the account field 'contactMembers' with the contacts name related to that account using map
try this code
if you found this answer helpful then please mark it as best answer so it can help others.
Thanks
@Rahul : we may land in cpu time out exception if we use for inside for loop . line 14 was comming error
@Bhargavi Tunuguntla : It was working perfectly fine