I have a business requirement where a new Quote record cannot be generated for a couple different Opportunity types. If the user tries, they get an alert. I've overridden the standard New Quote button with a javascript button. But a new requirement came in yesterday saying that one profile can generate contracts regardless of Opportunity Type. When I added this second condition to the if statement with an && logical, it seems to abort after the if and not proceed onto the other conditionals. A slightly modified version of the code is below.

var cQuote = new sforce.SObject("Quote");
var QuoteRecord = sforce.connection.query("Select OpportunityId, Id From Quote where OpportunityId='{!Opportunity.Id}' "); 
var records = QuoteRecord.getArray("records");
if('{!Opportunity.Type}'=='Example Type' && '{!User.Profile}' != 'Example Profile Type') {
    alert("A quote record cannot be created for this Opportunity Type.");
else if(records[0] != null) { 
    alert('A Quote Entry already exists.'); 
else {
    cQuote.Name="Do Not Edit";
    var result=sforce.connection.create([cQuote]);
    if (result[0].getBoolean("success")) {

I checked the javascript console - the only difference between the old button without the !User.Profile condition and the new button with it is that the new button returns two error messages that say "Refused to set unsafe header "User-Agent". See below image for more detail. I would really appreciate some insight on this. Here's the console error

  • Since User is a global visualforce variable, it needs a dollar-sign, e.g. $User.Profile.
    – Phil Rymek
    Feb 26, 2014 at 16:36
  • @phil Rymek Tried it like this: if('{$User.Profile}'!='System Administrator') { alert("A Q/C record cannot be created for this Opportunity Type."); I'm getting the error message even though my profile is System Administrator.
    – Matt Santy
    Feb 26, 2014 at 16:42
  • All merge fields require the exclamation, and the global user variable requires the dollar sign. {!$User.Profile}
    – Phil Rymek
    Feb 26, 2014 at 16:46
  • Now I get: Error: Field Profile does not exist. Check spelling.
    – Matt Santy
    Feb 26, 2014 at 16:47
  • 2
    I feel like a goon this has gone back and forth so much, but this page suggests its {!$Profile.Name}
    – Phil Rymek
    Feb 26, 2014 at 16:55

2 Answers 2


This example worked for me:


if('{!Opportunity.Type}' == 'New Customer' && '{!$Profile.Name}' != 'System Administrator') {
    alert("A quote record cannot be created for this Opportunity Type.");
else {
alert('Your Sys Admin');

If I change the Profile check to be something else, like "System Admin1", then the IF fails, and the redirect fires.


The reason this is happening is because Profile is not a valid field. Please use the following:


You can test this by creating a button which executes javascript and paste this in the behavior


If you wish to go by profile name you'll have to do something like this via javascript:


var queryResult = sforce.connection.query("SELECT Id, Name FROM Profile WHERE Id = '{!$User.ProfileId}'"); 
var profileRecord = queryResult.getArray('records')[0];


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .