You need to sign in to do that
Don't have an account?
Suneel B 9
Need After delete to update the last created record in custom field
Hai guys i have created a custom field in account which shows the latest created opportinity in it. Now if i created a record s1 first and s2 next where s2 is the latest created record and it will display s2 in the custom field. Now if i delete s2 the last created would be s1 and s1 has to be displayed.
Now below is the program with after insert and after update i need after delete.
Can anyone help me out with this,
trigger OppUp on Opportunity (after insert,after update, after delete)
{
Set<Id> SetId = new set<Id>();
map<id, Account> acmap = new map<id, Account>();
for(Opportunity Opp: trigger.new)
{
SetId.add(Opp.Accountid);
}
List<Account> opplist = [SELECT id, OptyName__c,(Select id,Opportunity.Name,Opportunity.CreatedDate,Opportunity.AccountId FROM Account.Opportunities order by createddate) FROM Account where Id IN :SetId];
for(Account Acc: opplist)
{
for(Opportunity opp: acc.opportunities)
{
acc.OptyName__c = opp.name;
acmap.put(acc.id, acc);
}
}
for(Opportunity Opp: trigger.old)
{
}
update acmap.values();
}
Now below is the program with after insert and after update i need after delete.
Can anyone help me out with this,
trigger OppUp on Opportunity (after insert,after update, after delete)
{
Set<Id> SetId = new set<Id>();
map<id, Account> acmap = new map<id, Account>();
for(Opportunity Opp: trigger.new)
{
SetId.add(Opp.Accountid);
}
List<Account> opplist = [SELECT id, OptyName__c,(Select id,Opportunity.Name,Opportunity.CreatedDate,Opportunity.AccountId FROM Account.Opportunities order by createddate) FROM Account where Id IN :SetId];
for(Account Acc: opplist)
{
for(Opportunity opp: acc.opportunities)
{
acc.OptyName__c = opp.name;
acmap.put(acc.id, acc);
}
}
for(Opportunity Opp: trigger.old)
{
}
update acmap.values();
}
Use this code: If this post helps, mark this as best answer so will help others in future.
Thanks,
Neetu
All Answers
Use this code: If this post helps, mark this as best answer so will help others in future.
Thanks,
Neetu