+ Start a Discussion
Liz Gibbons 16Liz Gibbons 16 

unexpected token: '='

I've got a strange error. I grabbed the controller code from this blog post, but when I try to save it to my dev org, I get an error: unexpected token: '='. I can't seem to figure out why. Any help would be appreciated!

Here's the controller throwing the error:
Public class ThumnailController {

  public String imageUrl {get; set;}

  ContentVersion[] cvs = [select id from contentversion where contentdocumentid= '0691a0000015c3v' and isLatest=true];

  imageUrl ='/sfc/servlet.shepherd/version/renditionDownload?rendition=THUMB720BY480&versionId=' + cvs[0].id;

}

The error is being thrown at this line:
imageUrl ='/sfc/servlet.shepherd/version/renditionDownload?rendition=THUMB720BY480&versionId=' + cvs[0].id;


 
Best Answer chosen by Liz Gibbons 16
LBKLBK
You need a constructor.
 
Public class ThumbnailController {

  public String imageUrl {get; set;}

  public ThumbnailController()
  {
      ContentVersion[] cvs = [select id from contentversion where contentdocumentid = '0691a0000015c3v' and isLatest =true];
      imageUrl = '/sfc/servlet.shepherd/version/renditionDownload?rendition=THUMB720BY480&versionId=' + (string)cvs[0].id;
  }
}

 

All Answers

Gareth Jones 7Gareth Jones 7
'imageUrl' should be initialised within a constructor, or on the same line as the declaration.
You cannot give imageUrl a value 'out in the open'.
Because of the get and set keywords there, I believe you cannot initialise the value on the same line as the declaration.
So, it has to be from within a method: either a constructor or some other method.
LBKLBK
You need a constructor.
 
Public class ThumbnailController {

  public String imageUrl {get; set;}

  public ThumbnailController()
  {
      ContentVersion[] cvs = [select id from contentversion where contentdocumentid = '0691a0000015c3v' and isLatest =true];
      imageUrl = '/sfc/servlet.shepherd/version/renditionDownload?rendition=THUMB720BY480&versionId=' + (string)cvs[0].id;
  }
}

 
This was selected as the best answer
Liz Gibbons 16Liz Gibbons 16
Thanks so much! It's working now!