function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vishal gupta 47vishal gupta 47 

modal popup from visual force page


How show a popup when one of the buttons is clicked. Something like a modal popup where user has to fill in something or click the cancel button in the popup page before to go back to the calling page.

Could someone point me with any sample code.
Best Answer chosen by vishal gupta 47
NagendraNagendra (Salesforce Developers) 
Hi Vishal,

If you are using a lookup window to find a contact, what about creating a custom lookup window to which you add a "create contact" button. Use the create button to replace the lookup content with new contact fields right in that window, simple as re-rendering the page using render flags. That way its in keeping with standard salesforce UX and your users will possibly embrace the custom functionality more easily.

The only moderately difficult part is getting the selection back from the child lookup window to the parent.

These functions go on the parent VF page:
function openPopupFocus(a, b, c, d, e, f, g, k) {
    closePopup();

    if (f) {
        if (lastMouseX - c < 0) 
            lastMouseX = c;
        if (lastMouseY + d > screen.height) 
            lastMouseY -= lastMouseY + d + 50 - screen.height;
        lastMouseX -= c;
        lastMouseY += 10;
        e += ",screenX=" + lastMouseX + ",left=" + lastMouseX + ",screenY=" + lastMouseY + ",top=" + lastMouseY
    }

    curPopupWindow = window.open(a, b, e, false);
    curPopupWindow.focus()

    if (k) 
        closeOnParentUnloadWindow = win
}

function closePopup() {
    if (closetimer) {
        clearTimeout(closetimer);
        closetimer = null
    }
    if (curPopupWindow != null) {
        try {
            if (curPopupWindow.confirmOnClose) if (curPopupWindow.confirm(curPopupWindow.confirmOnCloseLabel)) {
                curPopupWindow.confirmOnClose = false;
                curPopupWindow.focus();
                return false
            }
            curPopupWindow.close()
        } catch (a) {}
        curPopupWindow = null
    }
}
Link to open the window
openPopupFocus(%27/apex/<VF PAGE NAME>?filter=item%27, %27CCBCCLookup%27, 420, 490, %27width=420,height=490,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no%27, true);​
This function goes on the custom lookup page:
function sendToParent(selectedId,selectedName){

        top.window.opener.doLookupPick(<hidden field dom id>,
                                         <selected sfObject ID>,
                                         <text input field dom id>',
                                         <text input contact name>);


}

Please mark this post as solved if it's resolved.

Best Regards,
Nagendra.P

All Answers

NagendraNagendra (Salesforce Developers) 
Hi Vishal,

If you are using a lookup window to find a contact, what about creating a custom lookup window to which you add a "create contact" button. Use the create button to replace the lookup content with new contact fields right in that window, simple as re-rendering the page using render flags. That way its in keeping with standard salesforce UX and your users will possibly embrace the custom functionality more easily.

The only moderately difficult part is getting the selection back from the child lookup window to the parent.

These functions go on the parent VF page:
function openPopupFocus(a, b, c, d, e, f, g, k) {
    closePopup();

    if (f) {
        if (lastMouseX - c < 0) 
            lastMouseX = c;
        if (lastMouseY + d > screen.height) 
            lastMouseY -= lastMouseY + d + 50 - screen.height;
        lastMouseX -= c;
        lastMouseY += 10;
        e += ",screenX=" + lastMouseX + ",left=" + lastMouseX + ",screenY=" + lastMouseY + ",top=" + lastMouseY
    }

    curPopupWindow = window.open(a, b, e, false);
    curPopupWindow.focus()

    if (k) 
        closeOnParentUnloadWindow = win
}

function closePopup() {
    if (closetimer) {
        clearTimeout(closetimer);
        closetimer = null
    }
    if (curPopupWindow != null) {
        try {
            if (curPopupWindow.confirmOnClose) if (curPopupWindow.confirm(curPopupWindow.confirmOnCloseLabel)) {
                curPopupWindow.confirmOnClose = false;
                curPopupWindow.focus();
                return false
            }
            curPopupWindow.close()
        } catch (a) {}
        curPopupWindow = null
    }
}
Link to open the window
openPopupFocus(%27/apex/<VF PAGE NAME>?filter=item%27, %27CCBCCLookup%27, 420, 490, %27width=420,height=490,toolbar=no,status=no,directories=no,menubar=no,resizable=yes,scrollable=no%27, true);​
This function goes on the custom lookup page:
function sendToParent(selectedId,selectedName){

        top.window.opener.doLookupPick(<hidden field dom id>,
                                         <selected sfObject ID>,
                                         <text input field dom id>',
                                         <text input contact name>);


}

Please mark this post as solved if it's resolved.

Best Regards,
Nagendra.P
This was selected as the best answer