Apex Calls Between Independent Packages

You have a great idea for a process “Orchestrator” utility that can coordinate processes across your existing Force.com products, and perhaps involve some third-party apps too. Orchestrator may want to create, read, update and delete records within these products, but because of its process-oriented nature it will need to initiate existing product processes that have been exposed as Apex APIs.

Your customers may want to use Orchestrator with a variety of product combinations – so they won’t all have the same packages installed. But there’s a problem. Making a call in Apex from one package (Orchestrator) to APIs (Apex methods) in your product packages will create a dependency between the packages:

2013-02-05-DependentPackages

If Orchestrator has the ability to work with any of your products then all of your products must be installed in order to install Orchestrator.

This is not ideal. Orchestrator needs to call the Apex APIs within the other packages, but it also has to be independent of the other packages.

Continue reading

Posted in Patterns | Tagged , , , , | 1 Comment

Apex Method of the Day – Database.Batchable

MyIterableBatch implements Database.Batchable<AnyTypeYouLike>

Examples:
IntegerIterableBatch.cls
CustomTypeIterableBatch.cls

Force.com Apex Code Developer’s Guide – Using Batch Apex

Original Tweet

Posted in Documentation | Tagged , , | Leave a comment

Salesforce as an Identity Provider for Customer Portal

Salesforce Customer Portal is the Force.com ISV’s natural choice for providing support to users of their applications. However, requiring customers to log in to a Customer Portal using a Salesforce username and password which is separate from their own Salesforce login is cumbersome.

Fortunately, you can configure single sign-on using OAuth, with Salesforce as the identity provider for your Portal. This means that Portal users are identified by their Salesforce user accounts in their own orgs.

This was the approach taken to deliver the FinancialForce Community, which was launched at Dreamforce 2012.

Single sign-on is convenient for your customers, as they can move seamlessly from their own org to your Portal without being challenged for a separate username and password, but this also allows you to automatically update your customer Contact records via the single sign-on process. When the customer first signs-on via OAuth they must agree to share their user information with you in order to complete authentication.

There is a small problem however, relating to sessions. When a customer logs in to your Portal (whether by username and password, or by OAuth) a session id cookie for the Portal session will be created. If the Portal and the user’s own org are on the same domain, say na1.salesforce.com for example, then the customer’s session id for their own org will be overwritten. They could not work simultaneously in both their own org and the Portal, and they would need to log back in to their own org when they finish with the Portal. However, we can overcome this by using a Force.com Site to ensure that your Portal is on a unique domain, for example: foobar.force.com

I will be walking through the steps needed to set up single sign-on into a Portal using Salesforce as the identity provider, and using a Site to make the Portal domain unique.

I will be treading as narrow a path as possible, so I will not be covering detailed Portal or Site configuration. As we’re configuring single sign-on between orgs, we’ll be using two orgs – a vendor org which will host the Customer Portal, and a customer org where we will have our user who will access the Customer Portal via single sign-on.

I recommend working through this process using a trial or developer vendor org before attempting the same in a production org – some steps are irreversible! I am using a clean Developer Edition org for my vendor org, and a second Developer Edition org as my customer org.

Continue reading

Posted in Tutorials | Tagged , , , | Leave a comment

Apex Method of the Day – List Iterator

List<T> foo;
Iterator<T> bar = foo.iterator();
T baz = bar.next();

Example:

List<String> fruit = new List {'Orange','Apple','Banana','Peach'};
List<String> seed = new List {'Pip','Seed','Seed','Stone'};
Iterator fruitIterator = fruit.iterator();
Iterator seedIterator = seed.iterator();
while(fruitIterator.hasNext() && seedIterator.hasNext())
{
    String fruitItem = fruitIterator.next();
    String seedItem = seedIterator.next();
    system.debug(fruitItem + seedItem);
}

Force.com Apex Code Developer’s Guide – List Methods
Force.com Apex Code Developer’s Guide – Custom Iterators

Original Tweet

Posted in Documentation | Tagged , | Leave a comment

Apex Method of the Day – JSON.deserialize(jsonString, List.class)

List<Foo> f = (List<Foo>) JSON.deserialize(jsonString, List<Foo>.class);

Force.com Apex Code Developer’s Guide – JSON Methods

Original Tweet

Posted in Documentation | Tagged , , | 1 Comment

Apex Method of the Day – New Map from SObject List

List<SObject> lst;
...
Map<ID, SObject> mp = new Map<ID, SObject>(lst);

Force.com Apex Code Developer’s Guide – Maps from SObject Arrays

Original Tweet

Posted in Documentation | Tagged , , | Leave a comment

Apex Method of the Day – addFields

public class MyControllerExtn
{
   public MyControllerExtn(ApexPages.StandardController c)
   {
      // include fields not referenced on the Visualforce page
      c.addFields(new List<String>{'Foo__c','Bar__c','Force__c'});
   }
}

Force.com Apex Code Developer’s Guide – StandardController Class

Original Tweet

Posted in Documentation | Tagged , , | Leave a comment