You need to sign in to do that
Don't have an account?
Ajitkumar Pradhan 9
Populate the comma separated related Contact name on Account Description field which should work for insert, update and delete case.
Populate the comma separated related Contact name on Account Description field which should work for insert, update and delete case.
The Trigger scenario you mentioned can only work on before update and delete Trtigger Functionality cannot work on account insertion as contact can only be created when there is account. :)
Other functionality can be performed please find below:-
trigger FetchContactOnAccountDescription on Account (before update,before Delete) {
list<id> lstaccid= new list<id>();
string glue = '';
map<id,string> mapcontact = new map<id,string>();
if(Trigger.isBefore){
if(Trigger.isUpdate || Trigger.isDelete){
For(Account acc:Trigger.new){
lstaccid.add(acc.id);
}
if(lstaccid.size()>0){
for(Contact con:[Select id,name,Accountid from contact where Accountid IN :lstaccid]){
mapcontact.put(con.Accountid, con.Name);
}
}
if(mapcontact.size() != null){
for(Account acc:trigger.new){
if(mapcontact.containsKey(acc.id)){
acc.Description += glue + mapcontact.get(acc.id);
glue=';';
}
}
}
}
}
}
It is working as expected :)
Please let us know if this will help you.
Thanks,
Parag Bhatt
All Answers
The Trigger scenario you mentioned can only work on before update and delete Trtigger Functionality cannot work on account insertion as contact can only be created when there is account. :)
Other functionality can be performed please find below:-
trigger FetchContactOnAccountDescription on Account (before update,before Delete) {
list<id> lstaccid= new list<id>();
string glue = '';
map<id,string> mapcontact = new map<id,string>();
if(Trigger.isBefore){
if(Trigger.isUpdate || Trigger.isDelete){
For(Account acc:Trigger.new){
lstaccid.add(acc.id);
}
if(lstaccid.size()>0){
for(Contact con:[Select id,name,Accountid from contact where Accountid IN :lstaccid]){
mapcontact.put(con.Accountid, con.Name);
}
}
if(mapcontact.size() != null){
for(Account acc:trigger.new){
if(mapcontact.containsKey(acc.id)){
acc.Description += glue + mapcontact.get(acc.id);
glue=';';
}
}
}
}
}
}
It is working as expected :)
Please let us know if this will help you.
Thanks,
Parag Bhatt