• dkador
  • SMARTIE
  • 833 Points
  • Member since 2007

  • Chatter
    Feed
  • 32
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 374
    Replies

I'm using Apigee to return the records from OpportunityLineItem object.  But the Rest API doesn't return any records.  

So the following URL just describes the table with empty list

services/data/v20.0/sobjects/OpportunityLineItem

 

The following URL returns all the records

 

services/data/v20.0/query/?q=select+description+from+OpportunityLineItem

 

 

The question is, why is that the first URL not returning any records?

 

Thanks!

Hi all,

 

I have been tasked with finding out if the wsc-22.jar and the generated partner.jar are thread-safe.

We are building an application in Java that will be having multiple threads accessing the partner connection variable and sending queries/updates/creates to SalesForce.

I have found the documentation on the limits, so the limits of 10 query cursors and for concurrent requests (calls) with a duration of 20 seconds or longer:

However nothing really on if the code is thread-safe.

 

Any help in finding an answer to this would be greatly appreciated.

 

Regards,

 

Adrian

Hi,

I am right now working on prerelna1.pre.salesforce.com to evaluate REST API. I am at a point where I am trying to create a managed package (which includes these rest classes).

When I click on upload, I get the following error message "Packages containing Apex REST classes cannot be uploaded."

 

Does these mean that ISVs cannot create apps using REST?

 

Best Regards, Indresh

I'm trying to create a apex code that will be triggered by a button on the lead/contact page to log an activity. It's currently set up to assign the task to the lead owner, but I'm trying to update the code so that it will assign the task to the current user. I keep running into different errors while I try a bunch of stuff, but I'm having a hard time understanding what I need to do and how I should reference this because I'm a novice updating an existing code. I'm not sure where the "Current User" needs to be defined, and when I've tried I've gotten error message that my value doesn't exist or it works and then when I hit the button I get an error message saying that there are multiple values.

I have been trying to find help online, but, like I said, I'm a beginner and I keep getting lost in the apex language.

Thanks!

Here's the first part of the code -

