Code Monkey home page Code Monkey logo

salesforce-wave-api's Introduction

Salesforce Wave Client Library

A Java client library for [Salesforce Wave REST API] (https://resources.docs.salesforce.com/sfdc/pdf/bi_dev_guide_rest.pdf).

Features

This library can be used as a Java Client of Salesforce Wave API.

Usage

This library requires Salesforce username, Salesforce password and Salesforce loginURL.

  • Account provided in Salesforce username should have WAVE API privilege
  • Salesforce password should be appended with security token. For example, if a user’s password is mypassword, and the security token is XXXXXXXXXX, the user must provide mypasswordXXXXXXXXXX
  • loginURL can be http://login.salesforce.com or http://test.salesforce.com

Querying a dataset

This library can be used

Maven Dependency

<dependency>
    <groupId>com.springml</groupId>
    <artifactId>salesforce-wave-api</artifactId>
    <version>1.0.5</version>
</dependency>

Example Usage to query datasets using SAQL

import com.springml.salesforce.wave.api.APIFactory
import com.springml.salesforce.wave.api.WaveAPI;
import com.springml.salesforce.wave.model.QueryResult;
import com.springml.salesforce.wave.model.Results;

WaveAPI waveAPI = APIFactory.getInstance().waveAPI("salesforce_username",
		"salesforce_password_appended_with_security_token", 
        "https://login.salesforce.com");
String saql = "q = load \"dataset_id/dataset_version_id\"; q = group q by ('field1', 'field2'); q = foreach q generate 'field1' as 'field1',  'field2' as 'field2', count() as 'count'; q = limit q 2000;";
QueryResult result = waveAPI.query(saql);
List<Map<String,String>> records = result.getRecords();

Example Usage to query Salesforce objects using SOQL

import com.springml.salesforce.wave.api.APIFactory
import com.springml.salesforce.wave.api.ForceAPI;
import com.springml.salesforce.wave.model.SOQLResult;

ForceAPI forceAPI = APIFactory.getInstance().forceAPI("salesforce_username",
		"salesforce_password_appended_with_security_token", 
        "https://login.salesforce.com");
String soql = "SELECT AccountId, Id FROM Opportunity";
SOQLResult result = forceAPI.query(soql);
List<Map<String,Object>> records = result.getRecords();
// By default Salesforce will return 2000 records in a single call
// To query more use queryMore()
while (!result.isDone()) {
    result = forceAPI.queryMore();
    records.addAll(result.getRecords());
}

Example Usage to update Salesforce objects using Bulk API

import com.springml.salesforce.wave.api.APIFactory
import com.springml.salesforce.wave.api.BulkAPI;
import com.springml.salesforce.wave.model.JobInfo;
import com.springml.salesforce.wave.model.BatchInfo;

BulkAPI bulkAPI = APIFactory.getInstance().bulkAPI("salesforce_username", 
		"salesforce_password_appended_with_security_token",
        "https://login.salesforce.com", "36.0");
// Here we are updating Contact
JobInfo jobInfo = bulkAPI.createJob("Contact");
String jobId = jobInfo.getId();
// CSV Content contains the details to updated
// First column contains the Saleforce Object ID
// And further columns should contain the fields to be updated
// Here Description is updated for two Contacts
String csvContent = "Id,Description\n003B00000067Rnx,SuperMan\n003B00000067Rnw,SpiderMan";
// Adding batch to the created Job
// Please note that, csvContent should not exceed 10MB
// Add multiple batches if the content to be updated is more than 10 MB
BatchInfo batch = bulkAPI.addBatch(jobId, csvContent);
// Close the Job after adding all the batches
JobInfo closeJob = bulkAPI.closeJob(jobId);
// bulkAPI.isCompleted(jobId) can be used to check whether the job has been completed
while (!bulkAPI.isCompleted(jobId)) {
    // Waiting till the Job has been completed
    Thread.sleep(500);
}

salesforce-wave-api's People

Contributors

samuel-pt avatar k4jiang avatar springml avatar skinserloanpal avatar unintellisense avatar nhamiltontt 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.