Showing posts with label Apex Classes Visualforce Controllers Getter Setter Method Salesforce force.com. Show all posts
Showing posts with label Apex Classes Visualforce Controllers Getter Setter Method Salesforce force.com. Show all posts

Tuesday, 18 January 2011

Ruby and Salesforce Integration

With the announcement that Salesforce acquired the cloud platform Heroku I had to take a more vested interest in Ruby. Though I was aware of the capabilities of Ruby I would definitely consider myself a newbie with this type of programming. In order to jump on the bandwagon I started an extensive Ruby programming class which will allow me to build my skill set over the next couple of months.

That being said learning Ruby is great and all but the key is using it within the Salesforce platform. The next couple of posts will describe how we will use SOAP to integrate Ruby and Salesforce.

-First you need to install Ruby.  InstantRails 2.0 is radical.
-Access your developer account. Go to Setup->Develop->API then choose "enterprise.wsdl" and save it. Here is an example:

D:\RubyRails\rails_apps\sfdc\enterprise.xml

-Open the Ruby console and then install ‘SOAP4R’ by using this command:

gem install soap4r

You may get an error after running this command that reads "Errno::EADDRNOTAVAIL". This will happen if your Ruby gems are outdated. This is a simple problem to fix by going to the following site:


-After downloading the gems send them to a directory. You can then access that directory from the command line.
-Install the gems with the following command:

ruby setup.rb

At this point everything should be properly installed and you should not run into any errors. Go to the directory where you saved the ‘enterprise.xml’ and use the following command:

ruby wsdl2ruby.rb --wsdl D:\RubyRails\rails_apps\sfdc\enterprise.xml --type client –force

If everything goes well there should be four new files in your Salesforce directory. First step is complete! Next post we will use a code generated from Andrew’s (Super-size) Interwebdiary to generate an easy login function.

Till then fingers crossed the Jets get smashed by the Steelers this weekend.

Tuesday, 4 January 2011

Visualforce Controllers

The holidays are officially over and now that I have had a few days to recuperate it’s time to get back to work. The application we have been creating is pretty much ready to go… Go back to the Scheduled Invoices tab, and create a new invoice with an effective date two months in the past. Set the Duration to six months; fill out the remaining fields, and click "Save." Mark one of your pending payments as paid and you should now see three lists of payments: Past Due, Pending, and Paid. Granted this application is quite simple…but it was completed in a fraction of time and cost it would take for a traditional application.

So now that the first series of posts have been completed I wanted to jump into Visualforce Controllers. If you remember from previous entries a major component of how our application was rendered was through the use of Visualforce pages. Well a Controller is just Apex Code that analyzes and writes data in the force.com database. Also I need to make sure my blog is longer than a paragraph.

When working with Salesforce it is often required that you will need to display data from the force.com database or even insert data in database variables. Controllers can do these sorts of tasks much more quickly. There are two methods of the Controller that interact with the database variables. The ‘Getter’ method takes the value of the variables and displays it on the Visualforce page. The “Setter” method allows the developer to change the value of the variable using different Visualforce components. These methods operate similarly to the Getter and Setter methods in Java and C++.

A nice thing about the force.com platform is that it provides Standard Controllers, which are basic default controller that have already been implemented.  Though somewhat limited in functionality, you can perform certain changes to the native interface like editing records. Also you can use Apex classes to customize the controller.

My preferred method to the aforementioned Controllers is to create a Custom Controller that is completely user defined. The following is an example of a basic Custom Controller:

Page Code:

<apex:page controller="MyController">
   <apex:form>
         Name: <apex:inputText value="{!name}"/>
        <apex: outputText value="{!mssg}"/>
        <apex:commandLink action="{!Display}" value="Show Message" />
   </apex:form>
</apex:page>

MyController Code:

public class MyController{

      public String name {get ; set;}
      public String mssg {get ; set;}
      public PageReference Display() {
           mssg=’Time To Be Awesome’ + name;
           return null;
      }
}


Awesome!