• zjlg
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 7
    Replies

Hi all,
I have a question that need you help..
Now i wanna use the apex to scheduling the report to export and sent it to an email, the code is below:

global class Exporter implements System.Schedulable {
    global void execute(SchedulableContext sc) {
        ApexPages.PageReference report = new ApexPages.PageReference('/00O9000000213Md?excel=1');
        Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
        attachment.setFileName('report.xls');
        attachment.setBody(report.getContent());
        attachment.setContentType('application/vnd.ms-excel');
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        message.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment } );
        message.setSubject('Report');
        message.setPlainTextBody('The report is attached.');
        message.setToAddresses( new String[] {'tony@gmail.com'} );//,
        Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } );
    }
}
but the report.getContent() ofthe highlight line is not useful because it can't get data from report.
Do you know what should i do for it? My pleasure for you give me any suggestion...

  • January 11, 2013
  • Like
  • 0

Now i got a question that make me dizzy, the old version of salesforce is normal to display the pdf which is generate by apex code,but now, the version has upgrade to summer12 and there is a proplem to display the pdf unless i remove the picture of pdf head(logo), can you tell me what's wrong with it or some new functions have published that i didn't know? thank you and hope you to give me the good idea!!
code:
<apex:page renderAs="pdf" >
 <apex:image id="theImage2" url="{!URLFOR($Resource.Images, 'header.jpg')}" width="210" height="50"/>
</apex:page>

  • May 15, 2012
  • Like
  • 0

public class AllNewWelcomeLetter{

List<mbMemberAC__c> memberac;

public AllNewWelcomeLetter() {

}

List<Attachment> att;

public PageReference savePdf() {

memberac=[select id,MEnrollmentDate__c,Member_A_C_Client_name__c,Member_Chinese_Name__c,PRIVE_ADDR1__c,PRIVE_ADDR2__c,PRIVE_ADDR3__c,PRIVE_ADDR4__c,name from mbMemberAC__c where WelcomeLetterSenton__c=:null and MEnrollmentDate__c!=:null and MemberStatus__c=:'Active' ];

if(memberac.size()>0){

for(mbMemberAC__c mem:memberac){
//search the pdf name from attachment and judge if the old name is same as the new pdf name,pdf in present memAC is unique
att=[select Name from Attachment where ParentId =:mem.id and name=:mem.Member_A_C_Client_name__c+'.pdf'];

if(att.size()==0){

PageReference pdf = Page.WelcomeLetterForEach;

pdf.getParameters().put('id',mem.id);

Attachment attach = new Attachment();

// the contents of the attachment from the pdf
Blob body;

try {
// returns the output of the page as a PDF
body = pdf.getContent();

// need to pass unit test -- current bug
} catch (VisualforceException e) {
body = Blob.valueOf('Some Text');
}

attach.Body = body;
attach.Name = mem.Member_A_C_Client_name__c+'.pdf';
attach.IsPrivate = false;
// attach the pdf to the account
attach.ParentId =mem.id;
insert attach;

mem.WelcomeLetterSenton__c=date.today();
update mem;
}
}
}else{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL, '(error):The object memshipAC is null!');
ApexPages.addMessage(myMsg);
return page.WelcomeLetterPage;

}

return page.ListMembershipAC;
}

}

if i change the number 100 into 10 or less in method savePDF() , then it's ok! otherwise ,there will be the error message occurred,can you tell me how can i solve it. thank you very much!! 

 
  • May 09, 2012
  • Like
  • 0

The part of codes are my visualforce page code:


<apex:page controller="client_Controller"  tabStyle="account">


<style>


  .errorMessage{ color: red; font-weight: strong;}


 </style>


    <apex:messages styleClass="errorMessage"/> //this code is for display the error messages,and i

 

wanna make the font color red


</apex:page>

the result is the font color is still black,why?can you tell me how??

 

  • April 10, 2012
  • Like
  • 0

