Git Product home page Git Product logo

rforce-meta's Introduction

Use in conjunction with RForce to interact with the SalesForce Metadata API (as opposed to the regular API).  This will allow you to do things such as add custom fields to SalesForce objects.  Note that this project is not particularly well-maintained and is basically provided as proof that a more refined effort at a later time would provide a suitable library for interacting with this API.  I am offering this up on the chance it is useful to someone as SalesForce offers an abundance of useless information with regard to using this API and very little concrete or useful for Ruby programmers or anyone operating outside of Java.

Much of this code is borrowed from RForce, which is a much better library, but does not work with the Metadata API out of the box.

SETUP:
1) Drop this file in your Rails /lib 

2) Define the constant SALESFORCE as a hash with your SalesForce email and password somewhere

3) Add some methods to ApplicationController:
N.B. if this doesn't suit your style, edit the salesforce_meta.rb file to accept the metadata url in some other way such as by passing an argument on initialization.  Note that the metadata url will be returned in the response to your login to the regular SalesForce API as indicated below.

  ### SalesForce
  @@salesforce = nil
  @@salesforce_metadata = nil
  @@salesforce_metadata_server_url = nil
  
  def self.salesforce
    unless @@salesforce
      require 'rforce'
      s = RForce::Binding.new 'https://www.salesforce.com/services/Soap/u/10.0'
      response = s.login SALESFORCE['email'], SALESFORCE['password']
      @@salesforce = s # do assignment here so that if login fails (RuntimeError), nothing will be assigned
      @@salesforce_metadata_server_url = response[:loginResponse][:result][:metadataServerUrl]
    end
    @@salesforce
  end
  
  def self.salesforce_metadata
    unless @@salesforce_metadata
      require 'salesforce_metadata'
      @@salesforce_metadata = SalesforceMetadata.new
    end
    @@salesforce_metadata
  end
  
  def self.salesforce_metadata_server_url
    @@salesforce_metadata_server_url
  end 

4) Use in your project, here are some examples:

  require 'salesforce_meta'
  s = SalesforceMeta.new

  s.create(:fullName => "Contact.MyBool", :label => "Something Was Completed", :type => "Checkbox", :defaultValue => false)
  s.create(:fullName => "Contact.MyDate", :label => "Date It Was Completed On", :type => "Date")

  s.destroy(:fullName => "Contact.MyBool")
  s.destroy(:fullName => "Contact.MyDate")


rforce-meta's People

Contributors

alexfarrill avatar

Stargazers

Joey Chan avatar ketan avatar  avatar  avatar Bruce Burdick avatar

Watchers

 avatar James Cloos avatar

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.