I am trying to open standard page from a custom Visualforce Page through javascript using command button.But it reacts differently each time.It works properly sometimes.But in some cases it opens a blank window.
<apex:outputPanel id="jspanel">
<script>
function onControllerReturn() {
window.open('{!message}','_blank');
}
</script>
</apex:outputPanel>
<apex:actionFunction name="doControllerSave" action="{!merged}"
oncomplete="onControllerReturn()" rerender="jspanel" />
<apex:commandButton onclick="doControllerSave()" value="Merge" rerender="none" style="background:#D3D3D3;width:150px;" status="loadStatus"/>
Message contains URL Parameter to be passed.
Class:
public PageReference Merged() {
update ac1;
string mergeURL = '';
mergelst = new List<String> ();
for(Account a:selectedAccounts){
// mergeURL=a.id;
System.debug('size of accounts'+mergeURL);
account maxvalue=selectedAccounts.get(selectedAccounts.size() - 1); string
nextvalue=maxvalue.id;
System.debug('lastaccountid'+nextvalue);
mergeURL +='&cid='+a.Id; // mergelst.add(mergeURL);
}
try {
message ='/merge/accmergewizard.jsp?goNext=+Next+'+mergeURL ;
} catch(Exception e)
{
ApexPages.addMessages(e); message = 'Whoops! An error occurred -- ' + e.getMessage();
}
return null;
}
Need Suggestions.Urgent..
Best Answer
message might get empty values sometimes. to get updated values on message variable. try this code.
Points to remember 1. script should be rerendered then you will get modified values from controller
Apex Class: