Example Encrypting and Decrypting: Apex Classes Reference
Example Encrypting and Decrypting: Apex Classes Reference
// Encrypt the data and have Salesforce.com generate the initialization vector
Blob encryptedData = Crypto.encryptWithManagedIV('AES256', cryptoKey, data);
The following is an example of writing a unit test for the encryptWithManagedIV and decryptWithManagedIV methods.
@isTest
private class CryptoTest {
static testMethod void testValidDecryption() {
632
Reference Apex Classes
}
}
EncodingUtil Class
Use the methods in the EncodingUtil class to encode and decode URL strings, and convert strings to hexadecimal format.
633
Reference Knowledge Management Publishing Service Class
Note: You cannot use the EncodingUtil methods to move documents with non-ASCII characters to Salesforce. You
can, however, download a document from Salesforce. To do so, query the ID of the document using the API query
call, then request it by ID.
The following example illustrates how to use convertToHex to compute a client response for HTTP Digest Authentication
(RFC2617):
@isTest
private class SampleTest {
static testmethod void testConvertToHex() {
String myData = 'A Test String';
Blob hash = Crypto.generateDigest('SHA1',Blob.valueOf(myData));
String hexDigest = EncodingUtil.convertToHex(hash);
System.debug(hexDigest);
}
}
Usage
Use the methods in the KbManagement.PublishingService class to manage the following parts of the lifecycle of an
article and its translations:
634
Reference Apex Classes
• Publishing
• Updating
• Retrieving
• Deleting
• Submitting for translation
• Setting a translation to complete or incomplete status
• Archiving
• Assigning review tasks for draft articles or translations
To use the methods in this class, you must enable Salesforce Knowledge. See Salesforce Knowledge Implementation Guide
for more information on setting up Salesforce Knowledge.
Methods
The following are static methods of the KbManagement.PublishingService class.
assignDraftArticleTask String articleId Void Assigns a review task related to a draft article.
String articleId = 'Insert article
String assigneeID ID';
String String assigneeId = 'Insert assignee
ID';
instructions String instructions = 'Please review
this draft.';
Datetime dueDate Datetime dueDate =
Boolean Datetime.newInstanceGmt(2012, 12,1);
KbManagement.PublishingService.
sendEmailNotification assignDraftArticleTask (articleId,
assigneeId, instructions, dueDate,
true);
635
Reference Apex Classes
cancelScheduledArchiving String articleId Void Cancels the scheduled archiving of an online article.
OfArticle String articleId = 'Insert article
ID';
KbManagement.PublishingService.
cancelScheduledArchivingOfArticle
(articleId);
cancelScheduledPublication String articleId Void Cancels the scheduled publication of a draft article.
OfArticle String articleId = 'Insert article
ID';
KbManagement.PublishingService.
cancelScheduledPublicationOfArticle
(articleId);
636