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
Charline MitchenerCharline Mitchener 

Custom Controller & VF Page to lookup linked Account to User/Contact

I have created a VF page where I want the user logged into the community to be able to update certain fields under their contact as well as the account they are linked to. To clarify, we have Authorised Rep's that will all have access to our community, each rep (contact) is also linked to an account (their name of the company), and I need them to be able to update their details for both sections.

I have worked out how to lookup details from the Contact, but my knowledge with APEX is limited, and I have no idea how to extend this to lookup the associated Account. So far I have the Custom Controller as:

public class MyContactController {

    public String account { get; set; }
    public Contact contact {get; private set;}

    public MyContactController() {
        User user = [select ContactId from User where id = :UserInfo.getUserId()];
        Id id = user.ContactId;
        contact = (id == null) ? new Contact() :
        [SELECT id,email,title,firstname,lastname,mobilephone,Publish_Mobile_No_on_Website__c,Website_Bio__c,Specialty__c,Qualifications__c,photo__c FROM contact WHERE id = :id];
    }
}


And my VF page as - 

<apex:page Controller="MyContactController">
    <apex:form >
        <apex:pageBlock title="Update Company Details for {!$User.CommunityNickname}">
            <apex:pageMessages />
            <apex:pageBlockSection >
                <apex:inputField id="title" value="{!contact.title}" />
                <apex:inputField id="firstname" value="{!contact.firstname}" />
                <apex:inputField id="lastname" value="{!contact.lastname}" />
                <apex:inputField id="email" value="{!contact.email}" />             
                <apex:inputField id="mobilephone" value="{!contact.mobilephone}" />
                <apex:inputField id="Publish_Mobile_No_on_Website__c" value="{!contact.Publish_Mobile_No_on_Website__c}" />
                <apex:inputField id="Website_Bio__c" value="{!contact.Website_Bio__c}" />
                <apex:inputField id="Specialty__c" value="{!contact.Specialty__c}" />
                <apex:inputField id="Qualifications__c" value="{!contact.Qualifications__c}" />
                <apex:inputField id="photo__c" value="{!contact.Photo__c}" />
                 <br><br></br></br>
            </apex:pageBlockSection>
            <apex:pageBlockSection >
            <em>
            </em>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>



Really appreciate any help I can get! An example of the fields I need to link to from accounts is, 

                <apex:inputField id="phone" value="{!account.phone}" />
                <apex:inputField id="fax" value="{!account.fax}" />
                <apex:inputField id="Company_Logo__c" value="{!account.Company_Logo__c}" />