0

Here's my tricky question

  1. In my project some integration activity is going on where integration takes place between java and salesforce. Records of a custom object are sending from Java to salesforce, they are performing only insert operation from their side. So I have to handle the data for updating records, for this I wrote a trigger. Trigger is working fine as per the business requirement and have tested it in salesforce. But the issue is it's not handling the data as expected while sending records from java to salesforce. It's creating new records in salesforce instead of updating the existing records.

  2. There is now SOAP or REST code from salesforce, we just handed over the endpoint URL and some other needful things. Can you guys please suggest me from where the issue is occuring from?.

closed as off-topic by Eric, Brian Mansfield, Adrian Larson, Boris Bachovski, Ratan Paul Dec 19 '15 at 10:01

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on problems in code you've written must describe the specific problem and include valid code to reproduce it. For help writing short, self-contained syntactically-valid examples, see: SSCCE.org" – Eric, Brian Mansfield, Adrian Larson, Boris Bachovski, Ratan Paul
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    more info is required here.. how exactly (specific API used) is the Java code using; what trigger context is invoked? what does the trigger look like? – cropredy Dec 18 '15 at 18:24
  • Java guys using SOAP to send data from java to salesforce. I'm inovking after insert context. It will handle incoming records and can perform insert or update, I've tested the trigger by performing sample insert/update operations. I'm sure no issue from the trigger. – Laxman Dec 18 '15 at 18:40
  • 1
    If the Java side is using the standard SFDC SOAP create() call, then SFDC will insert the record regardless of whether you have a trigger or not unless your trigger does an addError – cropredy Dec 18 '15 at 19:13
  • Laxman, what records are you trying to update? It seems to me like you're trying to update records in an "after insert" trigger. I am confused. Can you provide some sample code? – Sebastian Kessel Dec 18 '15 at 22:11
1

You will not be able to solve this problem with your current approach.

If the Java app is calling the create() method in the Salesforce SOAP API and creating records, that is the only action which will take place. You cannot convert the behavior from an insert to an update action within the trigger.

You also cannot prevent the inserting of records which are in the trigger (generally performed by using .addError() on the records in the trigger collection) without also preventing the other operations which you are trying to perform in the transaction.

Two solutions:

  1. Change Java app to use update() where it is appropriate to do so
  2. Change Java app to use upsert() - not create() or update()

The Salesforce docs on the upsert call include Java examples and a description of how Salesforce chooses to perform an insert or an update on the incoming record(s).

-1

From Java I believe you are using either rest or soap to communicate with salesforce. Use below approach if it is helpful

  1. Change endpoint in java to point to requestbin or mockable.io to know exactly how the payload is formed.

  2. Verify your salesforce service from soapui or post man.

Compare the requests from requestbin and soapui you will find the missing piece.

Not the answer you're looking for? Browse other questions tagged or ask your own question.