You need to sign in to do that
Don't have an account?

Create a visualforce page with a custom button which updates field for a custom object
Hi everyone,
I had created a detailed page button that executes Java Scprit and now I am trying to create exactly the same button, but on a Visualforce page that I will make available for Salesforce1.
Can someone help me write the code for the Visualforce page?
Detailed Page/JavaScript/ Custom Object - "Travel Request"
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}
var tr = new sforce.SObject("Travel_Request__c");
tr.id = '{!Travel_Request__c.Id}';
tr.Approval_Status__c ='Recalled/Cancelled';
var result = sforce.connection.update([tr]);
if (result[0].success == 'false') {
alert(result[0].errors.message);
}
else {
location.reload(true);
}
I had created a detailed page button that executes Java Scprit and now I am trying to create exactly the same button, but on a Visualforce page that I will make available for Salesforce1.
Can someone help me write the code for the Visualforce page?
Detailed Page/JavaScript/ Custom Object - "Travel Request"
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}
var tr = new sforce.SObject("Travel_Request__c");
tr.id = '{!Travel_Request__c.Id}';
tr.Approval_Status__c ='Recalled/Cancelled';
var result = sforce.connection.update([tr]);
if (result[0].success == 'false') {
alert(result[0].errors.message);
}
else {
location.reload(true);
}
You can use following code to create your vf page.
Please don't forget to click Available for Mobile App checkbox as shown in below screenshot.
Thanks,
Himanshu
You can use following code
Apex Class:
VF Page:
Thanks,
Himanshu
Error: Compile Error: Option already set: PublicIdentifier at line 6 column 12
remove one public from line 6
public Travel_Request__c TR;
Status is a picklist if this makes a difference
Makes sense ?
Use below code, its for account change field and object name according to your object
Go to the link to learn more
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_std_actions.htm
To use the same in functionality on mobile you need to create Action, one suggestion start Learnig Salesforce on trailhead
Here is the link for mobile action module on trailhead https://developer.salesforce.com/trailhead/visualforce_mobile_salesforce1/visualforce_mobile_salesforce1_actions_global
I tried wsithing Approval Status with other fields from the object and I am getting the same error.
I have created a new Record Type called "Open". Can you please tell me the code for a VF to change the record type by clicking on the button?
You need to get the Recordtypeid first with following query
so your apex class will be
Thanks,
Himanshu