• Zachariah Rosenberg
  • NEWBIE
  • 25 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 7
    Questions
  • 5
    Replies
Hello,

I'm trying to access a csv document in my Document sObject via apex (in order to parse the csv). I know how to parse CSV one I get the data (there are many articles on that part), but I'm not sure how to grab the document from the documents sObject in the first place!

How do I reference the CSV document (in sObject Document) from Apex?

I did see that a URL is returned from the following query:
​SELECT body From Document WHERE name = 'myCSV'
That returns something like:
/services/data/v32.0/sobjects/Document/00000UptFER/Body
Do I need to point the parser to that address?



Thank you!
Hello,

I'm trying to use Salesforce's bulk API to run a query on some CSV data. Here is the desired result:

In SF, we have a field product.serial__c. I have a CSV with a bunch of serial numbers that I would like to pull other fields from, i.e.
SELECT product.name, product.price__c FROM product where product.serial__c IN (serial_csv)
So I'd like to add a batch, filled with this CSV data and run a query with it.

My question is how the add batch API call should be. Here is my function in python
#Code thanks to http://www.wadewegner.com/2014/04/update-records-with-python-and-the-salesforce-bulk-api/
def addBatch(instance, session_id, job_id, objects):

	request = u"""<?xml version="1.0" encoding="UTF-8"?>
  					<sObjects xmlns="http://www.force.com/2009/06/asyncapi/dataload">
    				 	""" + objects + """
  					</sObjects>"""

  	#encoded_request = request.encode('utf-8')
  	url = "https://" + instance + ".salesforce.com/services/async/32.0/job/" + job_id + "/batch"
  	headers = {"X-SFDC-Session": session_id, "Content-Type": "text/csv; charset=UTF-8"}

  	response = requests.post(url = url, headers = headers, data = request, verify = False)
  	return unicode(response.text)
Currently, I'm placing all my csv data in the objects parameter, i.e.:
csv_data = "0000,0001,0002,0003,0004,...,1111"
response = addBatch(instance, session_id, job_id, csv_data)

Is this incorrect?

Where do I put the query? All the docs on SF seem to point that I would put it in the 'objects' parameter in my function. Then where would my csv data go?

I'm sure I've completely confused how to use this API...

Thank you all!

Best,
Zac
I'm trying to use CSV data in an apex class. There are many articles written about how to parse csv data in apex, but not many on the first part: accessing the csv data in apex. I've looked into import wizard (and data loader) but my csv data is not being uploaded into any sobjects. Rather, the csv data will be used for a SOQL query.

Ultimately I'd like the following query to be able to use my csv data:
SELECT Object.Name Object.custom_field__c FROM Object WHERE custom_field__c in :[csv data]

How can I make this happen?

Thank you so much!
Hello,

I'm trying to strategize how best to run this series of SOQL queries without triggering the limits. I have a csv of approximately 10,000 records. The goal is to check for each record whether there is a contact.owner.name associated with it. For instance (not complete, of course):

For(integer i:[csv file]){
SELECT Contact.Owner.Name. Contact.Custom_Field__c FROM Contact WHERE Contact.Custom_Field__c = csvFile[i]
}

How would you recommend I grab the data for all 10,000 records?

Thank you so much for your time and consideration of my inquiry.

With gratitude,
Zac
Hello,

Im trying to write a SOQL query that will grab one of the Contact object's standard fields "Contact Owner", which is a Lookup(User) field.

The field name is "Owner", but when I try to query

SELECT Contact.Owner FROM Contact

I get an error stating that there is no such field.

How can I grab this field?

Thank you!
Hello,

I'm trying to write an REST aPI call from my google sheets. I originally wrote the call in python, which worked wonderfully. Porting it to JS on google apps, I'm getting a "grant_type" error:
 
function authenticateSF(){

  var url = 'https://login.salesforce.com/services/oauth2/token';
  var options = {
    grant_type:'password',
    client_id:'XXXXXXXXXXX',
    client_secret:'111111111111',
    username:'ITSME@smee.com',
    password:'smee'
  };

  var results = UrlFetchApp.fetch(url, options);
}

Produces:
 
Request failed for https://login.salesforce.com/services/oauth2/token returned code 400. Truncated server response: {"error_description":"grant type not supported","error":"unsupported_grant_type"} (use muteHttpExceptions option to examine full response) (line 12, file "Code")

