function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mohimohi 

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) 
{
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;
}
}
no error but it is not creating data according to record type
Best Answer chosen by Admin (Salesforce Developers) 
kxa422kxa422

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

kxa422kxa422

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.

This was selected as the best answer
Anup JadhavAnup Jadhav

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

frederic baudaxfrederic baudax

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