1

Apex class controller:

public class myController1 {

    public String usrPhone { get; set; }

    public String usrName { get; set; }
Public String userName {get;set;} 
Public String userPhone {get;set;}

    public string url{
        get {

            if (this.url == null)
                this.url = System.URL.getSalesforceBaseUrl().toExternalForm();
                user usr = [select id,name,phone from user where id =:userinfo.getuserid() limit 1];
    userName = usr.name;
   userPhone = usr.phone;
            return this.url;
              }
        set;
        }


 }

Visual Force Component:

<apex:component controller="myController1" access="global"> 
  <p /> 
  <apex:outputLink id="urlString" value="{!url}/{!$User.Id} >{!url}/{!$User.Id}</apex:outputLink> <br />
  <apex:outputLabel value="{!usrName}" id="someId" />
  <apex:outputLabel value="{!usrPhone}" id="someId2" />
</apex:component>

only url is passing from apex class to visual force component and how the username and phone should send to the Visual force component,Can anayone alternate the code of Controller class

1

Consider using a constructor for this case.

public class myController1 {
    public myController1() {
        User thisUser = [select name, phone from user where id = :userinfo.getuserid()];
        userName = thisUser.Phone;
        userPhone = thisUser.Name;
        url = System.URL.getSalesforceBaseUrl().toExternalForm();
    }
    Public String userName {get;set;} 
    Public String userPhone {get;set;}
    public String url { get; set; }
}
| improve this answer | |
  • @user36188 You're using both usrName and userName. You should probably stick to just one or the other. – sfdcfox Nov 16 '16 at 7:15
  • @user36188 I'm not exactly sure what you're trying to ask, but I'd suggest asking a new question with additional details for more details. – sfdcfox Nov 16 '16 at 7:22
  • salesforce.stackexchange.com/questions/148892/… @sfdcfox – SFDC Nov 16 '16 at 7:42
  • It is possible or Not @sfdcfox ,or i have to create another vf component to seperate the username in vf template – SFDC Nov 16 '16 at 8:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.