You need to sign in to do that
Don't have an account?
kelly.lu1.3940702104676975E12
use Javascript and the Salesforce API behind custom button how to get the recordtype
I want to get the recordtype or other fields in javascript on custom button the example code as next: How to get the recordtypeId from the for loop?
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
var url = parent.location.href;
var records = {!GETRECORDIDS($ObjectType.Account)};
var updateRecords = [];
if (records[0] == null) {
alert("Please select at least one record to update.");
} else {
for (var a=0; a < records.length; a++) {
var update_Item = new sforce.SObject("Account");
update_Item.Id = records[a];
update_Item.MyCustomField__c = "My Special Value";
updateRecords.push(update_Item);
}
//This line does the actual update
result = sforce.connection.update(updateRecords);
//Now check if there are any errors
var hasErrors = false;
var errorReport = "The following Accounts could not be updated:\n";
for (var j = 0; j < result.length; j++) {
if (!result[j].getBoolean("success")) {
hasErrors = true;
errorReport += ("AccountId: " + updateRecords[j].Id + ", error: " + result[j].errors.message + "\n");
if (j == 10 && j < result.length) {
errorReport += ("Maximum errors to display. Will show first 10 out of " + "result.length\n");
break;
}
}
}
if (hasErrors) {
alert(errorReport);
}
parent.location.href = url;
}
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
var url = parent.location.href;
var records = {!GETRECORDIDS($ObjectType.Account)};
var updateRecords = [];
if (records[0] == null) {
alert("Please select at least one record to update.");
} else {
for (var a=0; a < records.length; a++) {
var update_Item = new sforce.SObject("Account");
update_Item.Id = records[a];
update_Item.MyCustomField__c = "My Special Value";
updateRecords.push(update_Item);
}
//This line does the actual update
result = sforce.connection.update(updateRecords);
//Now check if there are any errors
var hasErrors = false;
var errorReport = "The following Accounts could not be updated:\n";
for (var j = 0; j < result.length; j++) {
if (!result[j].getBoolean("success")) {
hasErrors = true;
errorReport += ("AccountId: " + updateRecords[j].Id + ", error: " + result[j].errors.message + "\n");
if (j == 10 && j < result.length) {
errorReport += ("Maximum errors to display. Will show first 10 out of " + "result.length\n");
break;
}
}
}
if (hasErrors) {
alert(errorReport);
}
parent.location.href = url;
}
var qr = sforce.connection.query(“SELECT id,recordtypeid FROM Account);
and then loop through the records using for loop
for (var i=0;i<qr.records.length;i++)
{
update_Item.recordtypeid= qr.records[i].recordtypeid;
}
hope this helps.
All Answers
var qr = sforce.connection.query(“SELECT id,recordtypeid FROM Account);
and then loop through the records using for loop
for (var i=0;i<qr.records.length;i++)
{
update_Item.recordtypeid= qr.records[i].recordtypeid;
}
hope this helps.