• AvisheK
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies

Hi,

 

I need to create a pdf file and insert it to the attachment object as record. This would fire as a scheduled class and not on a button click in a Visualforce page.

The code is as below:

 

global class OrderDispatchToTopcall implements Schedulable{
/*
        Author            : Cognizant
        Functionality     : This is a helper class is for the creation of the Order Dispatch pdf file and attach to the batch object.
                            The class acts as a controller class for the pdf generation.
                            Fetches data from the objects like Purchase order, Job Elements, Supplier
        Create Date       : 15 May 2010
        Change History    :
        Modified Date     :
    */
global void execute(SchedulableContext SC) {
PageReference pdf =  Page.MerchantDeliveryChecklist;
     pdf.getParameters().put('id', 'a1CR000000044H8');
     pdf.getParameters().put('pageType', 'NCHODC');
     pdf.setRedirect(true);
     Blob b=pdf.getContentAsPDF();
    
     Attachment attachment=new Attachment(ParentId='a1CR000000044H8',body=b,ContentType='application/pdf',Name='test.pdf');
     insert  attachment;
}
}

global class OrderDispatchToTopcall implements Schedulable{

 global void execute(SchedulableContext SC) {

 PageReference pdf =  Page.MerchantDeliveryChecklist;    

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

 pdf.getParameters().put('pageType', 'NCHODC');    

 pdf.setRedirect(true);    

 Blob b=pdf.getContentAsPDF();      

  Attachment attachment=new Attachment(ParentId='a1CR000000044H8',body=b,ContentType='application/pdf',Name='test.pdf');    

insert  attachment;

 }

}

 

When this class runs it creates an attachment record but it is in a invalid format.

But when I call the same PDF creation code from button on a visualforce page, the attachment is created and it is a valid file.

 

Can somebody help me why I am not able to create a valid pdf file when the code runs from a schedular

 

I need to access the server variables from visual force page. A third party website is sending data by POST method. I need to access those information by the use of Request variables. This is can be done in ASP by the following method.

 

<HTML>
<BODY>
<%

dim fs,fname,path,timestamp

if Request.ServerVariables("request_method")="POST" then

    set fs=Server.CreateObject("Scripting.FileSystemObject")

    path="c:\" 'set your logfile directory path here
    timestamp=day(Date) & "-" & month(date) & "-" & year(date)
    timestamp=timestamp & "--" & hour(time) & "-" & minute(time) & "-" & second(time)

    set fname=fs.CreateTextFile(path & timestamp & "-" & Request.form("oid") & ".log",true)

    fname.WriteLine("OrderID - " & Request.Form("oid"))
    fname.WriteLine("Transaction Status - " & Request.Form("transactionstatus"))
    fname.WriteLine("Total - " & Request.Form("total"))
    fname.WriteLine("ClientID - " & Request.Form("clientid"))
    fname.WriteLine("Transaction Time Stamp - " & Request.Form("datetime"))
    fname.Close

    set fname=nothing
    set fs=nothing
   
end if


%>
</BODY>
</HTML>

 

Could anybody help me out on this problem?

 

Hi,

 

I have written an Apex Trigger which would automatically make the Case Aggignment Rule fire upon update of records either through front or back end using the AssignmentRuleHeader. This trigger was firing properly in the sandbox before the Winter 10 release came into effect. This code is still firing properly in Production which has not yet been upgraded to the Winter 10 release.

If anyone has faced a similar issue, and found a resolution, please provide me the same.

 

Thanking you in anticipation,

AvisheK

  • September 21, 2009
  • Like
  • 0

I need to access the server variables from visual force page. A third party website is sending data by POST method. I need to access those information by the use of Request variables. This is can be done in ASP by the following method.

 

<HTML>
<BODY>
<%

dim fs,fname,path,timestamp

if Request.ServerVariables("request_method")="POST" then

    set fs=Server.CreateObject("Scripting.FileSystemObject")

    path="c:\" 'set your logfile directory path here
    timestamp=day(Date) & "-" & month(date) & "-" & year(date)
    timestamp=timestamp & "--" & hour(time) & "-" & minute(time) & "-" & second(time)

    set fname=fs.CreateTextFile(path & timestamp & "-" & Request.form("oid") & ".log",true)

    fname.WriteLine("OrderID - " & Request.Form("oid"))
    fname.WriteLine("Transaction Status - " & Request.Form("transactionstatus"))
    fname.WriteLine("Total - " & Request.Form("total"))
    fname.WriteLine("ClientID - " & Request.Form("clientid"))
    fname.WriteLine("Transaction Time Stamp - " & Request.Form("datetime"))
    fname.Close

    set fname=nothing
    set fs=nothing
   
end if


%>
</BODY>
</HTML>

 

Could anybody help me out on this problem?

 

Hi,

 

I have written an Apex Trigger which would automatically make the Case Aggignment Rule fire upon update of records either through front or back end using the AssignmentRuleHeader. This trigger was firing properly in the sandbox before the Winter 10 release came into effect. This code is still firing properly in Production which has not yet been upgraded to the Winter 10 release.

If anyone has faced a similar issue, and found a resolution, please provide me the same.

 

Thanking you in anticipation,

AvisheK

  • September 21, 2009
  • Like
  • 0