You need to sign in to do that
Don't have an account?
Abhishek Rajput 20
display child account name on Parent Account
Hi,
I am trying to write a trigger to fetch all child account name on parent account. But my trigger is pulling only one child account on which we are making chages instead all child accounts. Please advise me on this.
trigger childaccount on Account (after update) {
map<id,Account> map1 = new map<id,Account>();
String str;
for (Account a : trigger.new)
{
if(a.parentId != null)
map1.put(a.parentId,a);
}
List<Account> lstanct = [Select name, ChildAccountName__c From Account where id in: map1.keyset()];
For (Account ac : lstanct){
str = str + ',' + map1.get(ac.id).name;
ac.ChildAccountName__c = str;
}
update lstanct;
}
I am trying to write a trigger to fetch all child account name on parent account. But my trigger is pulling only one child account on which we are making chages instead all child accounts. Please advise me on this.
trigger childaccount on Account (after update) {
map<id,Account> map1 = new map<id,Account>();
String str;
for (Account a : trigger.new)
{
if(a.parentId != null)
map1.put(a.parentId,a);
}
List<Account> lstanct = [Select name, ChildAccountName__c From Account where id in: map1.keyset()];
For (Account ac : lstanct){
str = str + ',' + map1.get(ac.id).name;
ac.ChildAccountName__c = str;
}
update lstanct;
}
Thanks
Amit Chaudhary
All Answers
https://developer.salesforce.com/page/Declarative_Rollup_Summary_Tool_for_Force.com_Lookup_Relationships
I have used this where I needed a Rollup Summary without a Master Detail relationship.
Let me know how it goes :-)
trigger childaccount on Account (after update) {
map<id,Account> map1 = new map<id,Account>();
Set<id> setids = new Set<id>();
String str='';
for (Account a : trigger.new)
{
if(a.parentId != null)
map1.put(a.parentId,a);
}
List<Account> lst = [Select name, parentid, id From Account Where parentid in: map1.keyset()];
List<Account> lstanct = [Select name, ChildAccountName__c From Account where id in: map1.keyset()];
For (Account ac : lstanct){
For(Account acc : lst){
str = str + ',' + acc.name;
}
ac.ChildAccountName__c = str;
}
update lstanct;
}
Thanks
Amit Chaudhary