I saw someone else on this board had a similar problem (https://developer.salesforce.com/forums/#!/feedtype=SINGLE_QUESTION_SEARCH_RESULT&id=906F00000009At3IAE), and he just went the OAuth route. I'd prefer not to, if possible. 

What might the issue be?

Thank you!
 
Hello,

I'm going through the Salesforce API REST guide, and I'm trying to authenticate via session id. My script is in python:

    import urllib, urllib2
    url = 'https://login.salesforce.com/services/oauth2/token'
    values = {
        "grant_type":"password",
        "client_id":"aaaaaaaaaaaa11111111111111",
        "client_secret":"1111111111111",
        "username":"myuser@domain.com",
        "password":"mypassword"
    }
    data = urllib.urlencode(values)
    req = urllib2.Request(url,data)
    sf = urllib2.urlopen(req)

I'm receiving a 400 Error:

    Traceback (most recent call last):
      File "/Users/ZR/Desktop/sf.py", line 14, in <module>
        sf = urllib2.urlopen(req)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 127, in urlopen
        return _opener.open(url, data, timeout)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 410, in open
        response = meth(req, response)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 523, in http_response
        'http', request, response, code, msg, hdrs)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 448, in error
        return self._call_chain(*args)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 382, in _call_chain
        result = func(*args)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 531, in http_error_default
        raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
    urllib2.HTTPError: HTTP Error 400: Bad Request
    [Finished in 0.4s with exit code 1]

Where have I gone wrong?

Thank you! 
Hello,

I'm trying to strategize how best to run this series of SOQL queries without triggering the limits. I have a csv of approximately 10,000 records. The goal is to check for each record whether there is a contact.owner.name associated with it. For instance (not complete, of course):

For(integer i:[csv file]){
SELECT Contact.Owner.Name. Contact.Custom_Field__c FROM Contact WHERE Contact.Custom_Field__c = csvFile[i]
}

How would you recommend I grab the data for all 10,000 records?

Thank you so much for your time and consideration of my inquiry.

With gratitude,
Zac
Hello,

Im trying to write a SOQL query that will grab one of the Contact object's standard fields "Contact Owner", which is a Lookup(User) field.

The field name is "Owner", but when I try to query

SELECT Contact.Owner FROM Contact

I get an error stating that there is no such field.

How can I grab this field?

Thank you!
Hello,

I'm trying to write an REST aPI call from my google sheets. I originally wrote the call in python, which worked wonderfully. Porting it to JS on google apps, I'm getting a "grant_type" error:
 
function authenticateSF(){

  var url = 'https://login.salesforce.com/services/oauth2/token';
  var options = {
    grant_type:'password',
    client_id:'XXXXXXXXXXX',
    client_secret:'111111111111',
    username:'ITSME@smee.com',
    password:'smee'
  };

  var results = UrlFetchApp.fetch(url, options);
}

Produces:
 
Request failed for https://login.salesforce.com/services/oauth2/token returned code 400. Truncated server response: {"error_description":"grant type not supported","error":"unsupported_grant_type"} (use muteHttpExceptions option to examine full response) (line 12, file "Code")

I saw someone else on this board had a similar problem (https://developer.salesforce.com/forums/#!/feedtype=SINGLE_QUESTION_SEARCH_RESULT&id=906F00000009At3IAE), and he just went the OAuth route. I'd prefer not to, if possible. 

What might the issue be?

Thank you!
 
Hello,

I'm going through the Salesforce API REST guide, and I'm trying to authenticate via session id. My script is in python:

    import urllib, urllib2
    url = 'https://login.salesforce.com/services/oauth2/token'
    values = {
        "grant_type":"password",
        "client_id":"aaaaaaaaaaaa11111111111111",
        "client_secret":"1111111111111",
        "username":"myuser@domain.com",
        "password":"mypassword"
    }
    data = urllib.urlencode(values)
    req = urllib2.Request(url,data)
    sf = urllib2.urlopen(req)

I'm receiving a 400 Error:

    Traceback (most recent call last):
      File "/Users/ZR/Desktop/sf.py", line 14, in <module>
        sf = urllib2.urlopen(req)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 127, in urlopen
        return _opener.open(url, data, timeout)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 410, in open
        response = meth(req, response)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 523, in http_response
        'http', request, response, code, msg, hdrs)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 448, in error
        return self._call_chain(*args)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 382, in _call_chain
        result = func(*args)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 531, in http_error_default
        raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
    urllib2.HTTPError: HTTP Error 400: Bad Request
    [Finished in 0.4s with exit code 1]

Where have I gone wrong?

Thank you! 

Can someone point me to the documentation for SOQL's "WHERE x IN :y" syntax, where y is a collection type (list, set, map).  I've tried searching for it, but "where" and "in" are such generic terms that my searches are essentially as useful as just searching for "soql" alone.

 

Thanks!