Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

Solution

To work with multiple records, loop through all records with a particular tag, collect their ItemIds, and edit them on an individual basis.

Suppose that all Northwest and Southwest tags need to be consolidated to a single West Coast tag. To remove the tags and replace them:

1.
Store the accounts that contain the tags you want to delete. You can execute the following in the AJAX Toolkit or your own client application:

var westCoastAccounts = sforce.connection.query("SELECT ItemId,
 Id
 FROM AccountTag WHERE Name = 'Northwest' OR Name =
'Southwest'");

2.
Create the new West Coast tag. Add the ItemIds by looping through the records:

var WestCoastTagArray = new Array();
for (var i = 0; i < westCoastAccounts.size; i++)
{
 WestCoastTagArray[i] = new sforce.SObject('AccountTag');
 WestCoastTagArray[i].Name = "West Coast";
 WestCoastTagArray[i].Type = "Public";
 WestCoastTagArray[i].ItemId =
westCoastAccounts.records[i].ItemId;
}
sforce.connection.create(WestCoastTagArray);

3.
Delete all instances of the Northwest and Southwest tags:

var IdsToDelete = new Array();
for (var k = 0; k < westCoastAccounts.size; k++)
{
 IdsToDelete[k] = westCoastAccounts.records[k].Id;
}
sforce.connection.deleteIds(IdsToDelete);

  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint