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
pradeep m 27pradeep m 27 

Error: Compile Error: expecting a right parentheses, found 'Id' at line 7 column 31

trigger accountTestTrggr on Account (before insert, before update){
     for(Account a: Trigger.new){
List<Contact> contacts = [select id, department, firstname, lastname, email from Contact where accountId = :a.Id];
                       
           
     for(Contact c: contacts){
          System.debug(Contact Id[' + c.Id + '], FirstName[' + c.firstname + '],LastName[' + c.lastname +']);                                
         c.Description=c.department+ ' ' + c.firstName + ' ' + c.lastname;               
         update c;
     }      
      }
KaranrajKaranraj
Pradeep - Apart from compile error,you have to change some of the things in your trigger code to avoid governor limit issues. You should not use SOQL query and DML statement inside the for loop.
 
trigger accountTestTrggr on Account (before insert, before update){
     List<contact> contactUpdate = new List<contact>();                 
    for(Contact c: [select id, department, firstname, lastname, email from Contact where accountId IN :Trigger.newMap.keySet()]){
          System.debug(Contact Id[' + c.Id + '], FirstName[' + c.firstname + '],LastName[' + c.lastname +']);                                
         c.Description=c.department+ ' ' + c.firstName + ' ' + c.lastname;               
         contactUpdate.add(c);
     }     
    if(contactUpdate.size() > 0)
     update contactUpdate;
}

Take a look into the salesforce Trailhead to understand more about trigger and its best practice - https://developer.salesforce.com/trailhead

Thanks,
Karanraj (http://www.karanrajs.com)
Usman AslamUsman Aslam
Please update the System.debug() statement. It should be something like;
System.debug('Contact Id[' + c.Id + '], FirstName[' + c.firstname + '],LastName[' + c.lastname +']'); 

Thanks