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
TLeahyTLeahy 

Auto-Populate account lookup field on VF page from custom object field

On a custom object I have [Work Order], I have a custom link which is intended to add a contact to an account defined in the lookup field on the Work Order [this is a lookup relationship, not a master-detail]. I have it all set up so that upon clicking the custom link on the Work Order, a small window pops up with the contact fields I want, and upon clicking the "save" button it successfully saves to the appropriate account - it just has to be manually entered.

 

I just want to some how carry the account listed in the "Contractor Account" lookup field on the workorder, into the account lookup field for the contact in the VF page that the link pops up. I know it is not a very big deal to just type it out, but anything to easy and hasten the proccesses is a help.

 

Is this possible?

 

Also, a side issue not terribly important, is I would prefer the window to close after saving the new contact, but it loads the new contact's page in the popup.

 

Here is the visualforce page I created:

 

<apex:page standardController="Contact" showHeader="false" sidebar="false" showChat="false">

<apex:form >
<apex:pageBlock mode="inlineEdit" id="AddTech" >

<apex:inlineEditSupport showOnEdit="saveButton, cancelButton"  hideOnEdit="editButton" event="ondblclick"  changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>

        <apex:outputPanel id="AddTech">
            <apex:commandButton action="{!Save}" id="saveButton" value="Save" status="closer"/>
            <apex:commandButton value="Cancel" onclick="window.top.close()"/>
            <apex:actionStatus startText="(Saving...)" stopText="" onStop="window.top.close();" id="closer"/>
        </apex:outputPanel>

    <apex:pageBlockSection >

            <apex:outputField title="Account" value="{!Contact.AccountId}"/>
            <apex:outputField title="Title" value="{!Contact.Title}"/>
            <apex:repeat value="{!$ObjectType.Contact.FieldSets.Name}" var="name">
                <apex:outputField value="{!Contact[name]}"></apex:outputField></apex:repeat>
            <apex:outputField title="Mobile Phone" value="{!Contact.MobilePhone}"/>
            <apex:outputField title="Email" value="{!Contact.Email}"/>

    </apex:pageBlockSection>
    
</apex:pageBlock>
</apex:form>
</apex:page>

 and the custom link on the work order has the content source listed as URL, and that URL is:

 

/apex/page/AddTechWO

 

 

MrMarcMrMarc

-bump-

 

I'm looking for this answer, too.