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
mahesh kumar 117mahesh kumar 117 

creating a trigger event 'after insert'

Hi
Iam creating a trigger event 'after insert' see the image and tell me the code is worng or writeUser-added image
Thanks,
Mahesh.
Best Answer chosen by mahesh kumar 117
Amit Chaudhary 8Amit Chaudhary 8
Try to update your code like below
trigger AutoCreateTrigger on emp__c(after insert) 
{
	  List<junction14__c> newjuns = new List<junction14__c>();
	  
	  for (emp__c acc : Trigger.new) 
	  {
			junction14__c jun = new junction14__c();
			//jun.Name        = acc.Name + 'junction14';
			jun.emp__c   = acc.Id;
			newjuns.add(jun);
	  }
	  insert newjuns;
}

 

All Answers

Nandakumar SakthivelNandakumar Sakthivel
Hi Mahesh,

You need to use the API Name of the object instead of the label , "Junction 14" looks like a label name. Please verify

API Name can be found @ Setup > create> objects> <select object name> > API name. 

Thanks,
Nanda
mahesh kumar 117mahesh kumar 117
Hi Nandakumar Sakthivel,

Error: Compile Error: Field is not writeable: junction14__c.Name at line 5 column 5

please modify this code

trigger AutoCreateTrigger on emp__c(after insert) {
  List<junction14__c> newjuns = new List<junction14__c>();
  for (emp__c acc : Trigger.new) {
   junction14__c jun = new junction14__c();
    jun.Name        = acc.Name + 'junction14';
    jun.emp__cId   = acc.Id;
  
      newjuns.add(jun);
  }
  insert newjuns;
}

Thanks,
mahesh
 
Nandakumar SakthivelNandakumar Sakthivel
Hi Mahesh,

Please verify the field access level and make sure that it's not Read-Only and Accessible

Thanks,
Nanda
Amit Chaudhary 8Amit Chaudhary 8
Try to update your code like below
trigger AutoCreateTrigger on emp__c(after insert) 
{
	  List<junction14__c> newjuns = new List<junction14__c>();
	  
	  for (emp__c acc : Trigger.new) 
	  {
			junction14__c jun = new junction14__c();
			//jun.Name        = acc.Name + 'junction14';
			jun.emp__c   = acc.Id;
			newjuns.add(jun);
	  }
	  insert newjuns;
}

 
This was selected as the best answer
mahesh kumar 117mahesh kumar 117
Hi Nandakumar Sakthivel,
please see the image and tell me where i have to change

User-added image

Thanks,
Mahesh
mahesh kumar 117mahesh kumar 117
Thankyou,
Amit Chaudhary