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
KD123456KD123456 

Error: Compile Error: unexpected token: '=' at line 13 column 11

Hi,

 

I am unable to find what is going wrong....

any help provided is highly appriciated

I am trying to get an attachment from a case and send it through the notification email and have been failing at each attempt.

After Insert triggers in case does not work, it seems to execute even before the records are saved. This is the last thing I am trying now

 

public with Sharing class notifyEmail {
    Casetracker__c objectCT;
    Case objectC;
    Attachment objectA;
    User objectU;
    List<Casetracker__c> listCT = new List<Casetracker__c>();
    List<Case> listC = new List<Case>();
    List<Attachment> listA = new List<Attachment>();
    List<User> listU = new List<User>();
    List<EmailTemplate> listET = new List<EmailTemplate>();
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    Messaging.EmailFileAttachment ea = new Messaging.EmailFileAttachment();
    listCT = [select Id, Casenumber__c from Casetracker__c where Id = 'a0090000001PMKpAAO'];
    listC = [select Id, OwnerId from Case where CaseNumber = : listCT.Casenumber__c];
    listU = [select Id, Email from User where Id = : listC.OwnerId];
    listA = [select Id, Name, Body, ContentType from Attachment where ParentId = : listC.Id];
    listET = [select Id, Name, Body, Subject from EmailTemplate where Name = 'Support: Case Assignment Notification'];
    if(listA.size()> 0) {
        ea.setFileName(listA.Name);
        ea.setContentType(listA.ContentType):
        ea.setBody(listA.Body);
        ea.setInLine(false);
        mail.setFileAttachments(new Messaging.EmailFileAttachment[] {ea});
    }
    string[] toadd = new string[] {listU.Email};
    mail.setToAddresses(toadd);
    mail.setReplyTo('spprtemail5@gmail.com');
    mail.setSenderDisplayName('SupportEmail');
    mail.setSubject(listET.Subject);
    mail.setHtmlBody(listET.Body);
    Messaging.sendEmail(new Messagin.SingleEmailMessage[] {mail});
}

 Please tell me why I get the above error.

 

 

Thanks

KD

sh-at-youseesh-at-yousee

Probably because that query won't return a List of objects but just a single instance of your custom Casetracker__c object (due to your where-clause).

 

When selecting something while having a where-clause like Id = some_id', SF returns just that one object as Id is a unique identifier.

 

Try re-writing it to this:

 

 

Casetracker__c objectCT = [select Id, Casenumber__c from Casetracker__c where Id = 'a0090000001PMKpAAO'];

 

 

Hope this helps.

 

/Søren Nødskov Hansen

KD123456KD123456

I initially tried it the way you had suggested. I encountered the same error and then went with the list only to see the same error. Is there any kind of a syntax error. If I comment line 13 then the error shows for the next line also.

 

Thanks

KD

sh-at-youseesh-at-yousee

Ok, now I've copy/pasted your code into my IDE and there are several issues.

 

  1. You haven't defined a method in your class (not sure why I didn't catch this the first time); this is the reason for your unexpected token error
  2. The line ea.setContentType(listA.ContentType): ends with a colon and not a semicolon
  3. The query defining listCT actually defines a single object and not a list
  4. Messaging was misspelled in the last line
  5. When using a List in your query you should use the IN operator; also, the WHERE-clause should then use the List itself and not  a specific field

I haven't looked at optimizing your code/queries or the "logical sanity" of the code - I've simply re-organized it and fixed the compile errors. Here's what I ended up with:

 

 

public with Sharing class notifyEmail {
	public void doStuff() {
		// Fetch data
	    Casetracker__c objectCT = [select Id, Casenumber__c from Casetracker__c where Id = 'a0090000001PMKpAAO'];
	    EmailTemplate listET = [select Id, Name, Body, Subject from EmailTemplate where Name = 'Support: Case Assignment Notification'];
	    List<Case> listC = [select Id, OwnerId from Case where CaseNumber = :objectCT.CaseNumber];
	    List<Attachment> listA = [select Id, Name, Body, ContentType from Attachment where ParentId IN :listC];
	    List<Id> caseOwners = new List<Id>();

		// Create list of owner IDs
	    for(Case c : listC) {
	    	caseOwners.add(c.OwnerId);
	    }

		// Fetch list of users
	    List<User> listU = [select Id, Email from User where Id IN :caseOwners];

		// Create Email and Attachment
	    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
	    Messaging.EmailFileAttachment ea = new Messaging.EmailFileAttachment();

		// Initialize attachment and attach to email
	    if(listA.size() > 0) {
	    	for(Attachment a : listA) {
		        ea.setFileName(a.Name);
		        ea.setContentType(a.ContentType);
		        ea.setBody(a.Body);
		        ea.setInLine(false);
		        mail.setFileAttachments(new Messaging.EmailFileAttachment[] {ea});
	    	}
	    }

		// Create to addresses
	    String[] toadd = new String[listU.size()];
	    Integer i = 0;
	    for(User u : listU) {
	    	toadd[i] = u.Email;
	    	i++;
	    }

		// Initialize email
	    mail.setToAddresses(toadd);
	    mail.setReplyTo('spprtemail5@gmail.com');
	    mail.setSenderDisplayName('SupportEmail');
	    mail.setSubject(listET.Subject);
	    mail.setHtmlBody(listET.Body);

		// Send email
	    Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
	}
}

 

This should bring you forward and hopefully help you reach your goal.

 

/Søren Nødskov Hansen