• Fiona Lui
  • NEWBIE
  • 0 Points
  • Member since 2007

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

I got error "Time limit exceeded-Your request exceeded the time limit for processing. " when generating PDF file by following code frequently. Is there any way to set the Time Limit to a larger value?
Code:
public class MyController {     
    public PageReference getDeliverAsPDF() {     
        // Reference the page, pass in a parameter to force PDF     
        PageReference pdf = ApexPages.currentPage();     
        pdf.getParameters().put('p','p');      
        pdf.setRedirect(false);     
    
        // Grab it!      
        Blob b = pdf.getContent();     
        
        //Prepare Parameters
        Id id= System.currentPageReference().getParameters().get('Id');
        List<Account> accountName= [SELECT Id, Name FROM account WHERE ID = :id];
        
        // Create an email     
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();      
        email.setSubject('Contact Information of ' + accountName[0].Name);     
        String [] toAddresses = new String[] {'abcd@hotmail.com'};     
        email.setToAddresses(toAddresses);      
        email.setPlainTextBody('Please find the following attached pdf.');     
        
        // Create an email attachment     
        Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();     
        efa.setFileName(accountName[0].Name + '.pdf'); 
    
        // neat - set name of PDF     
        efa.setBody(b); 
    
        //attach the PDF     
        email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});     
    
        // send it, ignoring any errors (bad!)     
        Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); 
        
        return null; 
    }
    
    
    public PageReference invokeService() {
        Id id = System.currentPageReference().getParameters().get('id');
        result = [SELECT Name FROM Contact WHERE Id=:id].Name;
        //returning null indicates the same page should be returned - in place change
        return null;
    }

    public List<Contact> getMyContacts() {
        Id id= System.currentPageReference().getParameters().get('Id');
        return [SELECT Id, Name, Title, Email, Phone, Fax FROM Contact WHERE AccountID = :id];
    }
}

 
Code:
<apex:page controller="MyController" renderAs="{!if($CurrentPage.parameters.p == null, null, 'pdf')}" tabStyle="Account">
<apex:form>
  <apex:pageBlock title="Contact Information">
  <apex:dataTable value="{!myContacts}" var="aContact" width="100%">
  <apex:column>
  <apex:facet name="header"><b>ID</b></apex:facet>
  {!aContact.id}
  </apex:column>
  
  <apex:column>
  <apex:facet name="header"><b>Name</b></apex:facet>
  {!aContact.Name}
  </apex:column>
 
  <apex:column>
  <apex:facet name="header"><b>Title</b></apex:facet>
  {!aContact.Title}
  </apex:column>
  
  <apex:column>
  <apex:facet name="header"><b>Email</b></apex:facet>
  {!aContact.Email}
  </apex:column>
  
  <apex:column>
  <apex:facet name="header"><b>Phone</b></apex:facet>
  {!aContact.Phone}
  </apex:column>
  
  <apex:column>
  <apex:facet name="header"><b>Fax</b></apex:facet>
  {!aContact.Fax}
  </apex:column>

  </apex:dataTable>
  <apex:commandLink rendered="{!$CurrentPage.parameters.p == null}"  value="PDF" action="{!getDeliverAsPDF}"></apex:commandLink>
  </apex:pageBlock>
  </apex:form>
  
  <apex:detail relatedList="true" />
</apex:page>

 


Message Edited by Fiona Lui on 06-30-2008 03:28 AM

Message Edited by Fiona Lui on 06-30-2008 03:31 AM

Message Edited by Fiona Lui on 06-30-2008 03:34 AM

Message Edited by Fiona Lui on 07-01-2008 06:25 PM
As i created a managed package in my development org to test some behaviours of upgrading managed pack. After testing, i found some of edit functions are locked. I want to delete the managed package to unlock the edit functions. But the Delete button in the upload history was disabled.Is there anyway I can delete the managed package?
I would like to check if the field-level sercurity is also an editable but not upgradeable component. That means when I upgade the managed package, the field-level sercurity set by installer will not be overwritten during upgrades. Thanks!

I created a unmanaged package in development environment. The package contains custom object which has trigger implementation. I pack the package and upload to AppExchange. After Installing the package in another development enviornment, I found that trigger implementation didn't installed. Is it the expected behaviour? If not, how can I install the triggers implemented ? Thanks!


