function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Stavros McGillicuddyStavros McGillicuddy 

Invalid or Unexpected Token error running query

This "should" work by placing everything into one field (Sample_Product_Name_1). but it throws an "Invalid or Unexpected token" error
 
{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")}

var record = new sforce.SObject("Opportunity");
record.oli ='{Select Amount,CloseDate,Name, 
     (Select PricebookEntry.Product2Id, 
             TotalPrice, 
             UnitPrice, 
             ListPrice 
      From OpportunityLineItems) 
   From Opportunity};

record.Id = '{!Opportunity.Id}';
record.Sample_Product_Name_1__c= record.oli;
sforce.connection.update([record]); window.location.reload();

 
Ashish GargAshish Garg
Hi,

Try using sforce connnection query.
var ReferraAccepted = sforce.connection.query(


{!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/32.0/apex.js")}

var record = new sforce.SObject("Opportunity");
record.oli =sforce.connection.query("Select Amount,CloseDate,Name, (Select PricebookEntry.Product2Id, TotalPrice, UnitPrice, ListPrice From OpportunityLineItems") From Opportunity};

record.Id = '{!Opportunity.Id}';
record.Sample_Product_Name_1__c= record.oli;
sforce.connection.update([record]); window.location.reload();