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
BridgetreeBridgetree 

dynamic pageblocktable which get the contact email when a contact is selected through lookup.

Hi everyone


                I want to create a pageBlockTable such that, where in i have two fields for a custom Object. The Two fields are

1 . Lookup for Contact

2. Email.

 

Now in the pageBlockTable, i have a Add-Row functionality, upon doing this, i will have new row in the pageBlockTable.

The pageBlockTable has two fields.

        Contact Name (lookup)

        Email.

 

Now when i select the contact in the pageBlockTable, the related email should populate in the email field.

remember the pageBlockTable is refered to the Custom Object.

Please let me know the solution please.

Thanks in advance.

Navatar_DbSupNavatar_DbSup

Hi,

 

You can write a JavaScript function then call that function on key up event on Contact name that will call action function component that call a controller method that bind that email field and then render the panel under which email field  is written.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

BridgetreeBridgetree

But onclick how will i pass the contact Id in javascript function to apex:actionFunction ???

 

Please let me know with small ex if  you can.

 

Pls

 

Thanks for Replying.

 

Navatar_DbSupNavatar_DbSup

Hi,

 

Try out the below code snippet to work around on the above task

 

<Script>
                Function emailfun (conid)
                {
                                callactionfun(conid);
                }

</script>

 

<apex:inputField value="{!contact.name}" onchange="emailfun('{!contact.id}')">
                <apex:actionFunction name="callactionfun" action="{!emailvalue}">
<apex:param name="assignconid" value="" assignTo="{!conid}"/></apex:actionFunction>


If there any issue let me know.

 

 

BridgetreeBridgetree

Hi many thanks to you for giving concern.

 

Firstly, the i am not able to get the id from the javascript function. Tried doing alert, shows null.

 

Secondly, I am using this in pageBlockTable, i have a small confusion that, since the field will be the same, and when i create a new row, will i be able to select any other contact other than the previously selected contact name???

 

 

Pleas elet me know !!!

 

 

Thanks

BridgetreeBridgetree

Hi

 

              I did implementing the way i got the suggestion. But i did it using remote javascripting. I am trying to invoke the Function in the lookup field onchange event. This is not returning the values for me. where as when i try to the same sending it through a text box, this fetches the data.

Please let me where i  am wrong.

I am posting the code here

<apex:page controller="fetchDetailCon">
    <script type="text/javascript">
    
    function getRemoteContact() {
        var conName = document.getElementById('contSearch').value;
        alert (conName);
        fetchDetailCon.getContact(conName, function(result, event){
            if (event.status) {
                alert (result.Id);
                // Get DOM IDs for HTML and Visualforce elements like this
                document.getElementById('remoteAcctId').innerHTML = result.Id
                document.getElementById(
                    "{!$Component.block.blockSection.secondItem.acctNumEmployees}"
                    ).innerHTML = result.NumberOfEmployees;
            } else if (event.type === 'exception') {
                document.getElementById("responseErrors").innerHTML = event.message;
            } else {
                document.getElementById("responseErrors").innerHTML = event.message;
            }
        }, {escape:true});
    }
    </script>
    <apex:form >
    <input id="contSearch" type="text" onChange="getRemoteContact()"/>
    <br />
    <apex:inputField id="contSearch" onChange="getRemoteContact()" value="{!contact.AccountId}"/>
    <div id="responseErrors"></div>
    </apex:form>
    <apex:pageBlock id="block">
        <apex:pageBlockSection id="blockSection" columns="2">
            <apex:pageBlockSectionItem id="firstItem">
                <span id="remoteAcctId"/>
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem id="secondItem">
                <apex:outputText id="acctNumEmployees"/>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

 

global with sharing class fetchDetailCon {
    public String conName { get; set; }
    public static Contact contact { get; set; }
    public fetchDetailCon() { } // empty constructor
    
    
    @RemoteAction
    global static Contact getContact(String conName) {
        Account acc = [Select Id from Account where Name = :conName];
        contact = [Select Id from Contact where AccountId = :acc.id];
        return contact;
    }
}

cwall_sfdccwall_sfdc

Apart from apex:inputField having a dup id and your getRemoteContact funtion not grabing the apex:inputField value, I don't see anything incorrect in your source.  (Of course, you also need to query the number of employees.)

 

What are expecting?

BridgetreeBridgetree

Thanks everyone for replyin.. sad news is that the issue is not solved yet. Remote Javascripting is giving me serious bug, so as of which i am thinking to go back to first solution given to me.

Can anyone tell me, how to get the data of a particular contact in pageBlockTable in same  Row.