You need to sign in to do that
Don't have an account?
Updating custom field with http response
Hi All, need ur help,
I m firing a trigger by passing id of the object that extecute the http request n response.n my getting the response also.
but i have to refresh my detail page manually ,then that response value gets set to my customfield.
I want that..when i click save then data n response value both gets saved at that time.
My trigger code is this:
trigger test on OpportunityGAQ__c (after insert) {
System.debug('Making future call to update account');
for(OpportunityGAQ__c op:Trigger.New)
{
GAQUpdater.updateGAQ(op.Id, op.Name);
}
}
My Apex code is this :
public class GAQUpdater {
public GAQUpdater(ApexPages.StandardController controller) {
}
//Future annotation to mark the method as async.
@Future(callout=true)
public static void updateGAQ(String id, String name) {
public void save(){
// system.debug('OPP:'+id);
//construct an HTTP request
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
string test = 'some string';
req.setEndpoint('http://www.test.com.aspx');
req.setMethod('POST');
req.setBody(test);
res = http.send(req);
System.debug(res.getBody());
Dom.Document doc =(res.getBodyDocument());
Dom.XMLNode envelope = doc.getRootElement();
Dom.XmlNode[] temp = envelope.getChildElements();
// String name = envelope.getChildElements('OrderID', null).getText();
system.debug(temp.size());
// print out specific elements
// System.debug('OrderID: ' + name);
if(temp.size()>0)
{
// Alternatively, loop through the child elements.
// This prints out all the elements of the address
for(Dom.XMLNode child : temp[1].getChildElements()) {
if(child.getName()=='OrderID')
{
// System.debug('G Ord Id: '+child.getText());
OpportunityGAQ__c op = new OpportunityGAQ__c(Id=id);
op.Refrence_Number__c = child.getText();
update op;
}
else if(child.getName()=='OrderStatusErrors'){
for(Dom.XMLNode child2 : child.getChildElements()) {
for(Dom.XMLNode child3 : child2.getChildElements()) {
if(child3.getName()=='ErrorText'){
System.debug('Error Message: '+child3.getText());
}
}
}
}
}
}
}
}
}
Every part of the Apex controller is fine cos m getting the response n also reading that response value(order no here)
but,the Red mark area is for updating the field,this is also working n update the field (to my custom reference field) but when i manually refresh the page.
I have created a custom object n have 2 field,name n id of field i am passing through trigger n in reference field for response to save. I am not using VF any Pages.
Pls help me to this.