+ Start a Discussion
Alaric WimerAlaric Wimer 

How to move attachment from a converted lead to Opportunity, Contact, and Account?

I have Leads converting without the Notes & Attachments being moved over to the new Opportunity, Contact, and Account records. I can see the attachment remains on the Lead record when I query the Attachments object and look at the ParentId. Does anyone know if it's possible to move an attachment on a converted Lead to it's new Opportunity, Contact, and Account records? Or more importantly, why would this not be happening in the first place?


Some more information about what is happening:

We use a HelloSign integration. When a customer signs a pdf, it comes back to Salesforce as "Signature Complete" which triggers a process in Process Builder that fires an invocable method that converts the Lead. That pdf does not appear on the newly created Opportunity, Contact, or Account records. Yet it appears to be on the converted Lead record instead.


Any help would be greatly appreciated!


Here's the code for the auto conversion invocable method if it's helpful:

public without sharing class AutoConvertLeads {
    @InvocableMethod(label='Convert Pre-Qual Leads' description='Converts Leads with Pre-Qualification Signature Request | Keeps running user as the owner of new Opportunity, Contact, and Account | Updates converted Opportunity status to Application In' category='Lead')
    public static void convertLeads(List<Id> leadIds) {
        LeadStatus conLeadStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true Limit 1];
        List<Database.LeadConvert> massLeadConvertList = new List<Database.LeadConvert>();
        Id currentUserId               = UserInfo.getUserId();
        String currentUserName         = UserInfo.getName();
        Set<Id> leadIdsSet             = new Set<Id>();
        Set<Id> convOppIds             = new Set<Id>();
        List<Opportunity> oppsToUpdate = new List<Opportunity>();
        String preQualTemplate         = '[V.2] Pre-Qualification'; // name of template to run the trigger
        System.debug('***** DEBUG FIRST | AutoConvertLeads | User Id who auto converted the Lead: ' + currentUserId + 
        ' and Name: ' + currentUserName);

        // Get only the leads that have '[V.2] Pre-Qualification' signature request template
        for (HelloSign__HelloSign_Signature_Request__c signRequest : [SELECT Id, HelloSign__Template__r.Name, HelloSign__Lead__c FROM HelloSign__HelloSign_Signature_Request__c WHERE HelloSign__Lead__c IN :leadIds]) {
            if (signRequest.HelloSign__Template__r.Name == preQualTemplate) {

        // Begin Converting Leads
        if (!leadIds.isEmpty() && !leadIdsSet.isEmpty()) {
            for (Id currentlead : leadIdsSet) {
                    Database.LeadConvert leadConvert = new Database.LeadConvert();
            } // end leadIdsSet loop
            if (!massLeadConvertList.isEmpty()) {
                List<Database.LeadConvertResult> lcrs = Database.convertLead(massLeadConvertList);
                for (Database.LeadConvertResult lcr : lcrs) {
                    System.debug('***** DEBUG 2 | AutoConvertLeads | Was lead conversion successfull? ' + lcr.isSuccess());
                System.debug('***** DEBUG 3 | AutoConvertLeads | Is ConvOppIds set empty? ' + convOppIds.isEmpty());
                if (lcrs.get(0).isSuccess() && !convOppIds.isEmpty()) {
                    // change Opportunity stage to 'Application Sent'
                    List<Opportunity> convertedOpps = [
                        SELECT Id, StageName, OwnerId, Owner.Name
                          FROM Opportunity
                         WHERE StageName != 'Application In'
                           AND Id IN :convOppIds

                    System.debug('***** DEBUG 4 | AutoConvertLeads | Is convertedOpps list empty? ' + convertedOpps.isEmpty());
                    if (!convertedOpps.isEmpty()) {
                        for (Opportunity convertedOpp : convertedOpps) {
                            convertedOpp.StageName = 'Application In';
                            System.debug('***** DEBUG 5 | AutoConvertLeads | Converted Opportunity Stage: ' + convertedOpp.StageName);
                            System.debug('***** DEBUG FINAL | AutoConvertLeads | Owner of Converted Opp: ' + convertedOpp.OwnerId);
                        if (!oppsToUpdate.isEmpty()) {
                            update oppsToUpdate;
                        } // end oppsToUpdate null check
                    } // end convertedOpps null check
                } // end lcrs and convOppIds null check
            } // end massLeadConvertList null check       
        } // end leadIds null check
    } // end leadAssign method
} // end AutoConvertLeads class
Best Answer chosen by Alaric Wimer

Files and Attachment moves automatcally on Account/Contact/Opportunity when you convert the lead. 
Not sure why that is not happening in your case, this is a standard functionality.

Can you check that once before moving to customization?

Please mark this as best answer if you find my answer's helpful.