Class is called from the trigger in response to update of an opportunity object

I am syncing data between two Saleforce Orgs.From the opportunity object I have been able to uspsert data in another org which in turn returns an inserted id which I will be storing in my org as an external id.

Now Upsertion is happening and I am trying to store the returned id but I am stuck

Below I have class which is connecting to another salesoforce org and then I am calling soap web service.I have my class as well as other web service class is given below.

I have pulled out the original opportunity id after querying and then storing that id in the map.Now I want to store returned id in another list so that I can eventually match the queried id and store the returned id as en externalid.

I am not able to create map to store the returned id or record.

Can somebody please help?

public class inter

    public static void match(list<id>i)
        soapSforceComSchemasClassAccountpla.plan id;
        list<opportunity> opp=[select id,name,closedate,stagename from opportunity where id in:i];

        String username = '[email protected]';
        String password = 'chris123';
        partnerSoapSforceCom.Soap sp = new partnerSoapSforceCom.Soap();
        /* For demonstration purposes only, enter your credentials on the following
           lines, but if you're going to use this a lot or in production, encrypt your    credentials and store them somewhere and then decrypt them here.
        partnerSoapSforceCom.LoginResult loginResult = sp.login(username, password);
        soapSforceComSchemasClassAccountpla.AccountPlan apx=new soapSforceComSchemasClassAccountpla.AccountPlan();
        soapSforceComSchemasClassAccountpla.SessionHeader_element SessionHeader= new soapSforceComSchemasClassAccountpla.SessionHeader_element();
        //soapSforceComSchemasClassGreatone.Greatone apx=new soapSforceComSchemasClassGreatone.Greatone();
        //soapSforceComSchemasClassGreatone.SessionHeader_element SessionHeader=new soapSforceComSchemasClassGreatone.SessionHeader_element();
        //soapSforceComSchemasClassAccountpla.plan p=new soapSforceComSchemasClassAccountpla.plan();
       for(opportunity lap:opp)

           soapSforceComSchemasClassAccountpla.plan p=new soapSforceComSchemasClassAccountpla.plan();
           //plan p=new plan();
           System.debug('The value returned from the the web service is'+id);

       // list<string>orders=new list<string>((string)id);  
       list<opportunity> m=[select id,name,oexternalid__c from opportunity where id in:opp];
       map<id,opportunity>k=new map<id,opportunity>(m);

       for(integer i=0;i<k.size();i++)

global class AccountPlan {

    //Define an object in apex that is exposed in apex web service
    global class Plan {
        webservice String name;
        webservice Integer planNumber;
        webservice Date planningPeriod;
        webservice Id planId;
        Webservice String stagename;

    webservice static Plan createAccountPlan(Plan vPlan) {

        opportunity opp = new opportunity();
        opp.Name = vPlan.name;
        upsert opp oppexternalid__c ;
        return vPlan;
  • 3
    Have you looked into the salesforce-to-salesforce feature ? This is designed to synchronize data between multiple salesforce orgs in one or two directions. Oct 9, 2014 at 9:35

1 Answer 1


I am assuming that you are getting the Id in this line and it is working fine-


Now, since you already have the opportunity you can directly add the returned Id value to oexternalid__c field in the same loop. Then update the list. Here is how it will look

list<opportunity> opp=[select id,name,closedate,stagename, oexternalid__c from opportunity where id in:i]; // line 8
     System.debug('The value returned from the the web service is'+id);

     lap.oexternalid__c = id;

update opp;

Let me know if this works!

  • Hi sai, I am going to try and let u know the outcome.However,your suggestion might work for when single id is returned what will happen when multiple id's are returned that is why I was thinking of using loop and maps.
    – Sales
    Jul 11, 2013 at 21:53
  • hmm....can you think of scenario where multiple Id might be returned? My understanding was that the Id corresponds to an insert operation of the same record in different Org.
    – Sai
    Jul 11, 2013 at 22:01
  • For example you sent list of record ids of couple of closed orders and they were processed and order id's are returned in a list and now you have to pull record from the salesforce org and see which order id should be inserted in which record as external id.
    – Sales
    Jul 12, 2013 at 18:39
  • What u have suggested is not going to work as id has soapSforceComSchemasClassAccountpla.plan as return type whereas the other object has opportunity as datatpe.No type of conversion is going to work from soapSforceComSchemasClassAccountpla.plan to string or to Sobject and then try to insert/update as they are not related to each other in any way.Basically I need some kind of connection between the id's datatype and the other class datatype so that id can be assigned.Not sure how to do that.
    – Sales
    Jul 12, 2013 at 18:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .