0

I have a Apex class:

public class myController {
    public string url{
        get {
            if (this.url == null)
                this.url = System.URL.getSalesforceBaseUrl().toExternalForm();
            return this.url; }
        set;
        }

}

Visual Force Component:

<apex:component controller="myController" access="global">
  <p />
   <apex:outputLink id="urlString" value="{!url}/{!$User.Id}?noredirect=1&isUserEntityOverride=1" >{!url}/{!$User.Id}?isUserEntityOverride=1&amp;noredirect=1</apex:outputLink>
</apex:component>

Visual Force Template in Workflow Rule:

<messaging:emailTemplate  recipientType="user"  relatedToType="order">
<messaging:htmlEmailBody >
   <html>
      <body>
         <center>
            <p>
               <c:URL/> -`/ Here the username will display/`
               <br>
               Click on below link to go to this user setup:
               <c:URL/>/{!$User.Id}"`/ Here the Link will display/`
               </br>
            </p>
         </center>
      </body>
   </html>
</messaging:htmlEmailBody>

{!user.name} is not working in the Visual Force Template,so i want to query the current username using the Apex class and then accessed using Visual force Component and command is used in Visual force template

I Have tried {!$user.username} and {!$user.name} both are not working anyone Guide me for the answer i want the combination of both firstname and Lastname,so i need to query through the apexclass guide me for the answer

But Now two Requirements <c:URL/> is used to display the link in one Place and <c:URL/> is used to display the username in another place How? Is it possible in same Component? Please Anyone Guide me for the updated Answer for my Requirement

2
  • I Have tried {!$user.username} and {!$user.name} both are not working anyone Guide me for the answer i want the combination of both firstname and Lastname
    – SFDC
    Nov 14 '16 at 9:07
  • If we querying through apex class means if we want we can query phone also,My thought is possible ah?
    – SFDC
    Nov 14 '16 at 9:10
0

You can get the username, FirstName and LastName, using the below format

<apex:outputLink value="{!$Label.URL}/{! $User.Id}" >{!$Label.URL}/{! $User.FirstName}{! $User.LastName}</apex:outputLink> 

So, your URL will still redirect the end-users to the correct uri, while for display it would have LastName and FirstName.

Your output should look something like the one below, in which you see that the link label is domain/username while the link address is still valid as it is domain/userid.

enter image description here

Define two properties in your controller, namely, usrName and usrPhone.

Public String usrName {get;set;} 
Public String usrPhone {get;set;}

user usr = [select name,phone from user where id =:userinfo.getuserid() LIMIT 1];

usrName = usr.Name;
usrPhone = usr.Phone;

In your VF component

<apex:component controller="myController" access="global"> 
  <p /> 
  <apex:outputLink id="urlString" value="{!url}/{!$User.Id}?noredirect=1&isUserEntityOverride=1" >{!url}/{!$User.Id}?isUserEntityOverride=1&amp;noredirect=1</apex:outputLink> <br />

  <apex:outputLabel value="{!usrName}" id="someId" />
  <apex:outputLabel value="{!usrPhone}" id="someId2" />

</apex:component>

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.