+ Start a Discussion
Atul GuptaAtul Gupta 

Pass Profile Name to String

Hi Guys,


I'm trying to get the !$Profile.Name in a var in an onclick javascript.


I need to some substring and indexOf operations on the profile name.


But every time I get an error that "Object Profile Name has no method subString".....


Please help me out here guys.

Best Answer chosen by Admin (Salesforce Developers) 



If my post helps you and it is your solution then please mark it as a solution.




All Answers

Marty C.Marty C.

Hello, Atul,


Are you trying to manipulate the Profile Name in JavaScript or in Visualforce? If you're trying to do it in JavaScript, the following example shows how you can pass the Profile Name to a JavaScript function as a string parameter.


<span onclick="alert('{!$Profile.Name}')">CommunityHome</span>

Atul GuptaAtul Gupta
Yes marty,

I'm retrieving the profile in an on click javascript button like this.

var profileName = '{!$Profile.Name}';

no I want to manipulate with the string of the profile name, something like

var stringProfile = profileName.subString(0,2);

but I don't get any value in stringProfile as it doesn't allow any kind of operation on profileName,. I'm getting profile name as an object and not as a String.

Please help.

This message is for the designated recipient only and may contain privileged, proprietary, or otherwise confidential information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the e-mail by you is prohibited.

Where allowed by local law, electronic communications with Accenture and its affiliates, including e-mail and instant messaging (including content), may be scanned by our systems for the purposes of information security and assessment of internal compliance with Accenture policy.






You are using subString(0,2) in js. Try this substring(0,2) because java script is case sensetive script. substring is correct name of method. and subString is working in java and in apex language.


Write syntax is string.substring(from, to);



If this post help you then mark it as a soloution and don't forget to give me kudo''s




Atul GuptaAtul Gupta

Hey D-Horse,


now I'm using some other approach to this issue.


but yes, I completely forgot that javascript is case sensitive :P


Thanks for solution :)




If my post helps you and it is your solution then please mark it as a solution.




This was selected as the best answer