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
Richard L JonesRichard L Jones 

OnClick Javascript/VF/SF1 woes

Hi all,

I've got a custom button which uses onclick javascript to update the Stage of my opportunity object, so users can push the opportunities through the first few stages of the sales process. The javascript I cobbled together to do this is;
 
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
var opp=new sforce.SObject("Opportunity");
var newRecords = [];
opp.id="{!Opportunity.Id}";
opp.StageName = 'Gate 1 - Pursuing';
newRecords.push(opp);
var result = sforce.connection.update(newRecords);
window.location.reload();

This particular JS is on the first button, moving it from Prospecting to Pursuing, and they all seem to work fine. Now, I know that Salesforce1 won't use OnClick Javascript because Salesforce basically like messing with me ;) 

However, I've attempted to move it into a VF page and create a global action, which sure enough creates a button on my SF1 action bar, but it's really clunky because all it does is open up an extra page with a button on it. Plus it doesn't work, so looks both awful and is pointless :p I'll put the code for it at the bottom, just in case anyone wants a laugh. 

Soooooo, is there any way to recreate the nice experience of just having a custom button on my opportunity object which just pushes the stage forward without needing to open up random pages or anything like that? 

thanks in advance
Richard 
 
<apex:page >
<apex:form >
 <script src="/soap/ajax/13.0/connection.js"></script >
    <script>
sforce.connection.sessionId = "{!$Api.Session_ID}";
function execute()
{
    var opp=new sforce.SObject("Opportunity");
    var newRecords = [];
    opp.StageName = 'Gate 1 - Pursuing';
    newRecords.push(opp);
    var result = sforce.connection.update(newRecords);
    window.location.reload();
    } 
    }
}
</script>
<input type="button" value="Next Stage" onclick="execute();"/>
</apex:form>
</apex:page>