Hi all,
I have a question that need you help..
Now i wanna use the apex to scheduling the report to export and sent it to an email, the code is below:

global class Exporter implements System.Schedulable {
    global void execute(SchedulableContext sc) {
        ApexPages.PageReference report = new ApexPages.PageReference('/00O9000000213Md?excel=1');
        Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
        attachment.setFileName('report.xls');
        attachment.setBody(report.getContent());
        attachment.setContentType('application/vnd.ms-excel');
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        message.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment } );
        message.setSubject('Report');
        message.setPlainTextBody('The report is attached.');
        message.setToAddresses( new String[] {'tony@gmail.com'} );//,
        Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } );
    }
}
but the report.getContent() ofthe highlight line is not useful because it can't get data from report.
Do you know what should i do for it? My pleasure for you give me any suggestion...

  • January 11, 2013
  • Like
  • 0

Now i got a question that make me dizzy, the old version of salesforce is normal to display the pdf which is generate by apex code,but now, the version has upgrade to summer12 and there is a proplem to display the pdf unless i remove the picture of pdf head(logo), can you tell me what's wrong with it or some new functions have published that i didn't know? thank you and hope you to give me the good idea!!
code:
<apex:page renderAs="pdf" >
 <apex:image id="theImage2" url="{!URLFOR($Resource.Images, 'header.jpg')}" width="210" height="50"/>
</apex:page>

  • May 15, 2012
  • Like
  • 0

public class AllNewWelcomeLetter{

List<mbMemberAC__c> memberac;

public AllNewWelcomeLetter() {

}

List<Attachment> att;

public PageReference savePdf() {

memberac=[select id,MEnrollmentDate__c,Member_A_C_Client_name__c,Member_Chinese_Name__c,PRIVE_ADDR1__c,PRIVE_ADDR2__c,PRIVE_ADDR3__c,PRIVE_ADDR4__c,name from mbMemberAC__c where WelcomeLetterSenton__c=:null and MEnrollmentDate__c!=:null and MemberStatus__c=:'Active' ];

if(memberac.size()>0){

for(mbMemberAC__c mem:memberac){
//search the pdf name from attachment and judge if the old name is same as the new pdf name,pdf in present memAC is unique
att=[select Name from Attachment where ParentId =:mem.id and name=:mem.Member_A_C_Client_name__c+'.pdf'];

if(att.size()==0){

PageReference pdf = Page.WelcomeLetterForEach;

pdf.getParameters().put('id',mem.id);

Attachment attach = new Attachment();

// the contents of the attachment from the pdf
Blob body;

try {
// returns the output of the page as a PDF
body = pdf.getContent();

// need to pass unit test -- current bug
} catch (VisualforceException e) {
body = Blob.valueOf('Some Text');
}

attach.Body = body;
attach.Name = mem.Member_A_C_Client_name__c+'.pdf';
attach.IsPrivate = false;
// attach the pdf to the account
attach.ParentId =mem.id;
insert attach;

mem.WelcomeLetterSenton__c=date.today();
update mem;
}
}
}else{
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL, '(error):The object memshipAC is null!');
ApexPages.addMessage(myMsg);
return page.WelcomeLetterPage;

}

return page.ListMembershipAC;
}

}

if i change the number 100 into 10 or less in method savePDF() , then it's ok! otherwise ,there will be the error message occurred,can you tell me how can i solve it. thank you very much!! 

 
  • May 09, 2012
  • Like
  • 0

The part of codes are my visualforce page code:


<apex:page controller="client_Controller"  tabStyle="account">


<style>


  .errorMessage{ color: red; font-weight: strong;}


 </style>


    <apex:messages styleClass="errorMessage"/> //this code is for display the error messages,and i

 

wanna make the font color red


</apex:page>

the result is the font color is still black,why?can you tell me how??

 

  • April 10, 2012
  • Like
  • 0