1 / 27

Force IDE (Apex and Visualforce ) Internet Passcode Z6ZT

Force.com IDE (Apex and Visualforce ) Internet Passcode Z6ZT. Caleb Sidel, Strategic Growth, Inc. Agenda. Install Force.com IDE How to run a SOQL query from the IDE How to modify Objects, Workflow, etc (dangerous, but fun!) How to create an Apex Trigger (just the shell)

butch
Download Presentation

Force IDE (Apex and Visualforce ) Internet Passcode Z6ZT

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Force.com IDE(Apex and Visualforce)Internet Passcode Z6ZT Caleb Sidel, Strategic Growth, Inc.

  2. Agenda • Install Force.com IDE • How to run a SOQL query from the IDE • How to modify Objects, Workflow, etc (dangerous, but fun!) • How to create an Apex Trigger (just the shell) • How to create a Visualforce Page (just the shell) • How to run testMethods • What is the Developer Console? • Running testMethods • Running queries • Running anonymous script statements (dangerous, but fun!) • Apex Trigger – Create a Case from an Opportunity • Visualforce – De-dupe before Saving an Account • Community Resources • Technical Resources

  3. Install Force.com IDE • IDE Install Guide • https://developer.salesforce.com/page/Force.com_IDE_Installation • Eclipse 4.3 Kepler • http://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/keplerr • Java • https://www.java.com/en/download/ • To Check your Java Version on a PC • Run CMD • At the command prompt type ‘java –version’ • To Check your Java Version on a Mac • Open TERM • At the prompt type ‘java –version’

  4. Project Browser • SOQL query using the .schema • Objects, Workflow, etc. • New Apex Trigger • New Visualforce Page • New Apex Class • Helper • Controller Extension • Run a single Test Class/All Test Classes

  5. New Project

  6. SOQL & Schema Browsing

  7. Metadata

  8. Metadata • Ever want to turn off every Workflow for an Object? • Open the object’s XML file, copy the contents into a text editor, then set <active>false</active> for everything in Eclipse, then revert back when done. • Ever want to know where a field is used? • Maybe you have data being changed and you can’t figure out why – maybe it is referenced in a field update or a trigger!

  9. New Apex/Visualforce

  10. Developer Console • Queries • Running Tests (All vs One) • Anonymous Script Statements • (aka living on the edge)

  11. Developer Console - Query

  12. Developer Console – Run Tests

  13. Developer Console – Anonymous

  14. Code Examples • Apex Trigger – Create a Case from an Opportunity • Visualforce – De-dupe before saving a Lead

  15. Trigger • Create a Case from an Opportunity • Have you ever wanted to create a project once an Opportunity is Closed/Won? Or a survey when a Case is Closed? Or create an Order when an Opportunity is Closed/Won?

  16. Trigger (GOOD) List<Case> casesToInsert = new List<Case>(); for(Opportunity o : Trigger.new) { //Filter out the Id or Keyword etc if(o.IsWon) { Case c = new Case(); c.Subject = o.Name; c.Description = o.Description; c.AccountId = o.AccountId; c.Oppoprtunity__c = o.Id; //You can set origin, type, status, etc //NEVER do a QUERY or a DML (insert, update, delete, upsert) INSIDE A LOOP!!! casesToInsert.add(c); } } //Done with the loop, what about the insert? if(casesToInsert.size() > 0) { //DO NOT do a try/catch and ignore the error //insert below will cause the entire trigger to fail if there is even 1 case with an error. //maybe this is good? insert casesToInsert; //If you’d rather you can use Database.insert() and handle errors one at a time. //Sometimes this is good. Just don’t “hide” the errors in System.debug() statements. //throw them or email them or something! }

  17. Trigger (BAD) List<Case> casesToInsert = new List<Case>(); for(Opportunity o : Trigger.new) { //Filter out the Id or Keyword etc if(o.IsWon) { Case c = new Case(); c.Subject = o.Name; c.Description = o.Description; c.AccountId = o.AccountId; c.Oppoprtunity__c = o.Id; //You can set origin, type, status, etc //NEVER do a QUERY or a DML (insert, update, delete, upsert) INSIDE A LOOP!!! insert c; //BAD! BAD!!!! } } //Done with the loop, what about the insert? if(casesToInsert.size() > 0) { //BAD try { insert casesToInsert; } catch (Exception exp) { //This exception only goes to a log when you monitor it. No one will ever know of the error :( System.debug(exp); } }

  18. Visualforce Page • There are a ton of de-dupe before saving a Lead apps out there, so don’t actually code this in a real org! But it makes for a simple example • There are lots of ways of going about this. This is how I like to do it: • First set yourself up with Development Mode (see next slide) • Then, in your Salesforce org/browserenter the URL https://naX.salesforce.com/apex/DeDupePage • The wizard will walk you through creating the page!

  19. Development Mode

  20. Visualforce Page – The Page (pre Extension) <apex:pagestandardController="Lead“ > <apex:form > <apex:pageBlock mode="edit" > <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!Save}" /> <apex:commandButton value="Cancel" action="{!Cancel}" /> </apex:pageBlockButtons> <apex:sectionHeader title="Lead"/> <apex:pageBlockSection title="Details" columns="1" > <apex:inputField value="{!Lead.Firstname}" /> <apex:inputField value="{!Lead.Lastname}" required="true" /> <apex:inputField value="{!Lead.Company}" required="true" /> <apex:inputField value="{!Lead.Email}" required="true" /> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

  21. Visualforce Page • If you’ve created your Visualforce Page via the Salesforce “browser” UI then once you add an “extension” or “controller” to your Page (see next slide) Salesforce will generate the Controller shell code for you! • Then you can refresh your IDE and edit the Controller there to get type ahead and other IDE goodness

  22. Visualforce Page – The Page (post Extension) <apex:pagestandardController="Lead" extensions="VFC_LeadDeDupeExt" > <apex:form > <apex:pageBlock mode="edit" > <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!customSave}" /> <apex:commandButton value="Cancel" action="{!Cancel}" /> </apex:pageBlockButtons> <apex:sectionHeader title="Lead"/> <apex:pageBlockSection title="Details" columns="1" > <apex:inputField value="{!Lead.Firstname}" /> <apex:inputField value="{!Lead.Lastname}" required="true" /> <apex:inputField value="{!Lead.Company}" required="true" /> <apex:inputField value="{!Lead.Email}" required="true" /> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

  23. Visualforce Page – The Controller public with sharing class VFC_LeadDeDupeExt { ApexPages.StandardControllerstdController; private Lead currentLead; public VFC_LeadDeDupeExt(ApexPages.StandardController controller) { stdController = controller; currentLead = (Lead)controller.getRecord(); } public PageReferencecustomSave() { List<Lead> duplicates = [SELECT Id FROM Lead WHERE Email = :currentLead.Email]; if(duplicates != null && duplicates.size() > 0) { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Error: A duplicate email address was found with Id: ' + duplicates[0].Id)); return null; } //try //{ return stdController.save(); //} //catch (Exception exp) //{ //TODO display pretty errors //} return null; } }

  24. Common Force.com Terms • Trigger – custom code that runs on save (like a workflow rule) • Visualforce – custom code that makes the screen look however your heart desires • Batch Apex – apex code that can run on Millions upon Millions of records • Scheduled Apex – apex code that runs at a set time each day (up to 5 times per day (shhhh - there is an exception via Developer Console)) • Force.com API (SOAP) – the “old fashioned” (i.e. good) way to integrate data into/out of salesforce • Force.com API (REST API) – the “new fashioned” way to do real-time or highspeed integrations of small transactional data • Native vs Non-Native Applications – Native applications run 100% on Force.com (and if we stretch, this also means Heroku). Non-native applications require a separate server to run a portion of the code. Why write non-native? That code supports non-Salesforce use cases. That code requires massive data volumes/complexities that Force.com would otherwise limit. That code was cheaper to write in Ruby/Java than Force.com.

  25. Community Resources • Developer Site: http://developer.force.com/ • Developer Discussions: http://boards.developerforce.com/sforce/?category.id=developers • Linked In Community: • Salesforce.com Professional Community • Salesforce.com Certified Professionals • Austin Force.com Developer Group • Meetup Site

  26. Technical Resources • Introduction to the Force.com Database • How to Create a Custom Object • Introduction to Force.com Apex Code • VisualForce Webinar (skip to 9:45) – nice overview • VisualForce Quick Start (VisualForce Developer's Guide p15-25, 32-39) • Creating a Developer Edition Account • Apex Language Reference and Wiki • VisualForce Developer's Guide and Wiki • Force.com Developer’s Guide • Force.com Web Services API Developer's Guide • Developer Technical Wiki

  27. Contact Information • More contact information then even I know what to do with! • caleb.sidel@strategicgrowthinc.com • 512.814.5775 • Twitter: @calebsidel • LinkedIn: www.linkedin.com/in/csidel • Dreamforce Chatter

More Related