var quoteId = '{!Quote.Id}';


var oppId = '{!Opportunity.Id}';


The variable oppid displays blank...

2 Answers 2


If you want to get the opportunity id of the quote, you need to look at the quote fields instead:


  • Create a formula field as Text for Opportunity Id, OpportunityId__c
  • Create custom button using the formula field instead :

var oppId = '{!Quote.OpportunityId__c}';

  • Error: Field Quote.OpportunityId does not exist. Check spelling
    – Tim Kolb
    Commented Dec 19, 2016 at 21:59
  • Interesting that OpportunityId wouldn't be available. Sorry about that. You could definitely try with ajax toolkit.
    – brovasi
    Commented Dec 19, 2016 at 22:15
  • Getting error "No such column 'OpportunityID' on entity 'Quote"
    – Tim Kolb
    Commented Dec 19, 2016 at 22:29
  • I am using Execute JavaScript on a custom button on for quotes. Also using you exact sample.
    – Tim Kolb
    Commented Dec 19, 2016 at 22:32
  • @TimKolb - sometimes (org-dependent), after one enables Quotes or Orders, some of the fields are not visible to even the System Administrator as running user. Check FLS on the Quote.OpportunityId standard object field
    – cropredy
    Commented Dec 19, 2016 at 23:05

To retrieve the OpportunityId behind the custom button, you need to execute the query explicitly as follows:


var quoteRec = sforce.connection.query("select Opportunity.Id from Quote where Id='" + '{!Quote.Id}' + "'"); 
var records1 = quoteRec.getArray('records'); 

if(records1 !=null) 

You must log in to answer this question.

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