You need to sign in to do that
Don't have an account?
Access to a VF page extreamly slow
Hi all,
I wrote a simple VF page, and overrided the "New" button of Accout with it. Then i clicked the "new" button from the Accounts tab, after selecting a Recordtype and clicked the "Continue" button, it took me incrediblel 20 seconds to call this VF page out, sometimes even slower. But an click on a standard or custom tab won't take me more than 2 seconds to display information of that tab.
I know every first time an end user accesses a vf page, force.com platform application server will retrieves the page from the metadata repository and sends it to the Visualforce renderer for conversion into HTML. And maybe that's why it's so time-consuming.
Any way, it's nonsense to take so much time to show a simple vf page. Is there any thing i can do to solve this problem?
Any suggestion will be highly appreciated.
Paul, thanks for your reply, the code are as below
VF page:
<apex: page Controller="AccountDuplicationCheck" cache="true" expires="600" tabStyle="Account">
<style type="text/css" media="all">
.error {
margin: 0;
padding: 0;
background-color: #00E0AA;
}
</style>
<apex: form >
<apex: pageBlock>
<p>
<apex: pageBlockSection >
<apex: panelGrid columns="4">
<apex: outputLabel for="searchText">Custom Name:</apex: outputLabel>
<apex: inputText id="searchText" value="{!searchText}"/>
<apex: commandButton value="Search" action="{!doSearch}" rerender="results" status="search"/>
<apex: commandButton value="New" action="{!doCreate}" rerender="results" status="create"/>
</apex: panelGroup>
</apex: panelGrid>
</apex: pageBlockSection>
</p>
<p>
<apex: actionStatus id="search" startText="Searching..."/>
<apex: actionStatus id="create" startText="Creating..."/>
</p>
<apex: pageBlockSection title="Results({!count})" id="results" columns="1">
<apex: pageBlockTable value="{!accs}" var="acc" rendered="{!NOT(ISNULL(results))}">
<apex: column value="{!acc.name}"/>
</apex: pageBlockTable>
<apex: pageBlockSectionItem >
<apex: messages styleClass="error"/>
</apex: pageBlockSectionItem>
</apex: pageBlockSection>
</apex: pageBlock>
</apex: form>
</apex: page>
Controller:
public class AccountDuplicationCheck {
String searchText;
List<Account> accs;
Integer count;
Boolean exist;
public Boolean getExist () {
return exist;
}
public void setExist (Boolean b) {
exist = b;
}
public Integer getCount() {
return count;
}
public void setCount(Integer c) {
count = c;
}
public String getSearchText() {
return searchText;
}
public void setSearchText(String s) {
searchText = s.trim();
}
public List<Account> getAccs() {
return accs;
}
public void checkDuplication () {
//judge if there is a completely duplicated account
results = ( List<Account> ) [SELECT Name FROM Account WHERE Name = :searchText];
if (results.size() > 0) {
setExist(True);
}
else {
setExist(False);
}
}
public void checkSimilarAccounts() {
//search all similar accounts
if (searchText.equals('')) {
results.clear();
}
else
{
String st1 = '%' + searchText + '%';
results = ( List<Account> ) [SELECT Name FROM Account WHERE Name like :st1];
}
setCount(results.size());
}
public PageReference doSearch() {
//clear the error messages with the context
ApexPages.Message[] msgs = ApexPages.getMessages();
msgs.clear();
checkSimilarAccounts();
return null;
}
public PageReference doCreate() {
if (searchText.equals('') ) {
ApexPages.Message dupeMsg = new ApexPages.Message(ApexPages.Severity.ERROR,
'Need enter a custom name');
ApexPages.addMessage(dupeMsg);
return null;
}
checkDuplication ();
if (Exist) {
ApexPages.Message dupeMsg = new ApexPages.Message(ApexPages.Severity.ERROR,
'Custom ' + searchText + ' already exist!');
ApexPages.addMessage(dupeMsg);
return null;
}
else {
PageReference prf = ApexPages.currentPage();
String recordType = prf.getParameters().get('recordType');
Account a;
if (recordType != null) {
a = new Account(Name = searchText, RecordTypeId = recordType);
}
else {
a = new Account(Name = searchText);
}
insert a;
//get the header of the url seems like 'https://emea.salesforce.com/'
String url = ApexPages.currentPage().getUrl();
String urlHeader = url.substring(0, url.indexOf('/', 8)+2);
return new PageReference(urlHeader + a.id + '/e?retURL=/' + a.id);
}
}
}