I've developed a Visualforce button that callout an external Webservice and fills object fields with the obtained information.
I cant find the way to create button to close the VF page and refresh the Object that was modified and refresh the page to show the changes.
Is this possible? What can I try to achieve this?
EDIT
Visualforce button.
<apex:page standardController="Account" extensions="EquifaxEmpresaController" action="{!consultaEmpresa}">
<input type="hidden" value="{!account.Equifax__c}"></input>
<apex:pageBlock >
<apex:form >
{!theJSON}
</apex:form>
</apex:pageBlock>
</apex:page>
Extension Class
public class EquifaxEmpresaController {
private final Account acct;
public EquifaxEmpresa theEmpresa {get;set;}
public String theJSON {get;set;}
public String aux {get;set;}
public EquifaxEmpresaController(ApexPages.StandardController stdController){
this.acct = (Account)stdController.getRecord();
}
public void consultaEmpresa(){
string msj = '{'+
'"NroDocumento":"'+acct.Equifax__c+'",'+
'"Consulta":"Empresa"'+
'}';
Http http = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('some endpoint here');
req.setBody(msj);
req.setMethod('POST');
req.setHeader('Content-Type','application/json');
req.setTimeout(12000);
HttpResponse res = new HttpResponse();
res = Http.send(req);
if(res.getStatusCode() == 200){
String body = res.getBody();
theEmpresa = EquifaxEmpresa.parse(body);
Account tempAcct = [select id, BC_IE_Razon_Social__c from account where id =: acct.Id];
tempAcct.BC_IE_Razon_Social__c = theEmpresa.Empresa[0].RazonSocial;
tempAcct.Name = theEmpresa.Empresa[0].NombreComercial;
tempAcct.BC_IE_Tipo_de_Contribuyente__c = theEmpresa.Empresa[0].TipoContribuyente;
tempAcct.BC_IE_Estado_de_Contribuyente__c = theEmpresa.Empresa[0].EstadoContribuyente;
tempAcct.BC_IE_Condicion_Contribuyente__c = theEmpresa.Empresa[0].CondicionContribuyente;
tempAcct.BC_IE_Razon_Dependencia__c = theEmpresa.Empresa[0].Dependencia;
tempAcct.BC_IE_Codigo_CIIU__c = theEmpresa.Empresa[0].CodigoCIIU;
tempAcct.BC_IE_Descripcion_CIIU__c = theEmpresa.Empresa[0].DescripcionCIIU;
tempAcct.BC_IE_Inicio_Actividades__c = theEmpresa.Empresa[0].InicioActividades;
tempAcct.BC_IE_Actividad_Comercio_Exterior__c = theEmpresa.Empresa[0].ActividadComercioExterior;
tempAcct.BC_IE_Numero_Trabajadores__c = theEmpresa.Empresa[0].NumeroTrabajadores;
update tempAcct;
theJSON = 'Datos correctamente insertados, puede cerrar esta ventana.';
}else{
theJSON = 'Error :'+res.getBody()+' '+res.getStatusCode();
}
}
Thanks