Retrieving blob objects from Azure with Apex

Maybe you need to retrieve blobs stored in Azure Storage Services and save them as Salesforce attachments. Let’s suppose we have an attachment base64 encoded stored as a blob in Azure. We could retrieve it with the following snippet: String blobName = ”; String urlQueue = ‘https://.blob.core.windows.net//’ + blobName; string storageKey = ”; Datetime dt […]

CreatedDate in test classes

Finally Salesforce fills the gap and allows you to specify the createddate field within test classes. You only have to use the Test.setCreatedDate method introduced with Spring ’16. @isTest private class CreatedDateTest { static testMethod void test() { Contact c = new Contact(FirstName =’Marc’, LastName = ‘Benioff’); insert c; Test.setCreatedDate(c.Id, DateTime.newInstance(2016, 1, 26)); Test.startTest(); Contact […]

Manage UserTerritory table through REST API

UserTerritory is one of the few objects that don’t allow DML Operations. However, we can manage it through the REST API. We could assign a User to a Territory by using the following APEX code: HttpRequest req = new HttpRequest(); Http http = new Http(); String baseUrl = URL.getSalesforceBaseUrl().toExternalForm(); req.setEndpoint( baseUrl + ‘/services/data/v34.0/sobjects/UserTerritory/’); req.setHeader(‘Authorization’, ‘OAuth […]

Defensive future calls

I would like to talk about the wonderful and simple pattern for making future calls. This pattern was presented by Dan Appleman at one of his sessions at Dreamforce this year. It looks like this: public void CallFuture2() { if(System.isFuture() ||system.isBatch()) defensiveFutureCallSync(); else { if(Limits.getFutureCalls() < Limits.getLimitFutureCalls()) defensiveFutureCallAsync(); else { // error handling } } […]

Using JWT to share data between Orgs

Let’s suppose we want to show some records in our Salesforce Org, let’s call this Org “A”, but this information is stored in another Salesforce Org, “B”. There are several ways to accomplish this requirement. We could use Salesforce-to-Salesforce to share records between different Orgs. We could also use third-party tools like Informatica Cloud or […]