You need to sign in to do that
Don't have an account?
Arup..
Pop up window in visualforce
Hi,
I am new in Salesforce...I want to design a pop up window. The window will appear after save button is hit which will show the values those an user has entered as input. After the pop up comes out then the user will click the ok in pop up and the page will be redirected to the object view page.
Now how can I implement it throgh java script or any other possible way.
Can u pls provide some sample coding for it.
Thanks in advance,
Hi,
I will provide an example for popup. Try to understand and convert it to your requirement.
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
chamil's blog
All Answers
Hi,
I will provide an example for popup. Try to understand and convert it to your requirement.
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
chamil's blog
chamil this is great. you are a savior :)
is it possible to create a test method unit for your class.
we would really appreciate for us newbiees in here
thanks
Hi,
Yes, It is possible to create test methods to this class(in normal manner).
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
Chamil's Blog
Great, chamil thanks,
can you you help us out with this class? thanks in advance
Hi,
You mean, you need a test class for the class which I have posted before. There is no any implementation to test. Therefore, you have to implment your scenario and after that consider about the test class. I just gave the example to get an idea about the popup. I'll help you to write the test class.
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
chamil's blog
Awesome, thanks chamil
Chamil,
Will this inactivate the other section of VF page other than the pop up. I mean a grayout? Could you please help me with gray out? I'm kinda green to Jquery/javascript/css !
Thanks.
@Srinath
This example has not a disabled backgroup.
Refer this link. It has disabled background : http://www.salesforcegeneral.com/salesforce-modal-dialog-box/
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
Hi
I am new to salesforce and need a sample code for a popup window when a user login for the first time only.Your help will be appriciated.
Hey Splash,
i hope this get you started
<script>
if(!{!Account.IsSubmittedForApproval__c})
alert('Please Submit the Account for Approval.');
</script>
this is a script for alerts in Account approvals. make sure you put it inside the <apex:page> </apex:page>
i hope it helps
I wonder if we want to refresh other panel after we closing the popup window, why we can't use reRender?I tried and it does not work.I am not understand because reRender suppose to render the panel that we want to.Example:
<apex:commandButton value="Ok" action="{!redirectPopup}" styleClass="closeButton" rerender="nameofPaneltheoutsidepopup">
Hi Arup
i have same requirement like your. Can you please share your code.
Thanks
Shobana
I have problem on the pop up window My code is as like your code Can you help me to solve my code issue?
Thanks
Mohan
I am using your example but in this i got one error
Like :
Error: Compile Error: unexpected token: 'redirectPopup' at line 22 column 28
i have used your example for popup window its working fine in my inline visualforce page. but when we close the popup window what ever the changes we have done before clicking the "X" those should be rollbacked when we close the popup(suppose i have checked the check box and entered the data in inputtext field and the click on the save button then popup will come again i entered some data then i dont what the save then i clicked the "X" button to close popup then the check box should be unchcked and input text fileds should be blank). can you please help me how to achive it. please send me sample code to be used in inline visualforce page. i have tried to refresh page when command button "X" is clicked using rerender. page is refreshing but changes are not getting rollback.
Thanks,
sai
My controller,
and my page:
if it help note the best answer it's will help to other please.
// The controller for main VF page vfAssignNewAccountToContact
public with sharing class AssignNewAccountToContact
{
public Contact c {get;set;}
public String selectedAccountName {get;set;}
public String selectedAccountId {get;set;}
public AssignNewAccountToContact()
{
selectedAccountName = '';
selectedAccountId = '';
c = [select id, name from Contact where id = :ApexPages.currentPage().getParameters().get('id')];
System.debug('////////////c is ' + c);
}
public pageReference changeTheAccount()
{
System.debug('//////////selectedAccountId is ' + selectedAccountId);
System.debug('//////////selectedAccountName is ' + selectedAccountName);
if(selectedAccountId != '')
{
System.debug('//////////selectedAccountId is not null, so proceeding ');
c.accountId = selectedAccountId;
update c;
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.info, 'New account assigned successfully'));
/*
Make variables null, so that if something is typed now in the textbox,
it gives error message if "Assign new account" is clicked again.
*/
selectedAccountId = '';
selectedAccountName = '';
}
else
{
System.debug('//////////selectedAccountId is null');
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.error, 'Kindly select an account by clicking on Lookup'));
}
return null;
}
//For clearing success/error message shown on the VF page after Lookup is clicked.
public pageReference clearMessages()
{
ApexPages.getMessages().clear();
return null;
}
}
<!--
VF page name :- vfAssignNewAccountToContact
Main VF page for assigning new account to a contact. Go to an existing contact record and add
/apex/vfAssignNewAccountToContact?id=<ContactRecordID> to the URL to view this VF page.
-->
<apex:page controller="AssignNewAccountToContact">
<apex:form >
<apex:PageMessages id="messages"/>
Click on Lookup to select a new account for this contact and then click on "Assign new account"
<apex:pageBlock title="Contact Details">
Contact name: {!c.name}
<br/>
<apex:pageBlockSection >
<apex:inputText value="{!selectedAccountName}" id="accountName" label="Account"/>
<a onclick="clearMessagesNow();popUp();" style="cursor: pointer;">Lookup</a>
<apex:inputHidden value="{!selectedAccountId}" id="accountId"/>
<script>
var objInputName = '{!$Component.accountName}';
var objInputId = '{!$Component.accountId}';
function popUp()
{
var objAccountInput = document.getElementById(objInputName);
//alert('parameter is ' + document.getElementById(objInputName).value);
var urlAdd = 'vf_AccountLookup_Controller';
if(objAccountInput.value.length > 0)
{
urlAdd += '?srch=' + objAccountInput.value;
//alert('urlAdd is ' + urlAdd);
}
var newWindow = window.open(urlAdd,'Popup','height=500,width=700,left=150,top=50,resizable=no,scrollbars=yes,toolbar=no,status=no');
}
function setAccount(recordId,recordName)
{
//alert('recordId is ' + recordId);
//alert('recordName is ' + recordName);
document.getElementById(objInputName).value = recordName;
document.getElementById(objInputId).value = recordId;
}
</script>
<br/>
<apex:commandButton value="Assign new account" action="{!changeTheAccount}"/>
<!--
For clearing success/error message shown on the VF page after Lookup is clicked.
-->
<apex:actionFunction name="clearMessagesNow" action="{!clearMessages}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
// The controller for the lookup popup box for selecting new account for a contact.
public class AccountLookup_Controller
{
public String searchText {get;set;}
public List<Account> searchResults {get;set;}
public AccountLookup_Controller()
{
// get search parameter from url if present
if(ApexPages.currentPage().getParameters().containsKey('srch'))
{
searchText = ApexPages.currentPage().getParameters().get('srch');
}
else
{
searchText = '';
}
searchResults = [Select Id, Name, AccountNumber, Site From Account Where Name Like : searchText + '%'];
}
public void searchRecords()
{
searchResults = [Select Id, Name, AccountNumber, Site From Account Where Name Like : searchText + '%'];
}
}
<!--
VF page name :- vf_AccountLookup_Controller
The VF page for the lookup popup box which appears for selecting new account for a contact.
-->
<apex:page controller="AccountLookup_Controller" showHeader="false" sidebar="false">
<apex:form >
<script>
window.onblur = function() {
// close this popup window if it loses focus, that is, goes into the background
self.close();
}
document.onblur = window.onblur;
document.focus = window.focus;
</script>
<apex:pageBlock >
<apex:sectionHeader title="Select the account to be associated with the contact"/>
<apex:inputText value="{!searchText}" onkeyup="searchImmediately()"/>
<apex:commandButton value="Go" action="{!searchRecords}"
rerender="results"/>
<apex:actionFunction name="searchImmediately" action="{!searchRecords}" reRender="results"/>
<apex:pageBlocksection title="Account Search Results" id="results">
<apex:pageBlockTable value="{!searchResults}" var="a"
rendered="{!searchResults.size>0}">
<apex:column headerValue="Name">
<a style="cursor:pointer;"
onclick="window.opener.setAccount('{!a.Id}', '{!a.Name}');
self.close();">
{!a.name}
</a>
</apex:column>
<apex:column headerValue="Account Number" value="{!a.AccountNumber}"/>
<apex:column headerValue="Account Site" value="{!a.Site}"/>
</apex:pageBlockTable>
<apex:outputText value="No results found"
rendered="{!searchResults.size=0}"/>
</apex:pageBlocksection>
</apex:pageBlock>
</apex:form>
</apex:page>
can anyone help me!!
Thanks for the above code. It was very helpful. Cheers!
Thanks,
Abhiraj
@Mohan Raj 33
Hello Mohan... I have the similar requirement but your code suits my requirement very well but can we just show few account fields directly instead of showing the list of account and choose accounts (I'm trying to have this code at account record level in a button - like a questionnaire form). Upon clicking on this button like your code does, it should show couple of field of that particular account record. And should able to do modification and able to save like your code does.
Your help is very much appreciated!
Many Thanks!
<style type="text/css">
.custPopup{ background-color: white; border-width: 2px; border-style: solid; z-index: 9999; left: 50%; padding:11px; position: absolute; width: 600px; margin-left: -240px; top:100px; }
.popupBackground{ background-color:black; opacity: 0.20; filter: alpha(opacity = 20); position: absolute; width: 100%; height: 100%; top: 0; left: 0; z-index: 9998; }
</style>
<apex:pageBlockButtons location="Top">
<apex:commandButton value="Submit" action="{!saveApplication}" rerender="tstpopup" disabled="{!Edit}"/>
<!-- <apex:commandButton value="Show" action="{!showPopup}" rerender="tstpopup"/>-->
<apex:outputPanel id="tstpopup">
<apex:outputPanel styleClass="popupBackground" layout="block" rendered="{!displayPopUp}"/>
<apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displayPopUp}">
<b>Record updated!</b>
<apex:commandButton value="OK" action="{!closePopup}" rerender="tstpopup"/>
</apex:outputPanel>
</apex:outputPanel>
<apex:commandButton value="Cancel" action="{!Cancel}" disabled="{!Edit}"/>
<apex:commandButton value="Back" action="{!Back}"/>
</apex:pageBlockButtons>
<apex:pageBlock>
<apex:pageBlockButtons location="Bottom">
<apex:commandButton value="Submit" action="{!saveApplication}" rerender="tstpopup" disabled="{!Edit}"/>
<apex:outputPanel id="tstpopup">
<apex:outputPanel styleClass="popupBackground" layout="block" rendered="{!displayPopUp}"/>
<apex:outputPanel styleClass="custPopup" layout="block" rendered="{!displayPopUp}">
<b>Record updated!</b>
<apex:commandButton value="OK" action="{!closePopup}" rerender="tstpopup"/>
</apex:outputPanel>
</apex:outputPanel>
<apex:commandButton value="Cancel" action="{!Cancel}" disabled="{!Edit}"/>
<apex:commandButton value="Back" action="{!Back}"/>
</apex:pageBlockButtons>
</apex:pageBlock>