+ Start a Discussion
WEIdataWEIdata 

Error: Compile Error: expecting a right parentheses, found 'Reading_Detail__c' at line 8 column 0

Any help with figuring out what the issue is here will be much appreciated. Thank you!

Trigger createPages on Contact (after insert, after update) {
List<Pages__c> p = new List <Pages__c> ();
For (Contact newContact: Trigger.New)

If (newContact.Pages_Read__c  > 0) {
p.add (new Pages__c (
Pages_Read__c = newContact.Pages_Read__c
Reading_Detail__c = newContact.Pages_Detail__c
Reader_Type__c = newContact.Reader_ID__c
Contact_Name__c = newContact.Name ) ) ;
pToInsert.add(p);

}
}
Try {
Insert pToInsert;
} catch (system.Dmlexception e) {
System.debug (e);
}
Best Answer chosen by WEIdata
Vishant ShahVishant Shah
your missing the commas in here 

Pages_Read__c = newContact.Pages_Read__c
Reading_Detail__c = newContact.Pages_Detail__c
Reader_Type__c = newContact.Reader_ID__c

All Answers

Vishant ShahVishant Shah
your missing the commas in here 

Pages_Read__c = newContact.Pages_Read__c
Reading_Detail__c = newContact.Pages_Detail__c
Reader_Type__c = newContact.Reader_ID__c
This was selected as the best answer
WEIdataWEIdata
Thank you so much! This worked!

Do you have any suggestions on how to auto-populate Contact_Name__c (Lookup field) within this trigger? The trigger saves but when I try to apply it, I receive an error stating that this required field is missing:

Error:Apex trigger createPages caused an unexpected exception, contact your administrator: createPages: execution of AfterUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Contact Name]: [Contact Name]: Trigger.createPages: line 10, column 1
WEIdataWEIdata
Nevermind- I figured out that

Contact_Name__c = newContact.Name

should be

Contact_Name__c = newContact.Id

First ever apex trigger a success.

Thanks again!