You need to sign in to do that
Don't have an account?

how to update same object field using trigger?
trigger realtime2 on Contact (before insert)
{
map<id,string> map1=new map<id,string>();
list<contact> conlist=new list<contact>();
list<contact> conlist1=new list<contact>();
if(trigger.isbefore)
{
for (Contact con:trigger.new)
{
map1.put(con.id,con.phone);
conlist.add(con);
}
for(contact con:conlist)
{
con.mobilephone=map1.get(con.id);
conlist1.add(con);
}
update conlist1;
}
}
{
map<id,string> map1=new map<id,string>();
list<contact> conlist=new list<contact>();
list<contact> conlist1=new list<contact>();
if(trigger.isbefore)
{
for (Contact con:trigger.new)
{
map1.put(con.id,con.phone);
conlist.add(con);
}
for(contact con:conlist)
{
con.mobilephone=map1.get(con.id);
conlist1.add(con);
}
update conlist1;
}
}
If so you can do the following:
You dont need to call the update.
Hope this helps
All Answers
If so you can do the following:
You dont need to call the update.
Hope this helps
You don't need to perform dml(i.e update conlist1) in before Insert. Simply You should assign the value. Looking at your code it seems you are trying to populate MobilePhone with Phone field. You can do as such.
trigger realtime2 on Contact (before insert)
{
if(trigger.isbefore)
{
for(contact con:conlist)
{
con.mobilephone=map1.get(con.id);
}
}
}
How to update the custom field using trigger in same object?
can you plase give me the example of above scenario.
In what context are you looking for an example?
Cheers
Shyam
I have one scenario in which i need your help.
Ther is two standard field on case : Case origin and Subject
When one of the field or both are updated, both field value(concating 2 filed values) should be auto populate in one custom field using trigger for the same object Case