4

Can we have an attachment on Leads?

Can the attachment be sent over from a web to lead form?

4 Answers 4

2

You can have attachments added to Leads (you can enable that on the setup of the Leads page layout object).

enter image description here

As for adding attachments from the web form itself - I am not aware of a standard setting, but a short google search, brought 2 options

http://boards.developerforce.com/t5/General-Development/web-to-lead-form-with-attachment/td-p/336137

1

This is not possible i feel out of box.

You can definately use sites to do this .

http://wiki.developerforce.com/page/Web2Lead_with_Force.com_Sites

Here is the document from wiki.

You can use input file tag in your Visualforce page to upload the attachment into salesforce.

<apex:form >
                    <apex:pageBlock >
                        <apex:pageBlockSection >
                            <apex:inputFile styleClass="btnSendNow" value="{!newAttachment.body}" filename="{!newAttachment.name}"/>
                            <apex:commandButton styleClass="button btnSendNow" value="Upload" action="{!Upload}"/>
                        </apex:pageBlockSection>
                    </apex:pageBlock>
                </apex:form>

public Attachment newAttachment {
    get {
        if (newAttachment == null) newAttachment = new Attachment();
        return newAttachment;
    }

    set;
}

          public PageReference upload() {
    String caseId=ApexPages.currentPage().getParameters().get('id'); 
    system.debug('caseId in upload:'+caseId);
    newAttachment.parentid = caseId;
    try{
        insert newAttachment; 
    }catch(Exception e){
        system.debug(e.getMessage());               
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Error in file upload:'+e.getMessage()));
    }     
    system.debug('New attachment uploaded');
    newAttachment.Body=null;

    PageReference thisPage=ApexPages.currentPage();
    thisPage.getParameters().put('id',caseId);
    return thisPage;
 }
1
  • I dont think client wants to use sites.. Thanks anyway
    – Prady
    Commented Oct 30, 2012 at 10:16
1

Well I achieved this using a different approch other that Web To Lead as I wanted to use the attachment feature.

  1. Enable Email Service in Salesforce by navigating Setup > Develop > Email Service. More details here.Create an Email Service that will accept email from a particular email id. (Email service will give u an recipeint email ID)

  2. Create An Inbound Email handler class that will process the email body and attachment.

  3. Parse the Email body,populate the appropriate fields and insert it.

  4. Use the atatchment ,add it to the created Lead . Voila its done.

  5. Now in your normal site, create a normal form , with textfields and attachment field. On click on Save/Submit button run the code to sent an email to the id of emailservice of salesforce. (Google for Email sending code in the language used by your site, you will easily find it) . Put the data you captured from form in the JSON as email body(Json is easy to read in Apex or in any other language).

Here is the class sampleof how I did this.

global class LeadWithAttachmentEmailHandler implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
    Lead l;
    Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();

    try {
        l = new Lead();
        String emailBody = email.plainTextbody;
        Map < String, String > bodyDataKeyValuePair = (Map < String, String > ) Json.deserializeUntyped(emailBody);
        //Populate the lead fields using this way   
        l.Email = bodyDataKeyValuePair.get('Email');
        insert l;
        //to save attachment to the newly inserted lead. Attachment size currently via inbound mail is restricted to 5MB
        for (Messaging.Inboundemail.TextAttachment tAttachment: email.textAttachments) {
            Attachment attachment = new Attachment();
            attachment.Name = tAttachment.fileName;
            attachment.Body = Blob.valueOf(tAttachment.body);
            attachment.ParentId = l.Id;
            insert attachment;
        }

        result.success = true;
    } catch (Exception e) {
        result.success = false;
        result.message = 'Failed to insert Lead.' + e.getMessage();
    }
    return result;
}

}

1
  • how did you send email from html web to lead form?
    – Sanjivani
    Commented Jul 12, 2019 at 11:03
0

Solution i provided for web2lead with attachments Most of the Situations companies Web 2 Lead form will be a contact us page on companies web site or any specific Landing Pages, Request for information forms or Trial Download forms. in my case customer is using the form for accepting Job Application forms which should support candidates resume as Attachment .

Add one more form with file upload fields and button , remove the submit button on your Salesforce lead forms. On button click call a Java Script Function

  1. Generate a Attachment Key

  2. Submit File Upload Form using AJAX along with the uploaded files submit the Generated Attachment key also to the Action Page

  3. Action page should Validate the File Type File Size and Attachment Key

  4. On Successful Validation Send the attachment as email to Salesforce Email Service and return Success Message

On receipt of Success Message Submit the Salesforce form with the generated attachment key as value on a Custom Field Created on Salesforce Lead Object.

Email sent to Salesforce email service will trigger a Apex Class which will process the attachments if it finds the lead with the matching attachment key then Link the attachment to the lead if lead creation is delayed store the Key and attachments to a custom object. Add a Trigger on the lead object which should match the Attachment record on the attachment object based on the Attachment Key and link it to the lead record and delete the Attachment record created on the custom object

http://blog.soquelllc.com/?p=1

3
  • Which has happened - the blog has gone. @soquel can you put the contents of the blog post on the answer here please?
    – JodieM
    Commented May 14, 2015 at 5:22
  • Not sure why this was down voted. It's a convoluted solution but it would work. Its existence is only necessary because salesforce has not provided a simple web2lead solution for a very common problem. Commented May 4, 2017 at 13:28
  • @ScottMorrison since you have had success with this could you add some explanation how one would accomplish each step. - Thanks
    – Aba
    Commented Feb 15, 2018 at 19:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .