Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- Change Record Type with JavaScript Button: Error
turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
0
Change Record Type with JavaScript Button: Error
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-14-2012 08:19 AM
I am trying to create a button that changes a record type from "For Sale" to "Off Market" on a custom object, but I am receiving an error that the result is not defined. Please advise.
{! REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
var recordtype= sforce.connection.query("select name, id from recordtype where name='For Sale'");
var records = recordtype.getArray("records");
try
{
if('{Listing__c.RecordType}' == 'Off Market')
{
sforce.connection.sessionid = '{!GETSESSIONID()}';
var account = new sforce.SObject("Listing");
Listing__c.id='{!Listing__c.Id}';
Listing__c.RecordTypeId =records[0].Id;
var result = sforce.connection.update([Listing__c]);
}
}
catch (ex)
{
alert(ex);
}
if (result[0].success=='false') {
alert(result[0].errors.message);
} else {
location.reload(true);
}
0
Re: Change Record Type with JavaScript Button: Error
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-17-2012 01:47 AM
you have declare result in curly braces section. Please declare it out. like
{! REQUIRESCRIPT("/soap/ajax/24.0/connection.js")}
var recordtype= sforce.connection.query("select name, id from recordtype where name='For Sale'");
var records = recordtype.getArray("records");
var result
try { if('{Listing__c.RecordType}' == 'Off Market') { sforce.connection.sessionid = '{!GETSESSIONID()}'; var account = new sforce.SObject("Listing"); Listing__c.id='{!Listing__c.Id}'; Listing__c.RecordTypeId =records[0].Id; result = sforce.connection.update([Listing__c]); } } catch (ex) { alert(ex); } if (result[0].success=='false') { alert(result[0].errors.message); } else { location.reload(true); }

