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
SayasoniSayasoni 

Help in auto-populating Contact email field on the Visualforce page Side

I have a controller that helps me in creating a new contact record using values from another custom object. The Contact Email field is supposed to be auto-filled with Emails field from another cutom object based on the If Statement in my controller.Everything works fine since when i create the new contact & leave the Email field blank & click save,the Email field on the newly created record contains the email value.My problem is making this value visible on my visualforce page before clicking save.

Here is a part of my controller & the visualforce pages for both Creating new Contact & my Custom object :

 

  public pageReference newContact() {
            PageReference newContact = new PageReference('/apex/CreateNewContact?id=' +unresolvedEmailId);
            newContact.getParameters().put('id',unresolvedEmailId);       
            newContact.setRedirect(true);
            return newContact;
        }    
    public PageReference saveContact() {
       String unRID = ApexPages.currentPage().getParameters().get('id');
    List<UnresolvedEmail__c> newContEmailAdd = [Select Id, Name,From__c,Assigned_to__c,owner.name FROM UnresolvedEmail__c   where  Id = :unRID ];
      if (newContEmailAdd[0].From__c == user.Email) {
         contact.Email = newContEmailAdd[0].Assigned_To__c;
      }      
     else if(newContEmailAdd[0].From__c != user.Email){      
      contact.Email=newContEmailAdd[0].from__c;
      }       
      insert contact; // inserts the new record into the database
 PageReference newPage = new PageReference('/'+contact.id); return newPage; }

Custom object VisualForce page:

<apex:page controller="UnresolvedEmailsController" >
<apex:form >
  <apex:pageBlock title="Unresolved Emails" mode="edit">
 <apex:pageBlockTable value="{!unresolvedEmails}" var="Emails" >
                 <apex:column >
                        <apex:facet name="header">Subject</apex:facet>
                        <apex:outputlink value="/{!Emails.id}">
                        <apex:outputField value="{!Emails.Name}"/>
                        </apex:outputlink>
                </apex:column>
                <apex:column >
                        <apex:facet name="header">From</apex:facet>
                        <apex:outputField value="{!Emails.From__c}"/>
                </apex:column>
                <apex:column >
                        <apex:facet name="header">Assigned To</apex:facet>
                        <apex:outputField value="{!Emails.Assigned_To__c}"/>
                </apex:column>
                <apex:column >
                        <apex:facet name="header">Owner</apex:facet>
                        <apex:outputField value="{!Emails.owner.name}"/>
                </apex:column>
                 <apex:column >
                        <apex:commandButton value="New Contact" action="{!newContact}" reRender="hiddenBlock">
                            <apex:param name="unresolvedEmailId"
                            value="{!Emails.id}"
                            assignTo="{!unresolvedEmailId}"/>
                        </apex:commandButton>
                        <apex:pageBlock id="hiddenBlock" rendered="false"></apex:pageBlock>               
                  </apex:column>
               </apex:pageBlockTable>
     </apex:pageBlock>
</apex:form>
</apex:page>

Create contact Visualforce page:

<apex:page controller="UnresolvedEmailsController">
  <apex:sectionHeader title="Visualforce Example" subtitle="Create a Contact"/>
   <apex:form >
    <apex:pageMessages /> <!-- this is where the error messages will appear -->
    <apex:pageBlock title="Contact Info">
       <apex:pageBlockButtons >
        <apex:commandButton action="{!saveContact}" value="Save"/>
      </apex:pageBlockButtons>
      <apex:pageBlockSection showHeader="false" columns="2">
        <apex:inputField value="{!contact.firstName}" />
        <apex:inputField value="{!contact.lastName}" />
        <apex:inputField value="{!contact.email}" />
      </apex:pageBlockSection>      
    </apex:pageBlock>
  </apex:form>
</apex:page> 

 How do i make the Contact email value visible when i click on 'Create Contact' button(which is on my Custom object Visualforce page)?

 

TheIntegratorTheIntegrator

rather than on save function, try assigning contact.Email in the constructor.