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
StefanStefan 

Button to update opportunity stage

I am trying to use a button to update opportunity stage to Finance Approved. What is wrong with the below code which gives me an error message: Invalid Field: No such column 'Stage' on entity 'opportunity'

<html>
<head>
<script src="/soap/ajax/9.0/connection.js"></script>
<script language="JavaScript">
var temp= new sforce.SObject("Opportunity");
temp["Id"]="{!Opportunity.Id}";
temp["Stage"]="Finance Approved";
try
{ sforce.connection.update([temp]);
} catch(e)
{ alert(e)
}
window.top.location.href = "/{!Opportunity.Id}";
</script>
</head>
</html>

jpizzalajpizzala
The API field name for the "Stage" field is "StageName". Hopefully that will do the trick :)
StefanStefan
Thanks, that worked perfectly. But how can I tell which names to use for other fields?
jpizzalajpizzala
You have a couple options here (probably more). You could go to Setup -> [App Setup] Customize -> ObjectName -> Fields then click on the desired field to get access to the Field Name (and to set security, accessibility, validation rules, etc.).

Or, you could use the SForce Explorer (a.k.a. Apex Explorer) found at the link below. Another great thing about using the Explorer is that you can develop and debug your SOQL queries with it before implementing in your code.

SForce Explorer 8.0 : http://wiki.apexdevnet.com/index.php/Apex_Explorer

StefanStefan
Many thanks.