You need to sign in to do that
Don't have an account?
Fiona Lui
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?
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
Time Limit Exceeded when Generating PDF File
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
With that said the issue here is not actually a time limit - it is an issue with the way our service detects what it believes is a duplicate request and then kills the request and gives you this generic message. This is something we are looking into - no easy automatic solution that also satisfies the kind of protections we need for our service.
One workaround is to get the url of the requesting page to be different from the page that the action is being invoked from - refactor the markup in your page into a component and then reference that component from 2 separate visualforce pages (one for pdf generation and the other for direct access).
ok. I got it. Thanks!
I get this error erratically too and it is hard to debug.
I have one VF page (which renders differently based on certain flag using the render attribute) and one controller.
The reason I ended up with this was because I needed to retain the context of the controller - an array in the controller created in phase 1 was required for phase 2. Phase 1 renders part of the page. when an action link is clicked in Phase 1, Phase 2 renders other part of the page.
Phase 2 of the page has another action button which fires workflow e-mail alerts for all elements in the array. When this action button is clicked, I get the Time Limit exceeded message. It doesn't seem to depend on size of the array - in test mode, it works fine with 1000 elements in the array. It fails sometimes when there are 60 or 70 elements in the array...
I am going to try it by separating this into two separate pages and going to the second page with setReDirect as false. Will that resolve the issue?
Since it is erratic, I appreciate a confirmation.
I
What I tried did not work.
Doug, we filed case # 02857653 to request help.
To summarize again our example through code after the refactoring effort we did. When I click the "'fire Action" button on page 2, we run into this issue. In my test environment, there were a 1000 records did not run into the issue. In production environment, we ran into this issue with only 60 record.
class SharedController {
integer drillDownRow; //o to 5
List of List contextObjects;//six entries, each entry is an array of sobjects.
public SharedController() {
compute contextObjects;
}
public pageReference drillDown() {
//get the drill down row
string DdRow = System.currentPageReference().getParameters().get('DrillDownRow');
DrillDownRow = Integer.Valueof(DdRow);
page2.setRedirect(false); //so the contextObjects are not lost
return page2;
}
//call to fireworkFlow runs into Time Limit Exceeded.
public pageReference fireActionThatHasTimeLimitExceeded()
{
recordToOperateOn = contexObjects[drillDownRow];
//in test environment, this does NOT time out with 1000 records.
//in production environment it times out with 60 odd records, not always - erratically.
some Code to fire workflow on recordsToOperatOn;
return null;
}
}
<apex:page Controller="SharedController"
....
<apex:commandLink action="{!DrillDown}" value={!aStatus.coun <apex:param name="DrillDownRow" value="{!aStatus.Row}"/>
</apex:commandLink>
<apex:dataTable>
...show the table of 6 rows with number of entries in each
contextObjects
</apex:dataTable>
</apex:page>
Page 2:
<apex:page Controller="SharedController">
<apex:commandButton action="{!fireActionThatHasTimeLimitExceeded}"
value="Fire Action"
<apex:DataTable>
...show the table of ContextObjects[drillDownRow]
</apex:DataTable>
</apex:page>
Thanks a lot for sharing your code. which is very useful for me ....
Regards,
Mahendiran
i got the same error, while generating a VF page. what is reason behind this?
Need Help.
There was a issue with the SOQL query. The query was taking a longer time to execute and when it was crossing 120 seconds, it was giving time out error. i had to use some index fields in my query to narrow the query range. it worked for me.
Hi Friends,
I am also having same problem.Am tring this issue for last five days but not complete this issue and also posted my controller code.please can anyone help me.i need solution how to resolve this err.Is it possible r not i like to know? thanks in advance.
Regards,
kathir