I am new on Salesforce, I am confused in Apex and Visualforce, actually I want to know the basic difference between Apex and Visualforce.


Yes. At it's most basic level, Visualforce is really just glorified HTML. You can use standard HTML and CSS in Visualforce pages. This is pretty much the same as any web site you visit. This is referred to as the "view"

Apex's syntax is very similar to Java and acts as a controller. What this does is define what the view see's and does and can manipulate the model (your Salesforce database).

Here's a little diagram to help you understand:

enter image description here

In a nutshell:

  • View: The presentation of data (Visualforce)
  • Controllers: Logic definition (Apex)
  • Model: A place where you store your data (SF Objects and Fields)
  • 1
    I would add that there is no objectual representation of the model (ie: it's not a class per se). The 'model' are just public properties in the controller really.
    – mkorman
    Dec 16 '15 at 11:28

Visualforce is a framework used for custom User Interface features.

Apex is custom code that can be evaluated in many different places including:

  • When a record is saved (trigger)
  • As a bound action for a Visualforce page (custom or standard controller)
  • As a javascript remote method invocation (custom controller)
  • As server-side functionality for Lightning Components
  • As an invocable action in a Flow
  • As a scheduled job
  • As a custom REST or SOAP API
  • As a one-off excution for testing code logic (execute anonymous)
  • In many places that our R&D department want to use programming logic on the platform (yes, we use Apex for coding, too...one example of this is the StandardController Apex class).

Another distinction is that Visualforce is primarily mark-up, with support for formulas, whereas Apex is a proper programming language.

Of course you will have noted that Visualforce and Apex interact, which is perhaps why you may have some confusion. There are a number of pages in the Visualforce developer guide that describe the page lifecycle. These may help you to understand better.

As you read them, pay attention to any references to what the controller is doing, or references to "actions are triggered". These are references to when the Visualforce page is invoking an Apex method of some sort.

Also pay attention to references to things being "created". These are references to when the Visualforce framework is doing the job of rendering HTML on the server side which will then be passed to the browser as an HTML page (when all is said and done, by the time your browser is showing the "Visualforce page" all you are really seeing is HTML...Visualforce is the engine that makes the HTML on the server side...this is why, if you look at the page source in your browser, you won't see any apex:whatever tags anymore...these are just instructions to the server to tell it what kind of HTML to create).

That's all a bit long winded, but in the end it all boils down to two things:

  • Visualforce is responsible for making the page that you are looking at
  • Apex is responsible for that page being able to interact with the server

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.