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

Trigger Help
i hve two custom object
with lookup relationship obj2 has three record type,
when i m creating obj1 it should create three field according to recoed type.
trigger LicenceInsert on Licence__c (after insert)no error but it is not creating data according to record type
{
Licence__c c=new Licence__c ();
System.debug(trigger.new[0].id);
if(c.id !=null)
{
List<OtherActivity__c> OtherActivity= new List<OtherActivity__c>();
OtherActivity__c a=new OtherActivity__c();
a.RecordTypeId='01290000000TdtQAAS';
a.DatamigrationApplicable__c='Yes';
a.DMTypeOnboarding__c='Yes';
a.LicenceID__c='trigger.new[0].id';
a.MigrationType__c='free';
OtherActivity.add(a);
OtherActivity__c b=new OtherActivity__c();
b.RecordTypeId='01290000000TdtLAAS';
b.LicenceID__c='trigger.new[0].id';
b.PaidTraining__c='no';
b.TrainingType__c='onboarding';
OtherActivity.add(b);
OtherActivity__c t=new OtherActivity__c();
t.RecordTypeId='01290000000TdtGAAS';
t.LicenceID__c='trigger.new[0].id';
t.UserSetUPStatus__c='Create';
OtherActivity.add(t);
insert OtherActivity;
}
}
Your problem could be there
Licence__c c=new Licence__c ();
if(c.id !=null)
c is a new object, the ID field should be empty.
All Answers
Your problem could be there
Licence__c c=new Licence__c ();
if(c.id !=null)
c is a new object, the ID field should be empty.
I suspect that kxa422 might be right. Try adding a few System.debug() statements inside the if () block and see if they get printed on the debug console.
-Anup
Hi,
As highlighted, indeed no Id is created/referenced till after the insert, since you do not perform any opperations on the record that fires the trigger simply change it into an "after insert".
Kr,
Fred