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
{
@future(callout=true)
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();
sessionHeader.sessionid=loginResult.sessionid;
apx.sessionheader=sessionHeader;
//soapSforceComSchemasClassAccountpla.plan p=new soapSforceComSchemasClassAccountpla.plan();
for(opportunity lap:opp)
{
soapSforceComSchemasClassAccountpla.plan p=new soapSforceComSchemasClassAccountpla.plan();
//plan p=new plan();
p.name=lap.name;
p.planid=lap.id;
p.planningPeriod=lap.closedate;
p.stagename=lap.stagename;
id=apx.createAccountPlan(p);
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++)
{
k.get()
}
}
}
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;
opp.oppexternalid__c=vplan.planid;
opp.closedate=vplan.planningPeriod;
opp.stagename=vplan.stagename;
upsert opp oppexternalid__c ;
vPlan.planId=opp.Id;
return vPlan;
}
}