• Unisoft PhucVV
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 3
    Replies
/**
 * Function attach file to email
 */
public PageReference attachFileToEmail() {

    // In case have file 
    if(attachment.Name != null) {
        // Get parentID
        EmailTemplate parentTemplate = [SELECT Id FROM EmailTemplate LIMIT 1];

        // Set ParentId and Description
        attachment.ParentId = parentTemplate.Id;
        try {
            // Insert file
            insert attachment;

            // Clear body file
            attachment.Body = null;

            if(attachment.Id != null) {
                uploadedAttachments.add(attachment);
            }
        } catch (DMLException e) {
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,UPDATE_FILE_FAILD_ERROR_MESSAGE));
        } finally {
            attachment = new Attachment(); 
        } 
    } else {
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,NO_CHOSE_FILE_ERROR_MESSAGE));
    } 

    return null;

}
My function:

My unit test:
/**
 * attachFileToEmail test
 * Insert success
 */
@isTest
static void AttachFileToEmailSuccessTestCase1() {
    // Create data
    Task[] results;
    BulkEmailSenderControllerTest mgr = new BulkEmailSenderControllerTest();
    BulkEmailSenderController controller = new BulkEmailSenderController();
    mgr.createEmailTemplateData();

    // Create data
    controller.attachment.Name='Unit Test Attachment';
    Blob bodyBlob=Blob.valueOf('Unit Test Attachment Body');
    controller.attachment.body = bodyBlob;
    controller.attachment.parentId = [SELECT Id FROM EmailTemplate LIMIT 1].Id;

    // Running test
    Test.startTest();

    controller.attachFileToEmail();

    Test.stopTest();

    // Compare
    System.assertEquals(1, controller.uploadedAttachments.size());
}

When I run test in Eclipse, this unit test is pass . However on Developer Console Tool is failed with message (System.AssertException: Assertion Failed: Expected: 1, Actual: 0).

Please help my problem.
Hi all,

I write a search Page in example: http://blog.jeffdouglas.com/2009/01/13/apex-search-with-checkbox-results.

When I run it, have a problem. When form submit data, I press Back and then Forward in Browser, my page will go error page with note : "Confirm Form Resubmission" . However I check link demo of topic don't have this error.

http://jeffdouglas-developer-edition.na5.force.com/examples/category_search

My code is user all in this topic. Don't different. I think have config or the environment. Do anyone know this error.

Please help me. Thank
User-added image

User-added image
I created a Page, after I add it in Tabs.

When I click in this Tabs. It's have URL : https://c.cs6.visual.force.com/apex/BulkEmailSender?sfdc.tabName=01rN0000000DCvk.

I want to add a parameter Account ID in this Page when click in Tabs Page in menu ( by code not hander). How I can do it?
Dear all,

I want add a button Attachment File in Visualforce Page. How I can it same in Send Email Template?


User-added image
User-added image
I created a email template by Visualforce. I create a Visualforce Page (Have a input text and 1 button). When I press button, it will get value in inputtext and set it in Email template and set email this. How I can set value to Email template. Please help me.
Hi all,
I created a Email Template by Visualforce.  Then I call a component. Code this:

<apex:component controller="BulkEmailSenderController" access="global">
    <apex:dataTable value="{!selectedOpportunities}" var="s_account">
        <apex:column>
            <apex:facet name="header">Account Name</apex:facet>
            {!s_account.oppObject.Account.Name}}
        </apex:column>
    </apex:dataTable>
</apex:component>

Then I create a send email button. I want set a value in {!selectedOpportunities}. How I can set value in parameter in Salesforce. My function send email:

 Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 
                String[] toAddresses = new String[] {'vopp@systena.co.jp'};
                // Set the paramaters of the email
                email.setTargetObjectId('003N000000Lalmz');
                email.setToAddresses( toAddresses );
                email.setTemplateId('00XN0000000DzEJ');

                // Send the email
                Messaging.SendEmailResult [] r =  Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});  
Hi all,
I created a Email Template by Visualforce.  Then I call a component. Code this:

<apex:component controller="BulkEmailSenderController" access="global">
    <apex:dataTable value="{!selectedOpportunities}" var="s_account">
        <apex:column>
            <apex:facet name="header">Account Name</apex:facet>
            {!s_account.oppObject.Account.Name}}
        </apex:column>
    </apex:dataTable>
</apex:component>

Then I create a send email button. I want set a value in {!selectedOpportunities}. How I can set value in parameter in Salesforce. My function send email:

 Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 
                String[] toAddresses = new String[] {'vopp@systena.co.jp'};
                // Set the paramaters of the email
                email.setTargetObjectId('003N000000Lalmz');
                email.setToAddresses( toAddresses );
                email.setTemplateId('00XN0000000DzEJ');

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