• Mario V
  • NEWBIE
  • 10 Points
  • Member since 2006

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 6
    Replies

I am stuck on this. I am getting the "You have uncommitted work pending. Please commit or rollback before calling out" CalloutException, even though I am doing the operations in the right order as I understand it.

The batch job has to select accounts that need updating, call a webservice to query some data, and update the accounts with this new information.

Below is a simplified version of my code. Basically:

- In the start() method I run a query on Account and return a QueryLocator
- In the execute() method I loop through the List<Account>,  do as many callouts as needed and set the relevant fields in the Account objects; at the end of the loop I do one update operation.

This should preserve the rule "no not do callouts after DML operations". But the second callout after I first set the fields is failing. It seems though setting field values on the object counts as DML, even though I am not performing the update operation yet.

Does that make sense? How can it be fixed? Or is it a whole different thing that I am doing wrong?

Thanks in advance.

 

global class AccountsUpdateWebService implements Database.Batchable<sObject>, Database.AllowsCallouts, Database.Stateful {
    global Database.QueryLocator start(Database.BatchableContext bc){
        String query = 'Select Id, Name FROM Account ...';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext bc, list<Account> accounts) {
        List<Account> toupdate = new List<Account>();
        for (Account account: accounts) {
            // Callout to web service that retrieves address info
            WSData wsdata = WebService.getData (account.Name);
            account.BillingStreet = wsdata.Street;
            account.BillingPostalCode = wsdata.PostalCode;

            toupdate.add (accounts);
        }
        update toupdate;
    }

    global void finish(Database.BatchableContext bc) {
    }
}

Hi everyone. Our customer has a somewhat complicated price structure; I would like to show some extra pricing information in the multi-line add product screen, so that the salespeople know the pricing for different quantities of products at the moment of first entering the quantity.

 

My first idea was a "before insert" Apex trigger that fills a read-only field with the possible prices for a given client and product, and add this field to the screen - but it turns out when the user reaches that screen, the line items have not been inserted yet, so the tigger does not fire and the field stays empty.

 

Next I tried a simple formula field, maybe to show a field from the PricebookEntry object - but apparently you cannot add formula fields to the multiline layout. No custom buttons and links either.

 

My first question is: is there a really simple way to achieve what I want, that I am missing?

 

I searched around the web a bit, and it seems the only solution for similar cases is to use a custom Visualforce page; but it is not possible to override just the "multiline layout" step of the process. I would have to override the Add Products button from the Opportunity Products list view, and that would force me to replicate in Visualforce the full Add Products process, including the search and select product functionality from the previous step.

 

I am new to Visualforce and this seems like a bit of a big thing to start with, so my second question is: can I find somewhere a specific example of  replicating the Product Selection screen in Visualforce?

 

Thanks in advance. 

Hi everyone. We are trying to integrate Salesforce with our client's Intranet. The Intranet is developed in PHP. We are using PHP 4.3.11, PEAR SOAP 0.9.1 and a custom class very similar to the one in the PHP sample code from http://www.sforce.com/resources/toolkits-samples.jsp#PHP

We have created a custom link from Salesforce to the Intranet passing the session ID and server endpoint. The intranet uses this to get the user data, authenticate the user against its local database (or insert it if it is not present), and interact with Salesforce to retrieve and update data.

If we create the link in our Developer Edition account, pointing to either our development server or our client's production server, this works perfectly (the endpoint passed from Developer Edition is https://na1.salesforce.com/services/Soap/u/6.0 ).

f we create the link in the customer's live Salesforce environment, pointing to our development server, this works perfectly (the endpoint passed from Salesforce is https://emea.salesforce.com/services/Soap/c/6.0 ).

If we create the link in the customer's live Salesforce environment, pointing to our client's production server, any call to the SForce web service returns the message INVALID_SESSION_ID: Invalid Session ID found in SessionHeader

This is the SOAP request and response involved.

Request:

<?xml encoding="UTF-8" version="1.0"?>

