I have a Javascript button that creates an Opportunity from a Case. One of the fields in the new Opportunity is a Contact lookup field that needs to be pre-populated with the Contact field on the Case. All works fine unless the Contact name contains an apostrophe, then the Javascript throws an error that I'm missing a ). Does anyone know how to get the text of the Contact field from the Case? I tried using JSENCODE, but that end us returning the Contact ID.
{!REQUIRESCRIPT("/soap/ajax/36.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/36.0/apex.js")}
var query = "SELECT FirstName,LastName FROM Contact WHERE Id = '{!Case.ContactId}' limit 1";
var CName = sforce.connection.query(query);
ConName = CName.getArray("ConName");
console.log('###'+ConName);
var myCon1 = ConName[0].FirstName;
window.open('/006/e?retURL={!Case.Id}&accid={!Account.Id}&RecordType=012a0000001Fsxa&opp11=Quote&00Na000000BODU0=Small Quote&opp3={!Case.Account} - Quote&opp9={!TODAY()+30}&CF00Na000000BAz6W='+myCon1+' '+myCon.LastName+'&ent=Opportunity');