global class logAttempts {
 
  WebService static String createAttempt(
    String sAttemptType,
    String sCallerType, 
    Id objectId) {
      
      List<Task> lstTasks = new List<Task>();
    
    try {
       
      If (sCallerType == 'Lead') {
        Lead newLead = 
          [Select Id, OwnerId, Status, Lead_Stage__c,
           Title, Email
           from   Lead 
           where  ID = :objectId];


HI All,

 

Does any one know if there is any dependency that the webservices should be deployed on axis 2 to be used via apex callouts? or can it be deployed on axis 1 also. Does there exist any such dependency? 

partnerConnection = Connector.newConnection(config);
partnerConnection.login(USERNAME, PASSWORD);
System.out.println("SessionId: " + config.getSessionId());	
			
MyWebServiceBindingStub Stub = new WyndhamMyWebServiceBindingStub();
			
MyWebServiceServiceLocator objMyWebServiceLocator=new MyWebServiceServiceLocator();
Stub=(MyWebServiceBindingStub)new MyWebServiceServiceLocator().getMyWebService();
			
SessionHeader_element sh = new SessionHeader_element();
sh.setSessionId(config.getSessionId());

Stub.setHeader(objMyWebServiceLocator.getServiceName().getNamespaceURI(),"SessionHeader",  sh);
Stub.callAction();

 the code for the my java client looks like this but when I am executing the code am always getting No serializer found for class com.sforce.soap.partner.SessionHeader_element in registry org.apache.axis.encoding.TypeMappingDelegate@96cf11

 

Can somebody help me out, where actually m doing wrong.

  • August 11, 2011
  • Like
  • 0

Hello All,

 

I am trying to create a Bulk API job doing 'UPSERT' to a custom object and getting the following error.

 

job = new JobInfo();

job.setObject("Publication__c");

job.setOperation(OperationEnum.upsert);

job.setContentType(ContentType.CSV);

job.setExternalIdFieldName("External_ID__c ");

 

InvalidJob : Field name provided, External_ID__c is not readable for Publication__c

 

Any help with more details on the error or how to solve is greately appreciated.

 

Thanks in advance.

Ramana Maddikunta

  • August 10, 2011
  • Like
  • 0

Hi,

 

I create a lookup field for Account object and this field related to Account itself too. Now i set the "Field Name" and "Child Relationship Name" to same value "TestLookupAccount". Click next and save.

 

Then i download the enterprise wsdl, and find the schema of this lookup field like this:

<element name="TestLookupAccount__c" nillable="true" minOccurs="0" type="tns:ID"/>
<element name="TestLookupAccount__r" nillable="true" minOccurs="0" type="tns:QueryResult"/>

 But if i set the "Field Name" and "Child Relationship Name" with different values, such as "TestLookupAccount" for "Field Name" and "TestLookupAccountChild" for "Child Relationship Name", then i will get the schema in enterprise wsdl file like this:

<element name="TestLookupAccountChild__r" nillable="true" minOccurs="0" type="tns:QueryResult"/>
<element name="TestLookupAccount__c" nillable="true" minOccurs="0" type="tns:ID"/>
<element name="TestLookupAccount__r" nillable="true" minOccurs="0" type="ens:Account"/>

 It seems Salesforce omit one element if I set same value for "Field Name" and "Child Relationship Name". Can anyone tell me why?  Is it allowed to set the same value for them?

 

Thanks

 

 

Hi,
I am trying to do an update of a Custom Object with java and Apache HttpClient 4 and getting a 400 Bad request error. I tried both _HttpPatch and the method below.Thanks for any help.

 

TIA,

Vijay

 

I blanked out he pod below to xxxxx-

 

URI:https://xxxxxx-salesforce.com/services/data/v20.0/sobjects/DeviceIdentifyingInfo__c/a1AK00000004HFaMAM

 status return code is not OK:400:HTTP/1.1 400 Bad Request
 
 Code snippet below:
 
 String url = "https://" + instanceUrl
  + "/services/data/v20.0/sobjects/DeviceIdentifyingInfo__c/"
  + escapedId;
//     + escapedId + "?_HttpMethod=PATCH";
 HttpPost post = new HttpPost(url)
{
 @Override
 public String getMethod() {
  return "PATCH";
 }
};


post.addHeader("Authorization", "OAuth " + sessionId);
HttpParams params = post.getParams();
HttpConnectionParams.setSoTimeout(params, connectionTimeoutInt);

post.setParams(params);
org.json.JSONObject device = new org.json.JSONObject();

try {
 device.put("Id", escapedId);

 device.put("Token__c", escapedToken);
}


StringEntity se = new StringEntity(device.toString());

post.setEntity(se);

post.setHeader("Content-type", "application/json");

// httpclient.executeMethod(get);
HttpResponse httpResponse = httpclient.execute(post);

if (httpResponse.getStatusLine() != null
&& httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {


} else {
//error 400<====
}

  • August 04, 2011
  • Like
  • 0

I'm trying to use the Bulk API to execute a query and get ~230,000 records back. But when I execute the query, instead I get a cryptic id number and no records at all. Can anyone help?

I'm using both the Force.com Toolkit for PHP and the PHP Bulk API found here: http://wiki.developerforce.com/index.php/Web_Services_API#PHP

In short, here's what I'm doing:

// connect to Salesforce using Force.com Toolkit for PHP
$sf = new SforceEnterpriseClient();
$sf->createConnection("enterprise.wsdl.xml");
$login = $sf->login($username, $password.$security_token);

// initialize the PHP Bulk API
$sfbulk = new BulkApiClient($login->serverUrl, $login->sessionId);
$sfbulk->setCompressionEnabled(true);

// create a Bulk API job
$job = new JobInfo();
$job->setObject('Contact');
$job->setOpertion('query');
$job->setContentType('CSV');
$job->setConcurrencyMode('Parallel');
$job = $sfbulk->createJob($job);

// add the batch and close the job
$batch = $sfbulk->createBatch($job, "SELECT Id, FirstName FROM Contact LIMIT 10");
$sfbulk->updateJobState($job->getId(), "Closed");

// monitor the batch status until it's done
while($batch->getState() == "Queued" || $batch->getState() == "InProgress") {
    sleep(5);
    $batch = $sfbulk->getBatchInfo($job->getId(), $batch->getId());
}
if($batch->getState() == "Failed") {
    echo("Batch failed!");
    exit();
}

// get the results
$results = $sfbulk->getBatchResults($job->getId(), $batch->getId());
echo("Batch complete! Results: ".json_encode($results));

And the results I'm getting from running this script are:

Batch complete! Results: <result-list xmlns="http://www.force.com/2009/06/asyncapi/dataload"><result>752A0000000GnBh</result></result-list>

I have tried several different queries. Some of the batches that have more complicated joins had a "Failed" status, but this is a really simple query, and I should be getting 10 contacts back. Instead I'm getting "752A0000000GnBh" with no indication of what this is an id for.

When I do the same thing except all with the Force.com Toolkit for PHP it works fine and I get the 10 results I'm looking for. The problem is when I want to select all of the records in the Contact table I run into the API request limit very quickly and can only process about 20,000 records in a single day. It seems like using the Bulk API would fix this (I don't have to constantly make queryMore() requests), but it doesn't appear to be working.

I googled around for a solution and found this blog post: http://blogs.developerforce.com/engineering/2011/03/bulk-api-queries.html

It says the query command in the Bulk API is a pilot feature and "Since this feature is still in pilot, first you will need to contact your Salesforce representative to have it enabled for your organization." I have called custoimer service and they assured me that my Salesforce account does have this enabled. Which would make sense, because it never gave me an error message.

Am I just using the Bulk API wrong? If so, how can I use it to get records from a query? If not, is the Bulk API broken?

  • August 02, 2011
  • Like
  • 0

Hi, i have created a custom field in the opportunity entity, the field's type is multipicklist and i want to update it (in some cases) with no values (clear the list).

I am able to update it when there are values to put in, but when i try to update with an empty string the old values persist and nothing is updated.

Example:

...
key = "custom_field";
value = ...
MessageElement messageElement = new MessageElement(key, value);
opp[0] = new SObject();
opp[0].setType("Opportunity");
opp[0].set_any(messageElements);
...
SaveResult[] sr = binding.update(opp);

when value is something like "first;second;third" (values separated by semicolons) it works fine, but when value is an empty string (value = "";) it does not work.

Am i missing something ? is there any restriction ?
What is the way to clear a multipicklist of an object ?

Any help will be appreciated


I get the error [INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session] when i try ro call a Apex Web Service as following with JAVA.

 

ConnectorConfig config = new ConnectorConfig();
config.setUsername(userId);
config.setPassword(passwd);   
SoapConnection connection = Connector.newConnection(config);

connection.MyWebServiceMethod();

 

This method works fine for Enterprise WSDL

 

 

  • July 21, 2011
  • Like
  • 0

Hi,

 

How do I return a picklist of values from an Entity via REST API call?

 

Here is how I do this in Apex code:

 

Caller code:

 

xxxxHelper.getSelectOptions(Account.Question1__pc.getDescribe());


Called code:

 

public static List<SelectOption> getSelectOptions(Schema.DescribeFieldResult fieldResult) {

List<SelectOption> options = new List<SelectOption>();

for (Schema.PickListEntry ple : fieldResult.getPickListValues()) {

options.add(new SelectOption(ple.getLabel(), ple.getValue()));

}

return options;

}

 

 

I do see an equivalent  /Account/describe but I am not sure how to map it into the call above to get the PickList values ?

 

TIA,

Vijay

  • June 22, 2011
  • Like
  • 0

Hello,

 

I have created a REST controller

@RestResource(urlMapping='/DealController/*')
global class DealRestResource {
...
}

 

When I call itas following, 

 

curl -k -H "Authorization: OAuth 00D50000000Isbl!ARYAQPcQ3MM9F1VigkIS6HJ_6MMP2lboHGgqljtuj.Eo2WlDELUzjIZwMySlcQK7Lsk0d_" -d @acc.json "https://na3.salesforce.com/services/apexrest/DealController/"

 

I get an error "[{"message":"Could not find a match for URL /DealController/","errorCode":"NOT_F
OUND"}]"

 

Also what would be the URL if I have to call it from Apex page itself.

 

Thanks,

Kam

Hi

 

I'm working on an application for our company that will rely on this pilot feature:

http://blog.sforce.com/sforce/2011/05/apex-rest-services-in-summer-11.html

 

I'm just wondering when will this cease to be a pilot, and if there are any implications for deploying an application based on this feature? E.g. it currently only allows for a restricted set of parameters- will this be expanded post-pilot?

 

Thanks.

Hello,

 

To parse and construct json within the server side REST controllers, are there any json utility classes? Something like flex json in Java world..

 

Thanks,

Kam

Hello,

 

Let's say we retrieve a specific account using

/services/data/v22.0/sobjects/Account/0015000000afWuJAAU

 

How to retrieve child records for this specific account? One entity can have 0..multiple child relationships.

e.g.something like following should retrieve Contacts or Cases for the account record...

/services/data/v22.0/sobjects/Account/0015000000afWuJAAU/Contacts
/services/data/v22.0/sobjects/Account/0015000000afWuJAAU/Cases

 

I am sure this is a dumb question but could not find the answer in the docs. Also using REST explorer but can not figure out how to get child records?

 

Please help.

 

Thanks,

Kam

 

Hello everyone

 

I have a follow up issue for my previous problem (http://boards.developerforce.com/t5/REST-API-Integration/Updating-records-from-REST-API/m-p/291815#M585).

 

I have this code from my JAVA application running on Google app engine:

 

 

HTTPRequest httpRequest = new HTTPRequest(url, HTTPMethod.POST, FetchOptions.Builder.withDeadline(10));

...

JSONObject update = new JSONObject();
update.put("my_txt", mTxt);			
			httpRequest.setPayload(update.toString().getBytes());

log.severe("payload: " + update.toString());		
			
HTTPResponse response = urlFetchService.fetch(httpRequest);

 

 

When I print out the text before sending it I see the spaces, new lines and format are kept and appear OK.

 

But when I look in my Force.com Org in the relevant Rich Text field I see on long line of text (with not spaces, new lines or any formatting).

 

Any advice on why is that happening and what am I doing wrong?

 

Thanks

 

Oded

 

I'm new to Apex development and ran into the following issue I can't decipher when making a simple web service call from the Force IDE.

 

I generated the Apex class from the WSDL for my client's service and used that to make the web service call. The call succeeds in getting a response from the web service; I can see the expected data in the Execute Anonymous results window. But it eventually throws the following exception:

 

09:06:22.193|FATAL_ERROR|System.CalloutException: Web service callout failed: Unable to parse callout response. Apex type not found for element http://www.w3.org/2001/XMLSchema=schema

 

Any help would be greatly appreciated.

All the examples of using the Bulk API show how to insert records (including the sample code). This works perfectly but we're also interested in using the API to delete all records of a particular type - basically we have a need to delete and recreate some reference data on a daily or weekly basis.

 

 

  • Do you need to provide a CSV file if you want to delete all records?
  • If you do, what format should the CSV be in (just the Id needed) and any hints on how to get the Ids of 100,000 records without hitting limits?
Thanks in advance for any help!

 

I'm using Apigee to return the records from OpportunityLineItem object.  But the Rest API doesn't return any records.  

So the following URL just describes the table with empty list

services/data/v20.0/sobjects/OpportunityLineItem

 

The following URL returns all the records

 

services/data/v20.0/query/?q=select+description+from+OpportunityLineItem

 

 

The question is, why is that the first URL not returning any records?

 

Thanks!

All,

I am using the Bulk Data Api to upsert a large number of records.  If one of those records fails I would not like the successful changes commited.  Is there a way to achieve this.  On the BulkConnection I see there is an abortJob method.  If I abort a job after it has already run through a few batchs will be undo the changes that have already been made?  Is there any easier way to do this?  Thanks in advance for any help. 

Anyone knows what is the default isolation level and if it is possible to change that? I have a use case as follows: I want to insert a record in an object if it does not exist, otherwise just update it. So I am doing a select (where say name = <some value>), if no record is returned, I create a new one, otherwise I update the existing one. But it appears that if two such calls are executed at the same time, I would end up creating two records (with same name). Anyone knows how to solve this problem?

  • November 21, 2011
  • Like
  • 0

Hi,

 I am facing problem with the integration of java with salesforce.

 

I have created a webservice class and generated wsdl for the same.When i am trying to call the webservice method in java it is showing the invalid session ID error.

 

CODE:

       HelloWebServiceLocator serLocator = new HelloWebServiceLocator ();

        PartnerConnection connection = null;
        ConnectorConfig partnerConfig  = new ConnectorConfig();
        partnerConfig .setUsername("*********************");
        partnerConfig .setPassword("************************");
        connection = Connector.newConnection(partnerConfig );

        serLocator.HelloWeb().sayHello();    //HelloWeb is the Apex Class & sayHello is the method

 

Here I am not passing sessionId.serLocator is not showing any default methods to set sessionID. How can I set session ID to the serLocator object? Can anyone provide me the sample code for this one?

 

  • October 24, 2011
  • Like
  • 0

Hi all,

 

I have been tasked with finding out if the wsc-22.jar and the generated partner.jar are thread-safe.

We are building an application in Java that will be having multiple threads accessing the partner connection variable and sending queries/updates/creates to SalesForce.

I have found the documentation on the limits, so the limits of 10 query cursors and for concurrent requests (calls) with a duration of 20 seconds or longer:

However nothing really on if the code is thread-safe.

 

Any help in finding an answer to this would be greatly appreciated.

 

Regards,

 

Adrian

we have a method calling an external webservice passing account and contact information. The call was working and then the user turned on Person Accounts and it is no longer working.

 

Any suggestions, greatly appreciated.

  • October 20, 2011
  • Like
  • 0

I am using Perl with Light Soap to select data from various SFDC objects such as opportunity and Quote. When executing the following statement: SELECT Id, Name from Opportunity LIMIT 10 I have no issues, hoaever if I change the table name from Opportunity to Quote: SELECT Id, Name from Quote LIMIT 10 I am getting the following error message: INVALID_TYPE: sObject type 'Quote' is not supported.<br>2. SELECT Id, Name from Quote LIMIT 10. Does anybody have a clue?

Hi,

I am right now working on prerelna1.pre.salesforce.com to evaluate REST API. I am at a point where I am trying to create a managed package (which includes these rest classes).

When I click on upload, I get the following error message "Packages containing Apex REST classes cannot be uploaded."

 

Does these mean that ISVs cannot create apps using REST?

 

Best Regards, Indresh

I am quite stuck after trying every trick I can find in the book, having done plenty of research into the classic "Too many SOQL queries" error.

 

I have, for example, made sure that there is no SELECT statement or UPDATE within a FOR loop (which seem to be the most common mistakes).

 

And yet still the error occurs!

 

Here is the error:

System.LimitException: Too many SOQL queries: 101

Class.RecordUpdate.updateInvoices: line 54, column 9 Trigger.DepartmentTrigger1: line 66, column 5

 Here is the Trigger that is causing the problem:

trigger DepartmentTrigger1 on Account (after update) {

  Set<Id> accountIds = new Set<Id>();


for (Integer i = 0; i < Trigger.new.size(); i++){
    if (
    //Changing btw two Parent Companies
        (Trigger.new[i].Parent_Company__c != Trigger.old[i].Parent_Company__c && 
        Trigger.new[i].Department__c == TRUE && Trigger.old[i].Department__c == TRUE)||
    //Changing to a Department
        (Trigger.new[i].Department__c == true && Trigger.old[i].Department__c == false)||
    // Changing from a Department
        (Trigger.new[i].Department__c == FALSE && Trigger.old[i].Department__c == TRUE)
        ) {
        accountIds.add(Trigger.new[i].Id);
    }
}
  
    //Update Contacts
    RecordUpdate.updateContacts(accountIds);
    
    //Update Deals
    RecordUpdate.updateDeals(accountIds);    

    //Update Sales Invoices
    RecordUpdate.updateInvoices(accountIds);
    
}

 And here is the Class that is referenced above:

public with sharing class RecordUpdate {

public static void updateContacts(Set<Id> contactset){
    Contact[] relatedContacts =
        [SELECT f.id, f.Accountid, f.Account.Department__c, f.Account.Parent_Company__c, f.Parent_Company__c
        FROM Contact f
        WHERE f.Accountid IN :contactset];

    for ( Contact childc : relatedContacts ) {
        if (childc.Account.Department__c == TRUE) {
            childc.Parent_Company__c = childc.Account.Parent_Company__c;
        }
        else
            childc.Parent_Company__c = childc.AccountId;
    }
    update relatedContacts;
}


public static void updateDeals(Set<Id> dealset){
    List<Opportunity> relatedDeals =
        [SELECT g.id, g.Accountid, g.Account.RecordTypeId, g.Account.Department__c, g.Account.Parent_Company__c, 
        g.Parent_Company__c, g.Agency_Client__r.id , g.Agency_Client__r.Department__c, g.Agency_Client__r.Parent_Company__c
        FROM Opportunity g
        WHERE g.Accountid IN :dealset OR g.Agency_Client__r.id IN :dealset];
    
    for ( Opportunity childo : relatedDeals ) {
        if (childo.Account.Department__c == TRUE) {
            childo.Parent_Company__c = childo.Account.Parent_Company__c;
        }
        else if (childo.Account.RecordTypeId == '01220000000Dqq6'){
            if (childo.Agency_Client__r.Department__c == TRUE){
                childo.Parent_Company__c = childo.Agency_Client__r.Parent_Company__c;
            }
            else
                childo.Parent_Company__c = childo.Agency_Client__c;
        }
        else
            childo.Parent_Company__c = childo.AccountId;
    }
    update relatedDeals;
}


public static void updateInvoices(Set<Id> invoiceset){
    Sales_Invoices__c[] relatedInvoices =
        [SELECT s.Id, s.Company__c, s.Company__r.Parent_Company__c, s.Company__r.Department__c, s.Parent_Company__c, s.Agency_Client__r.Id
        FROM Sales_Invoices__c s
        WHERE s.Company__c IN :invoiceset OR s.Agency_Client__c IN :invoiceset
        FOR UPDATE];
    
    for ( Sales_Invoices__c childs : relatedInvoices ) {
        if (childs.Company__r.Department__c == TRUE) {
            childs.Parent_Company__c = childs.Company__r.Parent_Company__c;
        }
        else
            childs.Parent_Company__c = childs.Company__c;
    }
    update relatedInvoices;
}

}

 

 There are a few other triggers that are involved, but they are tiny in comparison to the above example.

 

Thanks for any help you can offer.

HI everyone!

 

Integrated our system with SF and it works like a charm (with the development account)

 

Does anyone know if the Rest API is disabled for SF Enterprise Trial accounts?

 

Getting a "REST API is not enabled for this Organization" message when I call the API.

Don't know if missed something or if it just don't work with trials...

 

Thanks!



  • October 11, 2011
  • Like
  • 0

I'm using C# and SF REST API. I have no problems so far get-ing and inserting some custom data from SF (Accounts,etc..). But now a have to insert PDF attachment using REST API, and i'm stuck. I's  it even possible? And if it is how? Any help will be appreciated.

Using this guide as a reference, I've created a Remote Access application entry in my developer account.

I'd like to play around with the Authorization screen that the user should see after navigating to this URL:

 

https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=<your_client_id>&redirect_uri=<your_redirect_uri>

 

When I fill in the right values and navigate to the URL, I am not taken to the screen that I expect to see here, but rather the regular Salesforce login screen.  What am I getting wrong?  Thanks.

I have an old application that uses Web-To-Lead. I'm updating it to use the REST API. We have a bunch of assignment rules set up for Leads. When we create a lead through Web-To-Lead, the Lead is assigned according to our assignment rules. However, when we create a Lead through the REST API, the assignment rules are completely ignored, and the Lead is assigned to the account whose credentials we used to authenticate through OAuth. This has slowed our sales team to a crawl, because now they have to assign leads by hand.

 

Any ideas how to fix this?