Skip to main content

A Visualforce Page Excatly Same as Contact Edit Page

Hi 
This is a very simple post. I had seen that question  developerforce.com . That's why I thought I will share in my blog. The question was there will be a link called "Copy Mailing Address to Other Address" when clicked that link all Mailing address will be copied to other address same as standard edit page of contact.
This can be done two ways. 
  • By using java script
  • By using Controller extension
In the command link we have to call java script method there we will get all the field value of mailing addresss using documnet.getElementByid() method in javascript and will assign to the other address field. 

Second approach is we will call extension method where will assign all the mailing address field to other address field and will reRender (refresh) the block. It will behave exactly like as standard edit page layout of Contact functionality.
Now the challenge is how will we display that command link inside that pagablock section header.

This is the page and controller 


<apex:page standardController="Contact" extensions="contactEditPageExtension">
    <apex:sectionHeader title="Contact Edit" subtitle="New Contact"/>
    <apex:outputText value="Contacts not associated with accounts are private and cannot be viewed by other users or included in reports."> 
    </apex:outputText><br/><br/>
    <apex:form >
        <apex:pageBlock title="Contact Edit" id="test">
            <apex:pageBlockButtons location="both">
                <apex:commandButton value="Save" action="{!Save}"/>
                <apex:commandButton value="Save & New" />
                <apex:commandButton value="Cancel" action="{!Cancel}"/>
                
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Contact Information">
                <apex:inputField value="{!contact.FirstName}"/> 
                <apex:inputField value="{!contact.LastName}"/>       
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Test">
                   <apex:facet name="header">
                        <apex:pageBlockSectionItem >
                        <apex:outputText value="Address Information" style="float:left;"></apex:outputText>
                        <apex:commandLink value="Copy Malling Address to Other Address" style="float:right;" action="{!test}" reRender="test"/>
                        </apex:pageBlockSectionItem>
                    </apex:facet>
             
                    <apex:inputField value="{!contact.MailingCountry}"/> 
                    <apex:inputField value="{!contact.otherCountry}"/>  
                    <apex:inputField value="{!contact.MailingStreet}"/> 
                    <apex:inputField value="{!contact.otherStreet}"/>   
                    <apex:inputField value="{!contact.MailingState}"/> 
                    <apex:inputField value="{!contact.otherState}"/>    
                  
            </apex:pageBlockSection>
             
        </apex:pageBlock>
    </apex:form>
  </apex:page>


My controller 


public with sharing class contactEditPageExtension {
    public Contact contact{get;set;}
    public contactEditPageExtension(ApexPages.StandardController controller) {
        //this.contact = (Contact )controller.getRecord();
        contact = new Contact();
    }
    
    public void test(){
         contact.otherCountry  =  contact.MailingCountry;
        contact.otherState  =   contact.MailingState;
        contact.otherStreet  =   contact.MailingStreet;
        //return null;
    }


}

Comments

Unknown said…
Thanku bya,it is very useful to us

Popular posts from this blog

How to Create a Tooltip in Lightning Datatable ?

Imagine you have a datatable displaying a list of Contact records , and one of the columns shows the Account Name . The Account Name is a hyperlink that allows users to navigate to the Account record page. But what if users want to take a quick glance at some key Account fields —like Phone or Address—without navigating to the Account record? In Salesforce Classic, this was achieved using the Mini Page Layout feature from standard page. However, in Lightning Experience, we can implement a similar feature by adding a tooltip to the data table. Solution Overview: We’ll create a Lightning Web Component (LWC) that: Displays a data table with a clickable Account Name . Provides a tooltip that shows the Account's Phone and Address fields when users hover over the Account Name. Implementation Steps: 1. Data Preparation We need to retrieve the following fields for each Contact and its associated Account: Contact Fields : Name, Phone, Email Account Fields : Name, Phone, Billing Addre...

Lifecycle hooks in LWC

There are 3 phase of LWC component  1. Mounting  A. constructor, B. connnectedCallback C. render D. renderedCallback 2. UnMounting  A. disconnectedcallback 3. Error  A.errorcallback Note - render is not lifecycle hook, it is protected method of Lightning element class. Mounting Phase LWC Creation and Render Life cycle Constructor Method ·        This method called when component is instantiated and It flows from parent to child component. ·        Need to call Super() inside constructor method ·        Can’t access any component properties or child component because it’s not ready yet. ·        Host element can be accessed through “this. template” inside constructor method. ·        Don’t add any attributes to host inside constructor C   constructor (){          super (); //...

How to Create/Delete file attachments(Content Document) through Apex ?

 There are 3 standard salesforce objects to store file attachments. Content Document, ContentDocumentVersion, ContentDocumentLink.  Here is the article to talk about these objects and relationship.  https://www.forcetalks.com/blog/contentdocument-and-contentversion-in-salesforce-an-overview/ ContentDocumentVersion ContentDocumentLink This post is all about how to create/delete content document though Apex. Here is code snippet // Insert Content Version record ContentVersion contentVersionRec = new ContentVersion(Title='filename',PathOnClient ='FileName.pdf',VersionData = bodyBlob,origin = 'H'); INSERT contentVersionRec; // this will insert one record in ContentDocument and ContentVersion , ContentDocument  is parent and  ContentVersion is child record // get contentdocument id contentVersionRec = [SELECT Id, Title, ContentDocumentId FROM ContentVersion WHERE Id = :contentVersionRec .Id LIMIT 1]; // Create Content Document Link record- This will attach ...