Angelo Santagata's Blog

Inserting a interaction into Sales Cloud using Java

Angelo Santagata

Hey all,

Quick snippet of code showing how to create an interaction for an opportunity using Java.

This is only a snippet, I assume/note :

  • You've already created a Web-service proxy for the Interaction Service  (ie http://host/appCmmnCompInteractions/InteractionService) and added it to the project dependencie
  • You've tested a simple getInteraction() works fine
  • If you run standalone Java client, then make sure you import the Sales Cloud certificates into your keystore
  • If you run this as within Weblogic Server then the step of importing the Sales Cloud certificates isn't require
  • Tested and works on Sales Cloud R7
  • XML Payload is shown at the end
  • This is sample code


package oracle.fusion.pts.samples.clients;
import com.oracle.xmlns.apps.crmcommon.interactions.interactionservice.Interaction;
import com.oracle.xmlns.apps.crmcommon.interactions.interactionservice.InteractionAssociation;
import com.oracle.xmlns.apps.crmcommon.interactions.interactionservice.InteractionParticipant;
import com.oracle.xmlns.apps.crmcommon.interactions.interactionservice.ObjectFactory;
import com.sun.xml.ws.api.addressing.AddressingVersion;
import com.sun.xml.ws.developer.WSBindingProvider;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Map;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.ws.WebServiceRef;
import oracle.pts.fusion.samples.interaction.InteractionService;
import oracle.pts.fusion.samples.interaction.InteractionService_Service;
import oracle.pts.fusion.samples.interaction.ServiceException;
import weblogic.wsee.jws.jaxws.owsm.SecurityPolicyFeature;
public class createInteraction {
//Define the security policy
private static final SecurityPolicyFeature[] securityFeature =
new SecurityPolicyFeature[] { new SecurityPolicyFeature("oracle/wss_username_token_over_ssl_client_policy") };
private static final AddressingVersion WS_ADDR_VER = AddressingVersion.W3C;
public static void main(String[] args) {
// Default Values
String username = "matt.hooper";
String password = "somepassword";
String url="https://yourhost:443/appCmmnCompInteractions/InteractionService";
// Sample data, in a real system these would be either parameters to the function or queried as part of the code
Long participantPartyId = new Long("100000000099058");
String opportunityId="300000000667205";
Long customerId= new Long("300000000592745");
// Setup the webservice interface
InteractionService_Service interactionService_Service = new InteractionService_Service();
InteractionService interactionService = interactionService_Service.getInteractionServiceSoapHttpPort(securityFeature);
// Get the request context to set the outgoing addressing properties
WSBindingProvider wsbp = (WSBindingProvider)interactionService;
Map<String, Object> requestContext = wsbp.getRequestContext();
requestContext.put(WSBindingProvider.USERNAME_PROPERTY, username);
requestContext.put(WSBindingProvider.PASSWORD_PROPERTY, password);
requestContext.put(WSBindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
System.out.println("Example of creating an interaction on a opportunity");
// Create Payload
ObjectFactory factory = new ObjectFactory();
Interaction newInteraction=factory.createInteraction();
// Create XMLGregorianCalendar Object with todays date/time
DatatypeFactory dtf=null;
Date today= new Date();
try {
dtf = DatatypeFactory.newInstance();
} catch (DatatypeConfigurationException e) {
e.printStackTrace(); // Duh error
GregorianCalendar gc=new GregorianCalendar();
// Set Date
newInteraction.setCustomerId(customerId); // CustomerId can be obtained from TargetPartyId from the opportunity
newInteraction.setInteractionDescription(factory.createInteractionInteractionDescription("Angelos Test Interaction "+today.toString()));
newInteraction.setOutcomeCode(factory.createInteractionOutcomeCode("SUCCESSFUL")); // Configured in Setup/maintenance
newInteraction.setInteractionTypeCode("EMAIL"); // Custom types can be configured
newInteraction.setDirectionCode("INBOUND"); // INBOUND or OUTBOUND
newInteraction.setMediaItemId(0L); // Default =0
newInteraction.setMediaTypeCode(factory.createInteractionMediaTypeCode(""));// Leave Empty
// Create & Add Participant, can be RESOURCE and/or CONTACT
InteractionParticipant participant= factory.createInteractionParticipant();
// Create & Add Association, this links it back to Opportunity
InteractionAssociation association = factory.createInteractionAssociation();
// Do the insert
Interaction result=null;
try {
result = interactionService.createInteraction(newInteraction);
} catch (ServiceException e) {
System.out.println("end - interaction "+result.getInteractionId()+" created");


 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://xmlns.oracle.com/apps/crmCommon/interactions/interactionService/types/" xmlns:int="http://xmlns.oracle.com/apps/crmCommon/interactions/interactionService/">
<int:InteractionEndDate xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<!-- CustomerID= SalesParty Customer, also known as TargetPartyId in Opportunity -->
<int:InteractionDescription>CTI Detected customer callback </int:InteractionDescription>
<!-- InteractionTypeCode is part of the standard Lookup types -->
<int:MediaTypeCode xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<!-- ParticipantId is partyID for contact -->
<!-- AssociatedObjectUid is OPPORTUNITY you want to assocaite this with -->

Join the discussion

Comments ( 7 )
  • Govindh Tuesday, October 28, 2014

    Hi ,

    I have consumed OSC PersonService wsdl using java code. I want get custom field values from Person object . If i create object person we can get only standard field values. But i couldn't see the custom field option to get. Can you share me the code for getting custom filed. below my Wsdl url and sample code

    URL : https://caep-test.crm.em2.oraclecloud.com/foundationParties/PersonService?WSDL

    Person per = getPerson(pid);



    these are the custom fields in my person details. I get the out put in soapui but i dont know how to get using java.



  • angelo Thursday, November 20, 2014

    Have you regenerated your soap proxy AFTER publishing the changes in salescloud??

    if you do then accessing your custom fields should be as easy as accessing the standard fields

  • Govindh Thursday, November 20, 2014

    Hi Angalo,

    Thank so much. I have regenerated my webservice once again and i got all the custom field variables in my code.



  • shivaji Lohar Monday, April 20, 2015


    Creating Opportunity into Sales Cloud using Java.

    Can you please suggest me how to create Opportunity using Java?


    Shivaji Lohar


  • guest Monday, April 20, 2015

    Ive added an example for you

  • shivaji Lohar Tuesday, April 21, 2015

    Hi angelo,

    I am not able the see the code here.

    can you please look into this?


    Shivaji Lohar

  • angelo Tuesday, April 21, 2015

    The example is in a new blog posting @ blogs.oracle.com/angelo

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.