You need to sign in to do that
Don't have an account?
Nihar Annamaneni 7
populate contact description with modified user name when user update contact and when user creates contact and when user delete contact
when i am updating the trigger the contact description is not changing and how to write code for delete trigger for contacts in the same code.....
trigger contactbeforeinsert on Contact (before insert,before update) {
for(contact c:trigger.new){
if (c.Description == null)
{
c.Description = '(before Contact insert trigger wrote this)';
}
else
{
c.Description = c.Description + '(before Contact insert trigger wrote this)';
}
for(contact con:trigger.old){
if (trigger.isBefore) {
if(trigger.isUpdate)
{
contact con1 = [select id , lastname , Description from contact];
if(con1.Description == null){
con1.Description = 'New description';
}
update con;
}
}
}
}
}
trigger contactbeforeinsert on Contact (before insert,before update) {
for(contact c:trigger.new){
if (c.Description == null)
{
c.Description = '(before Contact insert trigger wrote this)';
}
else
{
c.Description = c.Description + '(before Contact insert trigger wrote this)';
}
for(contact con:trigger.old){
if (trigger.isBefore) {
if(trigger.isUpdate)
{
contact con1 = [select id , lastname , Description from contact];
if(con1.Description == null){
con1.Description = 'New description';
}
update con;
}
}
}
}
}
Trigger.New is not availble for delete.
Please use bellow modified code.
All Answers
What exactly you want in above trigger ,Incase delete where you update user deatil as your contact record will delete on delete event .
Second thing please explain your requirment properly so that we can help you .
Thanks
Manoj
If you want to update description on contact after insert and update of contcat then bellow sample code will work which is modified version of your code.
After delete you need to save deleted by on other record. I have created a new task for that case.
i am facing errors when deleting contact records...........
Error is :
Validation Errors While Saving Record(s)
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger ContactBeforeInsert1 caused an unexpected exception, contact your administrator: ContactBeforeInsert1: execution of BeforeDelete caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.ContactBeforeInsert1: line 2, column 1".
Click here to return to the previous page.
Trigger.New is not availble for delete.
Please use bellow modified code.
Try bellow code and let me know if any query.
My requirment is done thanks for your help with the code......................