You need to sign in to do that
Don't have an account?
Achilles21
Trigger Help
Hi ,
Can anybody guide me through the following scenario.
I want to insert into an object on the save action of another object. For the same , I have created a trigger ( after insert ).
How can I insert the data that's getting saved to another object ?
Hi,
I hope it will be useful for you,
insert data to another object:
trigger createRecord on UserRecord__c(after insert)
{
//list variable for second object
List<loginInfo__c> child = new List<loginInfo__c>();
for (UserRecord__c ur : Trigger.new)
{
loginInfo__c li = new loginInfo__c();
li.Name = ur.Name;
li.UserRecord__c = ur.id;
child.add(li);
}
insert child;
}
All Answers
Hi,
I hope it will be useful for you,
insert data to another object:
trigger createRecord on UserRecord__c(after insert)
{
//list variable for second object
List<loginInfo__c> child = new List<loginInfo__c>();
for (UserRecord__c ur : Trigger.new)
{
loginInfo__c li = new loginInfo__c();
li.Name = ur.Name;
li.UserRecord__c = ur.id;
child.add(li);
}
insert child;
}
Hi ,
Thanks for the reply. But i m afraid this is not working !
Can you provide us what error you are getting??
Hi ,
I am not getting any such error but the insertion is not happening either . The following is the modified code according to the previous comment. Here , as you can see i m trying to insert into ManuOrder__c custom object after the insertion into Order__c object.
But the records are not getting created.
trigger SendOrder on Order__c (after insert)
{
List<ManuOrder__c> rec = new List<ManuOrder__c>();
for(Order__c o:Trigger.new)
{
ManuOrder__c mo = new ManuOrder__c();
mo.catagory__c = o.catagory__c;
rec.add(mo);
}
insert rec;
}
How are you inserting the Order records. Did you check the debug logs??
I m just inserting them manually . Creating a new Order. Haven't checked the debug logs though ..
Can you check the debug log as i feel you might be missing to insert some fields on the object.
PFA the debug log for the insertion .
From your debug log, its clear the record is getting created. Did you actually check whether the record is getting created or not.
I dont see any issue with your code or with the debug log.
Hi,
I hope ur record get insertd. u need to do is
select ManuOrder__c tab in your account. then press Go button in the view. now u can see the inserted records.