-4
List<Contact> conList = new List<Contact> {
    new Contact(FirstName = 'Joe',LastName='Smith',Department='Finance');
    new Contact(FirstName = 'Kathy',LastName='Smith',Department='Technology')
        Contact(FirstName = 'Caroline',LastName='Roth',Department='Finance')
        Contact(FirstName = 'Kim',LastName='Shain',Department='Education')};
    insert conList;
    List<Contact> listToUpdate = new List<Contact>();
    for(Contact con : conList){
        if (Con.Department == 'Finance'){
            con.Title = 'Financial analyst';
            listToUpdate.add(con);
        }
    }
    Update listToUpdate;
  • Im getting the "unexpected token '&lt;'. " error – Kumar praveen Nov 12 at 19:21
4

Your problem is here:

List<Contact> conList = new List<Contact> {
  new Contact(FirstName = 'Joe',LastName='Smith',Department='Finance');
  new Contact(FirstName = 'Kathy',LastName='Smith',Department='Technology')
      Contact(FirstName = 'Caroline',LastName='Roth',Department='Finance')
      Contact(FirstName = 'Kim',LastName='Shain',Department='Education')};

You omitted the new for the third and fourth Contact in the list instantiation and each list element is not separated by commas

It should be:

List<Contact> conList = new List<Contact> {
    new Contact(FirstName = 'Joe',LastName='Smith',Department='Finance'),
    new Contact(FirstName = 'Kathy',LastName='Smith',Department='Technology'),
    new Contact(FirstName = 'Caroline',LastName='Roth',Department='Finance'),
    new Contact(FirstName = 'Kim',LastName='Shain',Department='Education')
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.