+ Start a Discussion
akkkakkk 

how to write a trigger because have a some condition ?

Hi Friends

i have two object object 1 and object 2 withoud any relationship condition 1;- both have same fields ex= firstName,city, status
if the first time insrt a record in object 1 then status is New.but doest not insrt Record in object 2.
conditon 2 :- if the update status approved then insert the record in Object 2.

please support

Thanks
Ishrat
 
Best Answer chosen by akkk
Deepak DineshDeepak Dinesh
trigger sampletrigger on object(after insert,after update)
{
List<object2>obj2list  = new list<object2>();
for(object1 obj1 : trigger.new)
{
​​​​​If(obj1.status =='approved')
{
Object2 obj2 = new object2();
Obj2.FirstNsme  = obj1.firstname;
Obj2.lastnsme = obj1.lastname;
obj2.city = obj1.city;
obj2.status = obj1.status;
Obj2list.add(obj2);
}
}
Database.insert(obj2list,false);
}

Choose this a best answer if it solves your requirement

All Answers

Deepak DineshDeepak Dinesh
trigger sampletrigger on object(after insert,after update)
{
List<object2>obj2list  = new list<object2>();
for(object1 obj1 : trigger.new)
{
​​​​​If(obj1.status =='approved')
{
Object2 obj2 = new object2();
Obj2.FirstNsme  = obj1.firstname;
Obj2.lastnsme = obj1.lastname;
obj2.city = obj1.city;
obj2.status = obj1.status;
Obj2list.add(obj2);
}
}
Database.insert(obj2list,false);
}

Choose this a best answer if it solves your requirement
This was selected as the best answer
akkkakkk
thanks