<SOAP-ENV:Envelope  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:xsd="http://www.w3.org/2001/XMLSchema"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"  xmlns:ns4="urn:partner.soap.sforce.com" >

<SOAP-ENV:Header>
<ns4:SessionHeader SOAP-ENV:actor="http://schemas.xmlsoap.org/soap/actor/next" SOAP-ENV:mustUnderstand="0"><ns4:sessionId>*</ns4:sessionId></ns4:SessionHeader>
</SOAP-ENV:Header>

 <SOAP-ENV:Body>
<ns4:getUserInfo>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Response:

HTTP/1.0 500 Internal Server Error
Server: sfdc
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Date: Wed, 04 Jan 2006 10:36:11 GMT

<?xml encoding="UTF-8" version="1.0"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>  
<soapenv:Fault>  
  <faultcode xmlns:ns1="urn:fault.enterprise.soap.sforce.com">ns1:INVALID_SESSION_ID</faultcode> 
  <faultstring>INVALID_SESSION_ID: Invalid Session ID found in SessionHeader</faultstring>
   <detail>
    <sf:fault xsi:type="sf:UnexpectedErrorFault" xmlns:sf="urn:fault.enterprise.soap.sforce.com">
     <sf:exceptionCode>INVALID_SESSION_ID</sf:exceptionCode>
     <sf:exceptionMessage>Invalid Session ID found in SessionHeader</sf:exceptionMessage>
    </sf:fault>
   </detail>
  </soapenv:Fault>
 </soapenv:Body>
</soapenv:Envelope>

I have deleted the session ID from the SOAP request for security purposes, but as far as I can tell it is being passed correctly - using it from the development server or my local machine does work. I have checked and the SOAP requests being sent from the development and the production server are identical.

Since it works in the development server, I do not think there is any serious problem with the code; and since it works in the production server when connecting to Developer Edition, there should not be any glaring server configuration errors either. We are completely out of ideas about this. Does anyone know what we may be doing wrong?

Message Edited by Mario V on 01-04-2006 04:18 AM

Message Edited by Mario V on 01-04-2006 04:21 AM

I am stuck on this. I am getting the "You have uncommitted work pending. Please commit or rollback before calling out" CalloutException, even though I am doing the operations in the right order as I understand it.

The batch job has to select accounts that need updating, call a webservice to query some data, and update the accounts with this new information.

Below is a simplified version of my code. Basically:

- In the start() method I run a query on Account and return a QueryLocator
- In the execute() method I loop through the List<Account>,  do as many callouts as needed and set the relevant fields in the Account objects; at the end of the loop I do one update operation.

This should preserve the rule "no not do callouts after DML operations". But the second callout after I first set the fields is failing. It seems though setting field values on the object counts as DML, even though I am not performing the update operation yet.

Does that make sense? How can it be fixed? Or is it a whole different thing that I am doing wrong?

Thanks in advance.

 

global class AccountsUpdateWebService implements Database.Batchable<sObject>, Database.AllowsCallouts, Database.Stateful {
    global Database.QueryLocator start(Database.BatchableContext bc){
        String query = 'Select Id, Name FROM Account ...';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext bc, list<Account> accounts) {
        List<Account> toupdate = new List<Account>();
        for (Account account: accounts) {
            // Callout to web service that retrieves address info
            WSData wsdata = WebService.getData (account.Name);
            account.BillingStreet = wsdata.Street;
            account.BillingPostalCode = wsdata.PostalCode;

            toupdate.add (accounts);
        }
        update toupdate;
    }

    global void finish(Database.BatchableContext bc) {
    }
}

Hello,

 

I am aware of the Apex Trigger in Sales Force, but Is there anyway to make Insert/Update from Sales force to MS Sql Server? If I create Web Service, then it needs to be called from externally.

 

Assume I have this scenario. If someone creates account in Sales Force, it should trigger an event and send this Account Information to MS Sql Server DB of our organization. Once its inserted in our Sql DB, it will create particular AccountID and give it back to Sales Force. The reason I need to accomplice this is our Account creation process used to start from Our own website so it was creating AccountID (Auto Generated) from DB and used from Primary identification for Account across system. Now we want to create Account from Sales Force but need to keeep AccountId generated from DB only.

 

