You need to sign in to do that
Don't have an account?
jishan roy
Opportunity description field display on account description field
hii everyone,
I write trigger for opportunity description field display on account description field, but my trigger working for only latest opportunity description i want all account related opportunity description showed in account description.
this is my code:
trigger UpdateAccountDescription on Opportunity (before insert, before update, after insert, after update) {
List<Opportunity > oppList =new List<Opportunity >();
Set<Id> setid = new Set<Id>();
if(trigger.isBefore){
system.debug('trigger before event');
oppList = trigger.new;
}else if(trigger.isAfter){
oppList=trigger.new;
for(Opportunity opp:oppList){
setid.add(opp.AccountId);
}
system.debug('setid ' + setid);
List<Account> accList = [Select Id, Name, Description From Account Where Id=:setid];
if(trigger.isInsert){
for(Opportunity opp1:trigger.new){
for(Account a1:accList){
a1.Description= opp1.Description+ ' ';
update a1;
}
}
}else if(trigger.isUpdate){
for(Opportunity opp2:trigger.new){
for(Account a2:accList){
a2.Description= opp2.Description+ ' ' ;
update a2;
}
}
}
}
}
Thanks in advance!
I write trigger for opportunity description field display on account description field, but my trigger working for only latest opportunity description i want all account related opportunity description showed in account description.
this is my code:
trigger UpdateAccountDescription on Opportunity (before insert, before update, after insert, after update) {
List<Opportunity > oppList =new List<Opportunity >();
Set<Id> setid = new Set<Id>();
if(trigger.isBefore){
system.debug('trigger before event');
oppList = trigger.new;
}else if(trigger.isAfter){
oppList=trigger.new;
for(Opportunity opp:oppList){
setid.add(opp.AccountId);
}
system.debug('setid ' + setid);
List<Account> accList = [Select Id, Name, Description From Account Where Id=:setid];
if(trigger.isInsert){
for(Opportunity opp1:trigger.new){
for(Account a1:accList){
a1.Description= opp1.Description+ ' ';
update a1;
}
}
}else if(trigger.isUpdate){
for(Opportunity opp2:trigger.new){
for(Account a2:accList){
a2.Description= opp2.Description+ ' ' ;
update a2;
}
}
}
}
}
Thanks in advance!
Can you try code as below.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
your code is working good only when any opportunity deleted then account description field stay as it is not deleted that description.
Do you want to handle in delete condition as well?
Thanks,
yes i think sooooo!
Can you try below.
If this solution helps, Please mark it as best answer.
Thanks,