weve used this before: http://www.tehnrd.com/visualforce-pop-up/ but that aside.
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
}
}
function doLookupPick(a,b,c,d){
$(a).val(b);
$(c).val(d);
closePopup();
}
the 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>);
}
Members of Trigger.new are read only in the after cycle.
In order to take action on an record in Trigger.new after insert/update, you need to create a new instance of each sObject record you want to work with and add it to a new list for update purposes.
...assuming after insert trigger on account...
List<Account> accts = new List<Account>();
for (Account a: Trigger.new) {
if (some condition) {
...take action on a...
Account acctToUpdate = new Account(id=a.Id, ...other updates...);
accts.add(acctToUpdate);
}
}
update accts;
The only thing here is if you also do this on update, you will run into a recursive trigger problem, but this is easily remedied by using the recursive trigger pattern found here in this cookbook recipe.
Best Answer
It is not possible to fire user interface interaction from a trigger, except that throwing an exception in a trigger can result in surfacing an error in a UI context if there is one. For example, throwing an exception in a trigger that is fired due to a user's edit action in a standard page will show an error on that page. However, no further UI-based interaction with the trigger is possible, and all data updates made during the transaction are rolled back.
It is not possible to surface a modal from a trigger and engage in user interaction.
Since triggers run in both UI (Classic/Lightning) interactions and in backend (API/Process/Flow) actions, in many cases there is no UI at all.