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
its chanteeits chantee 

Trigger Concepts

Hi to all

senario : When Ever a record is creted in Student object , get the details in payment object also
student is parrent record && Payment is Child
Fields in Student
Student Name
Batch ( Lookup relation in Traing Object )
Fee
when u inserting the records student name , batch & Fee these fielda are display the payment object that aree student name  & Fee

 trigger studentregis on Student__c(After insert)
   {
        Student__c stu = trigger.New[0];
        Payment__C pay = New Payment__C (StudentName__c=pay.Name_c,
        StudentID = pay.ID,
                                      Batch__C      =pay.Batch__c,
                                      Fee__C       =pay.Fee__C);
             insert stu;
             
    }


Getting an error line 1 Column 1
                      
 
Anoop yadavAnoop yadav
Hi,

Write the below trigger on Student Object.
Trigger StudentRegis on Student__c(after Insert) {
	List<Payment__c> payList = new List<Payment__c>();
	
	for(Student__c s :Trigger.New){
		Payment__c pay = New Payment__C (Name = s.Name,
		Student__c = s.ID,
		Batch__c = s.Batch__c,
		Fee__c = s.Fee__c);
		payList.add(pay);
	}
	insert payList;
}

 
SethuSethu
HI,

You have wrongly assigned.

Payment__C pay = New Payment__C (pay.Name_c = StudentName__c,
     pay.ID =  StudentID, pay.Batch__c = Batch__C,pay.Fee__C = Fee__C
  );  
                                 
Hope it will work.  Assignment should be always from Right to left.
 
its chanteeits chantee
Hi Anoop

Stiil I am Getting an error

Entity is not org-accessible at line 1 column 1
its chanteeits chantee
and Thanks for suggesting al bze new to tech
Anoop yadavAnoop yadav
Hi,
Are you using the right API Name of Student__c?
Check in the object.
 
its chanteeits chantee
Yaa excatly i am using API Name as Student_C only
 
SethuSethu
HI,
The error is due to API name mismatch.In your code,

trigger studentregis on Student__c(After insert)
   {
        Student__c stu = trigger.New[0];
        Payment__C pay = New Payment__C (StudentName__c=pay.Name_c,
        StudentID = pay.ID,
                                      Batch__C      =pay.Batch__c,
                                      Fee__C       =pay.Fee__C);
             insert stu;
             
    }

pay.Name__c should come instead of pay.Name_c,. If that not so,check all your field name with corresponding API Name.