You need to sign in to do that
Don't have an account?
Show Parent Account Contacts from Child Account records ...?
I'm new to SF coding so please forgive if this is a dumb question. I need to see the Parent Account Contacts from their Child Account records.
We're integrating with Oracle and have a one-way read-only feed for Parent Accounts and Child Accounts into SF. Contacts are all associated to the Parent Account but we need reps who handle the Child Accounts to see the Parent Account Contacts from the Child Account records.
We also have Oracle Notes coming across read only - those are also at the Parent Account Level and need to be seen at the Child Account level.
Any ideas will be greatly appreciated.
Thanks.
Tryout the code given below :
// collect the all accounts with its parent accountId
List<Account> ac=[select id,Name,parentid from Account];
Set<Id> ids=new Set<Id>();
for(Account a:ac)
{
ids.add(a.parentid); // collect the parent accountid for each account in a set
}
//collect the all contacts related to these parent accountid
List<contact> con=[select id,firstName,lastName,accountId where accountId in:ids];
// Now you can group these contacts based on accountId using map
Map<Id,List<Contact>> conMap=new map<Id,List<Contact>>();
for(Contact c:con)
{
if(conMap.containsKey(c.accountId))
{
(conMap.get(c.accountId)).add(c);
}
else
{
conMap.put(c.accountId,new List<Contact>{c});
}
}
I know this is a dumb question, but how do I get that on my related list on the accounts page? I am new to doing VisualForce, son in my sandbox I created a new VF page called newAccountPage with the controller
<apex:page controller="mycontroller"> <apex:detail relatedList="true" />
apex:page>
Then pasted your code in between the brakets of
public class mycontroller {
}
However I get this error
Error: mycontroller Compile Error: expecting right curly bracket, found 'for' at line 8 column 0