If I have a remote site (a webform) with the ability for an unauthenticated user to add an attachment from their local machine to a webfom. When they click submit, we create a new record and add the attachment to a case. Is this possible since the user is not logged in?


If your webform lives on a Force.com Site, you can definitely do this. The Site Guest User is allowed to insert and own Case records, even without Field Level Security set up on that profile.

You'll need a Visualforce Page and an Apex Class like the following:


<apex:page controller="GuestFormController" showHeader="false">
            <apex:pageBlockSection title="Subject">
                <apex:inputText value="{!subject}" />

            <apex:pageBlockSection title="Attachment">
                <apex:inputFile value="{!filebody}" fileName="{!filename}" />

            <apex:pageBlockSection title="Description">
                <apex:inputTextarea value="{!description}" rows="8" cols="80" />

            <apex:commandButton value="Submit" action="{!doSubmit}" />


public without sharing class GuestFormController {

    public String subject {get; set;}
    public String description {get; set;}
    public String filename {get; set;}
    public Blob filebody {get; set;}

    public PageReference doSubmit() {
        //create a new case
        Case basket = new Case(Subject = subject, Description = description);
        insert basket;

        //associate the attachment
        insert new Attachment(Name = filename, Body = filebody, ParentId = basket.Id);

        return null;


This will render alright on any public-facing Site page. Here's what it looks like, piggybacking off the Salesforce standard stylesheets.

Guest form:

guest form

No problems inserting the Case and the Attachment: just watch out that unless you use a specific User or Queue the Site Guest User will own the Cases submitted through this form.

Case detail:

case detail

| improve this answer | |

Yes, unauthenticated users can add files to the system, as long as the configuration allows it. For example, a Sites page using Visualforce could create a record and capture a file upload, or you could submit it by an email handler, or any one of several other mechanisms. You cannot, however, use web to lead/web to case, as those servlets do not natively support file attachments.

| improve this answer | |

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.