I currently have a custom button which has the following javascript :
{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}
var ref = "{!Proposal__Proposal__c.Id}";
var result = sforce.apex.execute("GenerateQuotePdfCont","saveQuotePdf",{parentId:"{!Proposal__Proposal__c.Id}"});
window.open('/apex/GenerateQuotePdfPage?scontrolCaching=1&id='+ref+'&scontrolCaching=1');
However, I would like to move this logic into a hyperLink function and then use it in a formula field like this :
IF (NOT ISBLANK(Configuration_Saved_Date__c) && Proposal__ReadyToGenerate__c && Grand_total_exclusive__c > 0, HYPERLINK("{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}
var ref = "{!Proposal__Proposal__c.Id}";
var result = sforce.apex.execute("GenerateQuotePdfCont","saveQuotePdf",{parentId:"{!Proposal__Proposal__c.Id}"});
window.open('/apex/GenerateQuotePdfPage?scontrolCaching=1&id='+ref+'&scontrolCaching=1');","_self"), NULL)
Is this something that is possible? Currently, the formula does not compile
Best Answer
Nope, it isn't possible to have Javascript or Apex in a formula field.
When you create a formula field, the formula itself is stored in the database (as opposed to storing the result of the formula when it's evaluated). Every time you query a formula field, that formula is evaluated by the database, and the result made available to you.
This behavior is briefly explained in An Introduction to Formulas in the Formula Limits section
SQL can't execute or evaluate Javascript (there would be a ton of chaos if that were possible.) At best, your Javascript would be treated as plain text. At worst, your formula field won't compile.