You need to sign in to do that
Don't have an account?
ministe2003
accessing Attachments via Sites
Hi all,
Trying to allow users to create a case via sites on our intranet. That isnt a problem, however I dont seem to be able to allow the user to create Attachments.
There's nothing in the user profile to allow access to Attachments that I can see but I'm getting Authorization errors when I try and insert an attachment.
Anyone know how I can do this?
Thanks
Steven
Curious.
The issue came when i was creating a case with both a Contact ID and an attachment - either one worked on its own but not together.
turned out the case ID wasnt being filled out when it had a contact on it and so when it came to inserting the attachment, it had no parent. Presumably SF must queue up inserts and do them in some other order to that which you specify in the code because when I cut out the Contact ID, inserted the case then the attachment and then after that, updated the case with the contact ID everything worked!
Finally....... :smileyhappy:
All Answers
Book: Force Platform Developer Guide Chapter 14 has an example where visitors upload their resumes (which are attachments)
Thanks for the suggestion but It hasn't helped :(
The only thing I have trouble with is inserting the attachment to the database:
Database.Saveresult sr = Database.insert(attach);
If I comment out that line I dont have any problems but otherwise I get
Here is my Controller:
and here is the insert section of the page:
Anyone have any Ideas why I get this error?
Thanks
Steven
I am having the same issue. Are attachment not allowed by Guest user license??? if someone has an answer pleae help.
It turns out that the "Authorization Required" page appears for other reasons such as an error while inserting. I created a debug log for the Site Guest User and found that the problem was my code. The Parent ID was not populating as i assumed it was. When i hard coded a parent ID it work like a charm. I just need to find out why my code is not taking the newly created record ID and assigning it to the Attachment Parent ID.
Really? Oh thanks for the update I'll have a go at that myself then; good luck and I'll let you know if I fix mine; I probably have the same error I imagine!
Cheers for the heads up!
Disappointing, I'm getting this:
And when I output my attachment I get this:
Which appears ok to me, am I missing something? Seems strange that I get that error!
Thanks
I've got it!!!
Edit the user profile and make sure the tick box "API Enabled" is ticked. It is under the Administrative Permissions section.
Once I ticked this I can now create attachments in Sites :D
Magic
Really? You must be doing something a little different then I because i didnt need to check "api access" for my guest license and it worked. Here are the steps i took
1) make sure the guest license profile for the site has access to the custom object.
2) under field level security make sure they have access to the fields you are referencing on the site
3) as for the parentid issue on the attachment; i resolved it by inserting the record before assigning the record id to the attachment parent id
public class subrogationController {
public blob getfile {get; set;}
public Object__c newResolution {get; set;}
public Attachment newAttachment {get; set;}
public String filename {get; set;}
public subrogationController()
{
newResolution = new Object__c();
newAttachment = new Attachment();
}
public PageReference save()
{
insert newResolution;
newAttachment.body = getfile;
newAttachment.parentid = newResolution.id;
newAttachment.name = filename;
insert newAttachment;
return ApexPages.currentPage();
}
}
I'm not using any custom objects, just Cases and Attachments. The only issue I had was when actually inserting the attachment to the database, the profile had access to everything it needed (fields and cases)
There is no option to give access to attachments (as you are probably aware) on the profile.
I had no issues with parentID or any other fields, I was already getting the Id after inserting the Case.
Strange how we have different fixes!
Now I have another issue, it seems I can't access Contacts either through the guest license!
I thought Guest licenses were meant to have read access to all standard objects? I've set the profile to be able to view contacts but I get Authentication Required all over again :(
Why can't I access these objects?!
Curious.
The issue came when i was creating a case with both a Contact ID and an attachment - either one worked on its own but not together.
turned out the case ID wasnt being filled out when it had a contact on it and so when it came to inserting the attachment, it had no parent. Presumably SF must queue up inserts and do them in some other order to that which you specify in the code because when I cut out the Contact ID, inserted the case then the attachment and then after that, updated the case with the contact ID everything worked!
Finally....... :smileyhappy:
Yep, thats what the issues was with mine too last week. look at my last post (post 9) step 3.
For everyone trying to access the ID of a newly created recored, make sure you insert the record first before trying to access the ID, otherwise it will just be blank when you assign it to a Foreign Key of another record
It wasnt quite as obvious as it seems though, I wasn't inserting the contact seperately, it was being inserted as a field on the Case which was in turn, being inserted before the attachment.
Anyway, im just glad I sorted it!
I have a quick question - how did you create a debug log for the Site Guest User? In my sites setup, sites unauthenticated users have the Site Guest User profile, but there's no actual user account to add to the debug logging. Is there a way around this?
Cheers,
-Philip
each site has an actual user (guest user). You can't login as this user, only gets authenticated when a public site visitor access your public site page.
You can find the user by clicking the "view users" button on the public access setting page for your site.
Bonus info: you can set your site default language and locale via this user as well.
Additional info for the folks reading this posting.
with Summer 10 we added the "preview as Admin" feature where you can see the exact error for your site.Search "Preview as admin" in online help for more details.
I can confirm this issues is only for Site Guest User and Interface Users.
The controller cannot find the Parent Id of case where the attachment needs to be added.
1.While you are navigating to the VF page of case, where you are adding attachments, make sure you pass your case id:
reRend = new PageReference('/apex/RedirectToCaseDetailsandAttachments');
reRend.getParameters().put('id',objCase.id);
2. then in controller, where you are attaching file, pass the same case id in ParentId as below:
public PageReference Submit() {
caseId = System.currentPageReference().getParameters().get('id');
insert new Attachment(Name = filename, Body = filebody, ParentId = caseId);
return null;
}
This is fix the Authorization error.
Our issue is that we have a website that was built with Visual Force (www.fundacion-imara.org). We have a custom object where we keep track of our volunteers and experts and the information from this object is displayed in that website. Also some information comes from the Contact object. In the contact object we add a picture of the person, and that picture has always displayed with no problem in the website, but we found out a couple of days ago that nobody can see the pictures. You can see the issue in http://www.fundacion-imara.org/BeOneOfUs_Members?lang=en_US&rt=if and I am attaching a picture here.
We have been struggling for nearly 2 weeks with this and we can't figure out where the issues is.. the photographs are being uploaded as an attached file in the files&attachments object. Because the attachment button does not show in lightning, we are changing to classic for this.. but it is not working any more.. any suggestions? We have the strong feeling that it has something to do with reading permits for the public profile. in our case it uses a licence called Guest User Licence. But maybe this is not the case