+ Start a Discussion

Attaching file with the Leads record

Using .net API I am developing an application to insert leads records into the SalesForce account.With each record I want to give a user facility to upload a file from his local drive which will be stored into the salesforce in association with the lead record.
Is there any way to achieve this?
Yes, you have to create a new Attachment object, set its parent to the lead ID (after the lead has been created obviously), Base64-encode the content of the file you want to attach and put that in the body field, then insert the Attachment.

Hi ,

I have found a complete solution for my problem on following link.You need to include partner WSDL to use this.I have a mdified version of this using asp file upload control.Feel free to contact me if you want that code 



You can refer following code snippet which is nothing but the modified version of the code on above link.Here Resume_upload is asp file upload server control.The code is written in VB.NET

If Resume_upload.FileName <> "" Then

            Dim xmlDoc As System.Xml.XmlDocument = New System.Xml.XmlDocument
            Dim any(3) As System.Xml.XmlElement

            'We can do a similar thing for an attachment
            Dim attach As sForcePartner.sObject = New sForcePartner.sObject
            attach.type = "Attachment"
            attach.Any = any

            attach.Any(0) = xmlDoc.CreateElement("Name")
            attach.Any(0).InnerText = Resume_upload.FileName
            attach.Any(1) = xmlDoc.CreateElement("IsPrivate")
            attach.Any(1).InnerText = "false"
            attach.Any(2) = xmlDoc.CreateElement("ParentId")
            attach.Any(2).InnerText = strRecordId
            attach.Any(3) = xmlDoc.CreateElement("Body")
            attach.Any(3).InnerText = Convert.ToBase64String(Resume_upload.FileBytes)

            Dim sr As sForcePartner.SaveResult = binding.create(New sForcePartner.sObject() {attach})(0)
            If (sr.success) Then


            End If
            'No attachment

        End If

Message Edited by rohitmarathe on 04-02-2008 09:56 PM