You need to sign in to do that
Don't have an account?
Gopal Chat
Hi,this is the trigger question,working on insert but not working on delete(before or after) and there is no error message showing
On Contact to update the Account Name field with contact Last Name, concatenated in the end. Example: If you Create A Contact whose FirstName='Sarthak' and LastName='Saxena' and the Accountname ='Tata', Then Account name must become 'TataSaxena'.
Update the above trigger to delete the Last Name from the Account field when a Contact is deleted without deleteing the other Last name.
trigger AddlastNmaeAccount on Contact (after insert,before delete)
{
if(trigger.isInsert)
{
set<id> s=new set<id>();
list<Account> listaccount=new list<Account>();
for(contact con:trigger.new)
{
s.add(con.accountId);
}
Map<id,account> mv=new Map<id,account>([select id,name from account where id IN:s]);
for(contact cont:trigger.new)
{
Account a=new Account();
a.Id=mv.get(cont.AccountId).id;
a.name=mv.get(cont.AccountId).Name+cont.LastName;
listaccount.add(a);
}
Update listaccount;
}
if(Trigger.isDelete)
{
set<id> s1=new set<id>();
list<Account> listaccount=new list<Account>();
for(Contact oContact : Trigger.Old)
{
if(oContact.lastName!= null)
s1.add(oContact.accountId);
}
Map<id,account> mv=new Map<id,account>([select id,name from account where id IN:s1]);
for(contact cont:trigger.new)
{
Account a=new Account();
a.Id=mv.get(cont.AccountId).id;
a.name=a.name.replace(cont.LastName,a.name);
listaccount.add(a);
}
update listaccount;
}
}
Update the above trigger to delete the Last Name from the Account field when a Contact is deleted without deleteing the other Last name.
trigger AddlastNmaeAccount on Contact (after insert,before delete)
{
if(trigger.isInsert)
{
set<id> s=new set<id>();
list<Account> listaccount=new list<Account>();
for(contact con:trigger.new)
{
s.add(con.accountId);
}
Map<id,account> mv=new Map<id,account>([select id,name from account where id IN:s]);
for(contact cont:trigger.new)
{
Account a=new Account();
a.Id=mv.get(cont.AccountId).id;
a.name=mv.get(cont.AccountId).Name+cont.LastName;
listaccount.add(a);
}
Update listaccount;
}
if(Trigger.isDelete)
{
set<id> s1=new set<id>();
list<Account> listaccount=new list<Account>();
for(Contact oContact : Trigger.Old)
{
if(oContact.lastName!= null)
s1.add(oContact.accountId);
}
Map<id,account> mv=new Map<id,account>([select id,name from account where id IN:s1]);
for(contact cont:trigger.new)
{
Account a=new Account();
a.Id=mv.get(cont.AccountId).id;
a.name=a.name.replace(cont.LastName,a.name);
listaccount.add(a);
}
update listaccount;
}
}
Try once below snippet code.and use after delete event.
Hope this helps you!
Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
Then use your code only it will work change event to after delete.
Hope this helps you!
Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com