You need to sign in to do that
Don't have an account?
Dave Berenato
Use UserID to get UserName
I'm currently using an Apex Class to generate a list of records owned by a specific User.
I build a Visualforce page for Managers to basically click in to the list of any User using the Visualforce page URL of that individual LeadGenerator's page.
Something like:
public TelemarketerDialing(){ if(ApexPages.currentpage().getParameters().get('leadgenerator') == null) {myParam = UserInfo.getUserId();} else{myParam = ApexPages.currentpage().getParameters().get('leadgenerator');} } public String myParam { get; set; }
I build a Visualforce page for Managers to basically click in to the list of any User using the Visualforce page URL of that individual LeadGenerator's page.
<td><a href="https://corere--c.na50.visual.force.com/apex/DoorKnockerPortal?leadgenerator=0056A000000f0af">Angel</a></td> <td><a href="https://corere--c.na50.visual.force.com/apex/TelemarketerPortal?leadgenerator=0056A000000e779">Antonio</a></td> <td><a href="https://corere--c.na50.visual.force.com/apex/TelemarketerPortal?leadgenerator=0056A000001IVgU">Ary</a></td>I'm wondering if there's a way to user the UserID to display the name of the User you are viewing on the page.
Something like:
public String LeadGeneratorName = getUserInfo(myParam).UserName;Is this possible?
Modify your code like below:
Change "String userName= usr.Name;" to "userName = usr.Name;"
Let me know if this helps.
Thanks,
Manish
All Answers
You can use SOQL to retrieve the user name if you have userId. SOQL that needs to be used:
Let me know if this helps.
Thanks,
Manish
Try the following to generate your page with the links by name. I used Profile to determine who to display and what portal to link to, but you can change that to meet your requirements. Disclaimer: This is completely untested. Don't be surprised if it doesn't compile the first time, but hopefully it conveys the idea.
<pre>
// Controller:
private Map<String,String> pageByProfile = new Map<String,String>
{ 'Door Knocker' => 'DoorKnockerPortal'
, 'Telemarketer' => 'TelemarketerPortal'
}
public class LeadGenerator
{
public Id userId;
public String name;
public String portal;
public LeadGenerator( Id userId, String name, String portal )
{
this.userId = userId;
this.name = name;
this.portal = portal;
}
}
public List<LeadGenerator> leadGenerators
{
get
{
if ( leadGenerators == null )
{
leadGenerators = new List<LeadGenerator>();
for ( User user :
[ SELECT Id, Name, Profile.Name
FROM User
WHERE Profile.Name IN :pageByProfile.keySet()
]
(
{
leadGenerators.add
( new LeadGenerator
( user.Id
, user.Name
, pageByProfile.get( user.Profile.Name )
)
);
}
}
return leadGenerators;
}
private set;
}
// Visualforce Page:
<apex:repeat value="{!leadGenerators}" var="leadGenerator">
<apex:outputLink value="{!'/apex/' + leadGenerator.portal + '?leadgenerator=' + leadGenerator.userId}">
{!leadGenerator.name}
</apex:outputLink>
</apex:repeat>
</pre>
Were you thinking something like this?
For some reason I'm able to display {!myParam} in the visualforce page but {!userName} returns nothing. Any suggestions?
Modify your code like below:
Change "String userName= usr.Name;" to "userName = usr.Name;"
Let me know if this helps.
Thanks,
Manish