I need to parse a webservice result first to take actions afterwards.
"You have uncommitted work pending. Please commit or rollback before calling out"
I'm getting now this error, and there are a bunch of similar questions asked here or over the internet that i have tried to implement, but most of them are about doing the DML first and then calling the webservice.
According to this article, you can't have a webservice call and a DML in the same scope, and the solution is to do the DML and then declare another method for the webservice call in a different class.
But to my demise, i need to update the object with a bunch of values (around 15) obtained from the webservice call. And i could always declare setters or variables for each value and pass them as parameters to the next function, but there's a lot of them, so i'm looking for a more elegant solution.
Using onComplete on the commandButton looks like an equally bulky solution, and it would mess with my view by adding controller logic to it. Besides, each response object created by the "Generate from WSDL" use nested classes, adding more complexity to it.
Here is my controller logic, "servicio" is the instance of the webservice class
public void Login() {
string alias = Usuario.Alias.split('@').get(0);
//Here is where i do the WS call and get the values
SalesforceTPSoap.ResultadoLogIn r = servicio.Login(this.IdEscritorio, Ofi, alias, Usuario.TP_Password__c);
//now with the values, i need to get an object (TPSesion__c) and populate it with values, if it doesn't exist, i need to create it. any DML on this scope will trigger the error
if (r.Err.CodError == 0){
TPSesion__c[] tpsesion = [select s.Id from TPSesion__c s where s.OwnerId = :UserInfo.getUserId() and s.Hora_Login__c = :Date.today() limit 1];
if (tpsesion.size() == 0){
TPSesion__c tps = new TPSesion__c();
tps.Usuario__c = Userinfo.getUserId();
//this is just one of the updates
tps.Hora_Login__c = r.Hora;
tps.IdEscritorio__c = this.IdEscritorio;
insert tps;
}
else{
TPSesion__c tps = tpsesion[0];
tps.Cantidad_Login_Diaria__c++;
update tps;
}
}
}
Thanks in advance
servicio.Login()
method perform DML before it makes a callout?