2013-12-26 1 views
0

계정 개체에 apex 클래스를 작성하고 단일 전자 메일로 첨부 파일로 전자 메일을 보내려면 어떻게해야합니까?정점을 사용하여 다른 개체의 첨부 파일 .xls 파일을 여러 개 보내는 방법

2 개체의 연락처 및 계정 개체를 원하고 하나의 메일로 2 개의 다른 개체로 전자 메일을 보낼 수 있습니까 ???

내 직접 요구하지만 난 하나 개의 정점 클래스에서 2 개체 SOQL 쿼리를 추가하고하지만 난 csvattc 파일이 무엇입니까

mail1 .setFileAttachments(new Messaging.EmailFileAttachment[]{csvAttc,csvAttc1}); 

첨부 파일로 단 1 일 2 회를 ​​얻고 하나의 이메일에 여러 첨부 파일 추가 첨부 파일로 회신하지만 첨부 파일로 csvattc1 파일을 가져 오지 못했습니다.

답변

2

Oracle APEX를 사용하고 있습니까?
당신은 APEX 문서에서 살펴 걸릴 경우

APEX 세일즈 포스를 들어
DECLARE l_id number; 
BEGIN 
    l_id := apex_mail.send(p_to  => '[email protected]', 
        p_from  => '[email protected]', 
        p_subj  => 'APEX_MAIL with attachment', 
        p_body  => 'Please review the attachment.', 
        p_body_html => '<b>Please</b> review the attachment'); 

FOR c1 IN (SELECT filename, blob_content, mime_type 
      FROM apex_application_files 
      WHERE ID IN (123,456)) LOOP 
-- 
apex_mail.add_attachment(p_mail_id => l_id, 
         p_attachment => c1.blob_content, 
         p_filename => c1.filename, 
         p_mime_type => c1.mime_type); 
    END LOOP; 
    COMMIT; 
END; 
/

여기에 해결책이 :

https://docs.oracle.com/database/121/AEAPI/apex_mail.htm#AEAPI343

당신은 쉽게 사용하여 다른 파일을 추가 할 수 있습니다, 찾을 수 있습니다을 (출처 : https://developer.salesforce.com/forums/?id=906F0000000904xIAA) :

public class sendEmail { 
public String subject { get; set; } 
public String body { get; set; } 

private final Account account; 

// Create a constructor that populates the Account object 

public sendEmail() { 
    account = [SELECT Name, 
       (SELECT Contact.Name, Contact.Email FROM Account.Contacts) 
       FROM Account 
       WHERE Id = :ApexPages.currentPage().getParameters().get('id')]; 
} 

public Account getAccount() { 
    return account; 
} 

public PageReference send() { 
    // Define the email 
    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 
    // Reference the attachment page and pass in the account ID 
    Integer numAtts=[SELECT count() FROM attachment WHERE parentid=: account.Id]; 
    system.debug('Number of Attachments Atts = '+ numAtts); 
    List<Attachment> allAttachment = new List<Attachment>(); 
    allAttachment = [SELECT Id, Name, ContentType, Body FROM Attachment WHERE parentid =: account.Id]; 
    // Create the email attachment 
*****  List<Messaging.Emailfileattachment> efaList = new List<Messaging.Emailfileattachment>(); 

    // try{ 
    if(numAtts > 0){ 
      for (Integer i = 0; i < numAtts; i++){ 
       system.debug(allAttachment[i].Name); 
*****Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();<br>   efa.setFileName(allAttachment[i].Name); 
       efa.setBody(allAttachment[i].Body); 
       efa.setContentType(allAttachment[i].ContentType); 
*****efaList.add(efa); 
      } 
    } 
    // } catch (ListException e){ 
     // |DEBUG|List index out of bounds: 2 
    //   system.debug(e.getMessage()); 
    // } 

    String addresses; 
    if (account.Contacts[0].Email != null) { 
     addresses = account.Contacts[0].Email; 
     // Loop through the whole list of contacts and their emails 

     for (Integer i = 1; i < account.Contacts.size(); i++) { 
      if (account.Contacts[i].Email != null) { 
       addresses += ':' + account.Contacts[i].Email; 
      } 
     } 
    } 

    String[] toAddresses = addresses.split(':', 0); 

    // Sets the paramaters of the email 

    email.setSubject(subject); 
    email.setToAddresses(toAddresses); 
    email.setPlainTextBody(body); 
    //email.setFileAttachments(new Messaging.EmailFileAttachment[] {List<efa>()}); 
    if(numAtts > 0){ 
******   email.setFileAttachments(efaList); 
    } 

    // Sends the email 
    Messaging.SendEmailResult [] r = 
     Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); 
    return null; 
} 
}