• Karol Macak
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 1
    Questions
  • 2
    Replies
Hi guys,

I have screen flow, where users can upload files. I would like to send an email.

I tried to look for a solution and make it working (I am not the developer) and it is working for .pdf files, but I need your help with making it more dynamic, as I don't know what file type will be uploaded by User (it can be jpg, png...)
 
public class sendAnEmail
{
    @InvocableMethod(label='Send an email from apex class' description='sends an email')
    public static void sendEmailWithAttachment(List<List<String>> IDList)
    {
    ContentVersion cvData = [SELECT Id, Title, FileType, VersionData, ContentDocumentId FROM ContentVersion WHERE ContentDocumentId in :IDList[0] LIMIT 1];
               string fileName = cvData.Title + '.pdf';
               Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
               attachment.setBody(cvData.VersionData);
               attachment.setFileName(fileName);
               attachment.setContentType('application/pdf');    
               
               Messaging.SingleEmailMessage semail= new Messaging.SingleEmailMessage();
               semail.setSubject('Case created');
               String[] emailIds= new String[]{'*********@gmail.com'};
               semail.setToAddresses(emailIds);
               semail.setPlainTextBody('Please find the attached Case details');
               semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attachment});
               Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
           }
    }

Thanks in advance for any help.
 
Hi guys,

I have screen flow, where users can upload files. I would like to send an email.

I tried to look for a solution and make it working (I am not the developer) and it is working for .pdf files, but I need your help with making it more dynamic, as I don't know what file type will be uploaded by User (it can be jpg, png...)
 
public class sendAnEmail
{
    @InvocableMethod(label='Send an email from apex class' description='sends an email')
    public static void sendEmailWithAttachment(List<List<String>> IDList)
    {
    ContentVersion cvData = [SELECT Id, Title, FileType, VersionData, ContentDocumentId FROM ContentVersion WHERE ContentDocumentId in :IDList[0] LIMIT 1];
               string fileName = cvData.Title + '.pdf';
               Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
               attachment.setBody(cvData.VersionData);
               attachment.setFileName(fileName);
               attachment.setContentType('application/pdf');    
               
               Messaging.SingleEmailMessage semail= new Messaging.SingleEmailMessage();
               semail.setSubject('Case created');
               String[] emailIds= new String[]{'*********@gmail.com'};
               semail.setToAddresses(emailIds);
               semail.setPlainTextBody('Please find the attached Case details');
               semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attachment});
               Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail});
           }
    }

Thanks in advance for any help.
 
public class spltedinputemail 
{
  public List<string> splitString {get;set;}
  public Backup__c back{get;set;}
  
    public spltedinputemail(ApexPages.StandardController controller) 
    {
       controller.addFields(new List<string>{'splitemail__c'});
       this.back= (Backup__c)controller.getRecord();
        splitString = new List<string>();

        if(!String.IsBlank(back.splitemail__c))
            splitString = back.splitemail__c.split(';');
       system.debug('!!!!splitString' +splitString );
    }

  List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
  public pagereference splitemail()
  {
  if(splitString != null)
  {
   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
   List<String> sendTo = new List<String>();
    sendTo.add('splitString ');
      mail.setToAddresses(sendTo);
      mail.setSenderDisplayName('CCC Infotech');
     List<String> ccTo = new List<String>();
      ccTo.add('splitString ');
    mail.setCcAddresses(ccTo);
      mail.setSubject('URGENT BUSINESS PROPOSAL');
      String body = 'Dear '  + ', ';
      body += 'I confess this will come as a surprise to you.';
      body += 'I am John Alliston CEO of the Bank of Nigeria.';
      body += 'I write to request your cooperation in this ';
      body += 'urgent matter as I need a foreign partner ';
      body += 'in the assistance of transferring $47,110,000 ';
      body += 'to a US bank account. Please respond with ';
      body += 'your bank account # so I may deposit these funds.';
      mail.setHtmlBody(body);
      mails.add(mail);
  } 
 Messaging.sendEmail(mails); 
  return page.spltsendingmail;
 }
}

what is the problem?
public class spltedinputemail 
{
  public List<string> splitString {get;set;}
  public Backup__c back{get;set;}
  
    public spltedinputemail(ApexPages.StandardController controller) 
    {
       controller.addFields(new List<string>{'splitemail__c'});
       this.back= (Backup__c)controller.getRecord();
        splitString = new List<string>();

        if(!String.IsBlank(back.splitemail__c))
            splitString = back.splitemail__c.split(';');
       system.debug('!!!!splitString' +splitString );
    }

  List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
  public pagereference splitemail()
  {
  if(splitString != null)
  {
   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
   List<String> sendTo = new List<String>();
    sendTo.add('splitString ');
      mail.setToAddresses(sendTo);
      mail.setSenderDisplayName('CCC Infotech');
     List<String> ccTo = new List<String>();
      ccTo.add('splitString ');
    mail.setCcAddresses(ccTo);
      mail.setSubject('URGENT BUSINESS PROPOSAL');
      String body = 'Dear '  + ', ';
      body += 'I confess this will come as a surprise to you.';
      body += 'I am John Alliston CEO of the Bank of Nigeria.';
      body += 'I write to request your cooperation in this ';
      body += 'urgent matter as I need a foreign partner ';
      body += 'in the assistance of transferring $47,110,000 ';
      body += 'to a US bank account. Please respond with ';
      body += 'your bank account # so I may deposit these funds.';
      mail.setHtmlBody(body);
      mails.add(mail);
  } 
 Messaging.sendEmail(mails); 
  return page.spltsendingmail;
 }
}

what is the problem?