You need to sign in to do that
Don't have an account?
Chris Ronnie
Getting the Agent Image and the Agent Name for Live Agent
So I have build a custom chat page that gets the agents photo. When I say built.... I mean borrowed from here https://systemdebug.wordpress.com/2015/05/17/live-agent-rest-api-connectapi/
What I want to do now is also get the agents name.
The current Apex Class is
How do I extend this to also get the agents name. When I then have it how do I use it in my Visualforce page?
What I want to do now is also get the agents name.
The current Apex Class is
public without sharing class Chatwindowcontroller { @RemoteAction public static String getPhoto(String userId) { ConnectApi.Photo p = ConnectApi.ChatterUsers.getPhoto(Network.getNetworkId(), userId); return p.smallPhotoUrl; } }
How do I extend this to also get the agents name. When I then have it how do I use it in my Visualforce page?
All Answers
Can you use this
{userDetail.Name}
??
Or if you require other value as well, then you can use something like below.
Error: Compile Error: Variable does not exist: userId at line 6 column 104
it doesnt like this line
ConnectApi.UserDetail userDetail = ConnectApi.ChatterUsers.getUser(Network.getNetworkId(), userId);
Sorry for being a pain :(
The userId to be used here is same as you are using for this method :
public static String getPhoto(String userId)
Just to know the background, what is the userId? is it the logged in user?
return UserInfo.getFirstName() ;
return UserInfo.getLastName() ;
I then need a way to use this data in a Visual Force page.
It's pretty straightforward then. No need for any thing to be done in controller.
Just use the below tag in your VF page. Refer below link to get more details
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_variables_global_user.htm
I should have mentioned this too, this is for Live Agent, so the customisation is running from a public site. It is being triggered from a website. I think I need to allow the sites public profile read access to the user object.
Then you will have to use the below code.
Where userId is the Id of the Livechat Agent, the same value that you are passing in tht getPhoto method. Try the above and let me know if it helped. If not please share both your page and controller here, so that I can have a look as to how and what agent Id you are setting.
Error: Compile Error: Variable does not exist: AgentId at line 6 column 13
I tried changing this to this This is my VF page
Also, I can see on line 14
details[key] is already having the agent details.
Using JS you can the name and set it to the html component
Something like,
details[key].Name and assign that value to the html component
I still like the idea of using the controller. I have made the changes in my sandbox and it all looks great. Of course the issue is now I need to move it to production and my test coverage is only 33%
My test class looks like this
The error I get for line 8 is
As I can see you are hardcoding Id's which is not allowed, as these Id's may not be present on production, resulting in test class failure during deployment.
replace with relevant values between <>
you can refer few articles as in below
https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
To help the community grow, do mark the answers with likes or best answer, so as to help anyone face similar issue in future.
Seems the latest bit of code has introduced a permissions issue.
I have checked the permissions for the visualforce page and the apex class and they both have the full force.com user permissions.
My Class now looks like this
I have updated my visualforce page to have this:
How do I just get the results of getUserStuff to display has plain html here
Were you able to solve the above issue. Displaying Live agent name on the custom chat page? Please post the code if you were successfull.
When I tried the above code selected as the Answer, the agentId is getting null.
I have added ChatWindowController code in apex class section i am getting this error
"Error: Compile Error: Method was removed after version 34.0: getPhoto at line 6 column 54". This getPhoto method removed.