How can I accomplice this?

Hi,

I'm still using the PEAR SOAP libraries and never had problems creating SObjects like tasks. But now we moved to a new ISP and after all create calls the XML response seems to be invalid an I get the following error message:

XML error on line 1 col 4 byte 4 not well-formed (invalid token)

When I print out the resulting error object it shows that the sObject was created but the positive xml response seems to cause the mentioned error.

I already tried to set the default character set to utf-8 using PHP's ini_set and Apache's .htaccess directives but that didn't change anything.

Since this is a massive problem for a customer of ours any help is greatly appreciated!

Thanks,

Henry

Hi everyone. We are trying to integrate Salesforce with our client's Intranet. The Intranet is developed in PHP. We are using PHP 4.3.11, PEAR SOAP 0.9.1 and a custom class very similar to the one in the PHP sample code from http://www.sforce.com/resources/toolkits-samples.jsp#PHP

We have created a custom link from Salesforce to the Intranet passing the session ID and server endpoint. The intranet uses this to get the user data, authenticate the user against its local database (or insert it if it is not present), and interact with Salesforce to retrieve and update data.

If we create the link in our Developer Edition account, pointing to either our development server or our client's production server, this works perfectly (the endpoint passed from Developer Edition is https://na1.salesforce.com/services/Soap/u/6.0 ).

f we create the link in the customer's live Salesforce environment, pointing to our development server, this works perfectly (the endpoint passed from Salesforce is https://emea.salesforce.com/services/Soap/c/6.0 ).

If we create the link in the customer's live Salesforce environment, pointing to our client's production server, any call to the SForce web service returns the message INVALID_SESSION_ID: Invalid Session ID found in SessionHeader

This is the SOAP request and response involved.

Request:

<?xml encoding="UTF-8" version="1.0"?>

<SOAP-ENV:Envelope  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:xsd="http://www.w3.org/2001/XMLSchema"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"  xmlns:ns4="urn:partner.soap.sforce.com" >

<SOAP-ENV:Header>
<ns4:SessionHeader SOAP-ENV:actor="http://schemas.xmlsoap.org/soap/actor/next" SOAP-ENV:mustUnderstand="0"><ns4:sessionId>*</ns4:sessionId></ns4:SessionHeader>
</SOAP-ENV:Header>

 <SOAP-ENV:Body>
<ns4:getUserInfo>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Response:

HTTP/1.0 500 Internal Server Error
Server: sfdc
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Date: Wed, 04 Jan 2006 10:36:11 GMT

<?xml encoding="UTF-8" version="1.0"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>  
<soapenv:Fault>  
  <faultcode xmlns:ns1="urn:fault.enterprise.soap.sforce.com">ns1:INVALID_SESSION_ID</faultcode> 
  <faultstring>INVALID_SESSION_ID: Invalid Session ID found in SessionHeader</faultstring>
   <detail>
    <sf:fault xsi:type="sf:UnexpectedErrorFault" xmlns:sf="urn:fault.enterprise.soap.sforce.com">
     <sf:exceptionCode>INVALID_SESSION_ID</sf:exceptionCode>
     <sf:exceptionMessage>Invalid Session ID found in SessionHeader</sf:exceptionMessage>
    </sf:fault>
   </detail>
  </soapenv:Fault>
 </soapenv:Body>
</soapenv:Envelope>

I have deleted the session ID from the SOAP request for security purposes, but as far as I can tell it is being passed correctly - using it from the development server or my local machine does work. I have checked and the SOAP requests being sent from the development and the production server are identical.

Since it works in the development server, I do not think there is any serious problem with the code; and since it works in the production server when connecting to Developer Edition, there should not be any glaring server configuration errors either. We are completely out of ideas about this. Does anyone know what we may be doing wrong?

Message Edited by Mario V on 01-04-2006 04:18 AM

Message Edited by Mario V on 01-04-2006 04:21 AM