Giter VIP home page Giter VIP logo

sfdc.js.demo's Introduction

Salesforce JavaScript Demo

This is a demonstration of the capabilities of JavaScript as used within the Salesforce.com platform. This provides practical examples of JavaScript Remote Actions, DOM Manipulation, and Libraries to make development considerably easier. These examples are shown in the context of a custom VisualForce page as well as being integrated into a standard Salesforce page.

The practical example of the demonstration is to quickly add products to an opportunity. This is not production ready. The intention is to give a developer guidance and real world examples of how to leverage JavaScript and RemoteActions in Salesforce.

As seen at Denver Developer User Group on 7/31/2013. ScreenShot ##File Explanations

##Editing Standard Page DOM / Cross-Domain Considerations

  • Adding a VisualForce page into the standard page layout is simple, just use the WYSIWYG Page Layout editor. Unfortunately, this loads your VisualForce page (from the domain c.< instance number >.visual.force.com) into the standard page (from the domain < instance number >.salesforce.com). This complicates our life, as iframes from a different domain are isolated within the browser. You cannot parse the contents nor execute any functions using JavaScript from one domain to the other.
  • Our solution to this is to use the HTML5 method window.PostMessage. This allows the passing of messages via the browser's main window object. You will have a listener method on the standard salesforce page and another method to send a message from the iframe.
  • The pertinent JS for this can be viewed at iframe side and standard page side

##Replicating this demo in your own Development Org

  • First deploy these files using your favorite method. Eclipse IDE, MavensMate, or plain old copy pasting into the Setup UI.
  • Now you should be able to view the VisualForce page and see it working by pasting in a valid Opportunity record Id and swapping the comments here

Integrating into the Standard Opportunity page

  • Add the VisualForce page to the Opportunity layout by going to Setup -> Customize -> Opportunities -> Page Layouts -> Opportunity Layout, clicking Edit, selecting Visualforce Pages in the WYSIWYG Editor and dragging it down to somewhere in the page layout where it can be 100% width and ~400px tall. Click Save.
  • Now you should be able to see the quick product add UI on the standard layout page. Make sure to fix this, if you edited it earlier. You should notice a UX bug pretty quick. The standard Opportunity Detail section does not update with the changes from your Remote Action updates. This is where we need to get creative with the cross-domain mumbo jumbo.
  • So what can modify the DOM on the Standard Page? Javascript on the standard page! How do we do that? We can inject via a homepage component with the type HTML area. The Procedure for this is to go to Setup -> Customize -> Home -> Home Page Components -> New Custom Components, then create a new component with name OppQuickAddInjection with type HTML area. Then you can check the Show HTML checkbox in the editor and paste in this JavaScript. Select Narrow (Left) Column and hit Save.
  • Now we need to add our new component to the sidebar layout by Going to Setup -> Customize -> Home -> Home Page Layouts, editing the appropriate layouts, checking OppQuickAddInjection and hitting Next & Save.
  • In order to show this custom component on all pages we have to tweak a setting located at Setup -> Customize -> User Interface. Check "Show Custom Sidebar Components on All Pages" and hit save.
  • We now have a JavaScript listener on all pages looking for a message from our VF Page in an iframe. Once it receives this message it will update the appropriate DOM element with the new data.
  • When you go back to the opportunity page and use the widget you should see the Opportunity Detail "Amount" field changing as you make updates in the widget.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.