I got error "Time limit exceeded-Your request exceeded the time limit for processing. " when generating PDF file by following code frequently. Is there any way to set the Time Limit to a larger value?
Code:
public class MyController {     
    public PageReference getDeliverAsPDF() {     
        // Reference the page, pass in a parameter to force PDF     
        PageReference pdf = ApexPages.currentPage();     
        pdf.getParameters().put('p','p');      
        pdf.setRedirect(false);     
    
        // Grab it!      
        Blob b = pdf.getContent();     
        
        //Prepare Parameters
        Id id= System.currentPageReference().getParameters().get('Id');
        List<Account> accountName= [SELECT Id, Name FROM account WHERE ID = :id];
        
        // Create an email     
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();      
        email.setSubject('Contact Information of ' + accountName[0].Name);     
        String [] toAddresses = new String[] {'abcd@hotmail.com'};     
        email.setToAddresses(toAddresses);      
        email.setPlainTextBody('Please find the following attached pdf.');     
        
        // Create an email attachment     
        Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();     
        efa.setFileName(accountName[0].Name + '.pdf'); 
    
        // neat - set name of PDF     
        efa.setBody(b); 
    
        //attach the PDF     
        email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});     
    
        // send it, ignoring any errors (bad!)     
        Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); 
        
        return null; 
    }
    
    
    public PageReference invokeService() {
        Id id = System.currentPageReference().getParameters().get('id');
        result = [SELECT Name FROM Contact WHERE Id=:id].Name;
        //returning null indicates the same page should be returned - in place change
        return null;
    }

    public List<Contact> getMyContacts() {
        Id id= System.currentPageReference().getParameters().get('Id');
        return [SELECT Id, Name, Title, Email, Phone, Fax FROM Contact WHERE AccountID = :id];
    }
}

 
Code:
<apex:page controller="MyController" renderAs="{!if($CurrentPage.parameters.p == null, null, 'pdf')}" tabStyle="Account">
<apex:form>
  <apex:pageBlock title="Contact Information">
  <apex:dataTable value="{!myContacts}" var="aContact" width="100%">
  <apex:column>
  <apex:facet name="header"><b>ID</b></apex:facet>
  {!aContact.id}
  </apex:column>
  
  <apex:column>
  <apex:facet name="header"><b>Name</b></apex:facet>
  {!aContact.Name}
  </apex:column>
 
  <apex:column>
  <apex:facet name="header"><b>Title</b></apex:facet>
  {!aContact.Title}
  </apex:column>
  
  <apex:column>
  <apex:facet name="header"><b>Email</b></apex:facet>
  {!aContact.Email}
  </apex:column>
  
  <apex:column>
  <apex:facet name="header"><b>Phone</b></apex:facet>
  {!aContact.Phone}
  </apex:column>
  
  <apex:column>
  <apex:facet name="header"><b>Fax</b></apex:facet>
  {!aContact.Fax}
  </apex:column>

  </apex:dataTable>
  <apex:commandLink rendered="{!$CurrentPage.parameters.p == null}"  value="PDF" action="{!getDeliverAsPDF}"></apex:commandLink>
  </apex:pageBlock>
  </apex:form>
  
  <apex:detail relatedList="true" />
</apex:page>

 


Message Edited by Fiona Lui on 06-30-2008 03:28 AM

Message Edited by Fiona Lui on 06-30-2008 03:31 AM

Message Edited by Fiona Lui on 06-30-2008 03:34 AM

Message Edited by Fiona Lui on 07-01-2008 06:25 PM
I have a Visualforce page that renders as PDF (depending on an incoming parameter) when a button is pushed.
However, if that button has a "rendered" attribute, then the PDF fails to render for some reason.  (I don't want the button rendered if I'm producing a PDF, as I don't want to see it in the PDF). Instead, the page simply refreshes.  This seems a little odd - any idea what's up?

Here' s the page:
<apex:page renderAs="{!chooserender}" controller="MyController" > 
  <apex:pageBlock title="Some Page Block">
   <apex:pageBlockSection title="Section 1"> Text </apex:pageBlockSection>
   <apex:pageBlockSection title="Section 2"> Text </apex:pageBlockSection>
  </apex:pageBlock>
  
  <apex:form >
  <apex:commandLink rendered="{!$CurrentPage.parameters.p == null}"  value="PDF" action="{!deliverAsPDF}" target="_blank"></apex:commandLink>
  </apex:form>

</apex:page>

 Here's the controller:
public class MyController {

  public String getChooserender() {
     if (ApexPages.currentPage().getParameters().get('p') != null)
        return 'pdf';
        else
      return null;
  }

  public PageReference deliverAsPDF() {
      PageReference pdf =  Page.foo;
        pdf.getParameters().put('p','p');
        return pdf;
  }

}

I've blogged about this (sans problem) here.
 
I know I can solve my problem in a different way (style sheets come to mind), but I'd really like to figure out why, when a button has a rendered='false', it no longer generates a PDF. (I mean, I've already pushed it, and an action is occuring, so whether the button itself is present or not in the result shouldn't matter?)

Thanks!