You need to sign in to do that
Don't have an account?
Image insert into VF page based on User log in
I have started working with a clip of code from a different post to work in an image to a visual force page that is based on the credentials of the current user.
I have stored the image in the "Notes and Attachements" section of the contact object, the title of the file is "Contact.jpg" ...
Here is the javascript :
<script src="/soap/ajax/15.0/connection.js" type="text/javascript">
function doit() {
var ids = sforce.connection.query("SELECT id FROM Attachment WHERE ParentId = '{!Contact.Id}' AND Name='Contact.jpg' limit 1");
if(ids == NULL) {
document.getElementById('displayDiv').innerHTML = '<br />No Image Found.<br />';
} else {
var srv = ("{!Scontrol.URL}".split(/salesforce.com/))[0] + 'salesforce.com/services/SRedirect?u=';
var url = '/servlet/servlet.FileDownload?file=' + ids.records.Id + '&retURL=/' + '{!Contact.Id}';
document.getElementById('displayDiv').innerHTML = '<img src=' + srv + url + ' alt="Unable to Display Picture/>';
}
}
Here is my call :
<body onload="doit()">
Here is my error:
ERROR: index line 10, column 92 The reference to entity “retURL” must end with the ‘;’ delimiter
ERROR: The reference to entity “retURL” must end with the ‘;’ delimiter
(LINE 10 =)
var url = '/servlet/servlet.FileDownload?file=' + ids.records.Id + '&retURL=/' + '{!Contact.Id}';
I think the error lies in the URL itself that I am trying to assemble, but I have gone around this issue so much today, I think my eyeballs are going to fall out soon. Can anyone spot the error and help me out? Thank you!!!
Here is what I have done to solve the issue for anyone looking to do this in the future:
I ran a query to get the name of the company based on the users login. Then I stripped out the white spaces, and sandwiched it between the folder name and the image extension.
EXAMPLE:
Charlie Brown logs into his partner portal. He works for Brown Ltd. The query fetches "Brown Ltd" and returns it to the string "file". Then the white space is stripped out to make it file = "brownltd"
then I append my foldername, file, and extension together to make one string as such:
"Logos/brownltd.jpg"
and I return that to my Visualforce page.
Works like a charm. Now I have one common file for company Logos and I can display them based on who logs in.
All Answers
Why are you doing this in JavaScript? Why not do this as pure Visualforce?
Of course, this is just one possible means of doing so, but the idea here is that you don't need to waste an API call (!) just to get data that is otherwise "free." That is, calling the API counts against the 5000 per day per user API call limit, while doing the same in the controller costs nothing. You can even use @RemoteAction so you don't get charged the API call if you want to use actual JavaScript, but I don't see why this is necessary.
Using this solution, I get an error telling me there is unexpected token "{" here -->
new String{ String.valueof(a.id) } );
I did try modifiying the line using parens, but that didnt work.
I tried removing the curly brackets, that did not work.
I am not sure what to try next.
Anyone have thoughts on why this is not working?
Thanks!
My apologies, it should be:
Here is what I have done to solve the issue for anyone looking to do this in the future:
I ran a query to get the name of the company based on the users login. Then I stripped out the white spaces, and sandwiched it between the folder name and the image extension.
EXAMPLE:
Charlie Brown logs into his partner portal. He works for Brown Ltd. The query fetches "Brown Ltd" and returns it to the string "file". Then the white space is stripped out to make it file = "brownltd"
then I append my foldername, file, and extension together to make one string as such:
"Logos/brownltd.jpg"
and I return that to my Visualforce page.
Works like a charm. Now I have one common file for company Logos and I can display them based on who logs in.