• Matthias Riverti
  • NEWBIE
  • 10 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Hello,

I have this method that works fine: 
Public class AutoConvertLeads
{
    @InvocableMethod
    public static void LeadAssign(List<Lead> Leads)
    {
        LeadStatus CLeadStatus= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true Limit 1];
        System.debug('Lead Converted Status' + CLeadStatus.MasterLabel);
        List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();
        for(Lead currentlead: Leads){
                Database.LeadConvert Leadconvert = new Database.LeadConvert();
                Leadconvert.setLeadId(currentlead.Id);                
                Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
                if (currentlead.Account__c != null) {
                    System.debug('Lead Account' + currentlead.Account__c);
                    Leadconvert.setAccountId(currentlead.Account__c);
                }
            	MassLeadconvert.add(Leadconvert);
        }
        System.debug('List Convert' + MassLeadconvert);
        if (!MassLeadconvert.isEmpty()) {
            List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
        	System.debug('Result' + lcr);
        }
    }
}

But I want to add a return value.
The value would be the variabe "lcr" which is List<Database.LeadConvertResult>. It could also be a list of strings or opportunity.

When I'm trying this :
Public class AutoConvertLeads
{
    @InvocableMethod
    public static List<Database.LeadConvertResult> LeadAssign(List<Lead> Leads)
    {
        LeadStatus CLeadStatus= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true Limit 1];
        System.debug('Lead Converted Status' + CLeadStatus.MasterLabel);
        List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();
        for(Lead currentlead: Leads){
                Database.LeadConvert Leadconvert = new Database.LeadConvert();
                Leadconvert.setLeadId(currentlead.Id);                
                Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
                if (currentlead.Account__c != null) {
                    System.debug('Lead Account' + currentlead.Account__c);
                    Leadconvert.setAccountId(currentlead.Account__c);
                }
            	MassLeadconvert.add(Leadconvert);
        }
        System.debug('List Convert' + MassLeadconvert);
        if (!MassLeadconvert.isEmpty()) {
            List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
        	System.debug('Result' + lcr);
            return lcr;
        }
    }
}

I'm having the following error : InvocableMethod methods do not support return type of List<Database.LeadConvertResult>
I have tested  all kind of value like string etc but none of those are accepted.

Do you have any idea ?

Thanks,
Matthias