Monday, December 27, 2010

Inheritance and Visualforce page controllers

Salesforce Apex is pretty finicky with inheritance in comparison to Java.
Even though it is Java based, there are many caveats, especially in inheritance and OO related principles.

In Visualforce, you have the option of denoting either a StandardController or Controller, in addition to controller extensions.  The extensions may or may not have code in common with the controller.  If they do, then you'll want to take advantage of inheritance and creating an abstract controller.

Below is a simple example of a Visualforce page utilizing an abstract controller.

Test.page:

<apex:page controller="Test" extensions="Test1,Test2,Test3">
<apex:form>
<apex:commandButton value="Go" action="{!go}" rerender="out" />
<apex:outputPanel id="out">{!output}</apex:form>
</apex:page>

Test.cls:
public abstract class Test {
  public String output {get; set;}
 
  private Test controller = null;
 
  public Test(){}
 
  public Test(Test controller){
      this.controller = controller;
  }
 
  public virtual void go(){
      output = 'Test';
  }
}

Test1.cls:
public class Test1 extends Test{
  public override void go(){
      this.output = 'Test1';
  }
  //Visual force needs this constructor to perform the controlling logic
  public Test1(Test test){ super(test); }
}

Test2.cls:
public class Test2 extends Test{
  public override void go(){
      this.output = 'Test2';
  }
  public Test2(Test test){super(test);}
}

Test3.cls:
public class Test3 extends Test{
  public override void go(){
      this.output = 'Test3';
  }
  public Test3(Test test){super(test);}
}

FYI, if you're reading through the Advanced developer study guide, 'Test1' is printed after clicking  the go command button.

Thursday, December 16, 2010

ORA-12519

I created a polling adapter in my BPEL process.  Once I threw it on the server, it caused the Oracle XE (10.1.3?) database to crash.  After the database crashed, I could not view the BPEL console nor execute any commands on the database through SQL Developer.  The error I received was 'ORA-12519'.

What happens is that the XE database by default only allows a small number of connections.  BPEL consumes those connections rather quickly. If you encounter this problem, restart the XE database:
  1.   Perform the following SQL as SYS user: ALTER SYSTEM SET PROCESSES=150 SCOPE=SPFILE
  2. Restart the database
  3. Restart BPEL / SOA

Wednesday, December 15, 2010

BPEL and TopLink - Method Accessors have not been selected

This error occurs when adding a DbAdapter in BPEL, having a master-detail or 1 to many relationship.  There's more information on this defect and a solution at this link: http://iadviseblog.wordpress.com/category/toplink/.  Search for 'Method accessors'.

BPEL - Importing schemas for Polling orchestration

By default, BPEL orchestrations are started with a client partner link with two activities, one for input and one for output. When creating a polling orchestration, or an orchestration that polls from a database rather then waits for an http request, the first task is to remove the partner link and the two activities. Unfortunately, this renders the client WSDL useless.
Without the client WSDL, there's no other way to import additional schemas into the BPEL orchestration. Or is there? When you create the polling activity in BPEL, it generates an XSD and a WSDL file for the Polling partner link. When you need to add additional schemas to your BPEL process, then add the following into your Polling WSDL. (If the types element already exists, then you can add your schema import there).



After saving the WSDL, be sure to add the declaration of the schema and namespace to your bpel source. Then you should be able to reference the schema in your orchestration.

Thursday, December 9, 2010

Passing null values for xml elements

I've been working on a Salesforce webservice class to create cases. After generating the wsdl, I ran into a couple issues.

First issue: The order of the child elements in the method's parent need to match the webservice method you're calling. Found this out after changing some elements around and getting 'invalid format for xsd:dateTime' when it was a string or an Integer instead. This also means you need to specify all the elements as well. Which leaves me to my next issue.

Second issue: I kept receiving 'invalid type '' for xsd:dateTime when attempting to pass nulls into the element. ,, all return the same error. Instead, you have to declare the schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance and include xsi:nil="true" in your element. After I changed all my optional dateTime elements to , I was able to invoke my web service.

Now, why I have to include a separate schema just to include null values in my xml is beyond me.

- J