function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
HTANIRSHTANIRS 

Class not displaying record values and attachment

Hi Friends,
I need help in getting record values from lead object for below class.
I am getting blank values when testing.
 
Class ::

public with sharing class helperleadTrigger {
    
    public static List<Lead> sendEmail(List<Lead> leads){
        Leads = [SELECT Id, Name, FirstName, LastName, Email, Business_Hub__c, Title__c FROM Lead WHERE Id =: recordId];
        for(Lead l : leads){
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            String[] toAddresses = new String[]{'test@gmail.com'};
            mail.setToAddresses(toAddresses);
            mail.setTargetObjectId(l.Id);
            mail.setTemplateId('00X5D000000EmxQ');
            mail.saveAsActivity = false;
            
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            
            //Set email file attachments
            List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
            for (Attachment a : [select Id, Name, Body, ContentType, BodyLength from Attachment where ParentId =: l.Id]) {
             // Add to attachment file list
                Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
                efa.setFileName(a.Name);
                efa.setBody(a.Body);
                efa.setContentType(a.ContentType);
                fileAttachments.add(efa);
            }
            mail.setFileAttachments(fileAttachments);
        }
        return leads;
    }

Thanks in advance.
Raji MRaji M
Hi,
Can you check WHERE clause in line 6. I don't see any variable "recordId" in your class but directly used in query. Please do check your code and update it.

Raji M
HTANIRSHTANIRS
Hi Raji,

Thanks for reply. Sorry for typo.
WHERE Id =:ApexPages.currentPage().getParameters().get('id')

Could you please check my code now and let me know why my WFR is not populating the data.

Thanks.