function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sabsisabsi 

trigger post Https

Hi everybody,

I'm a newbie...

I need to post  Opportunity fields to an Https URL after updating one of this field. I've tried with a simple http but that doesn't work

I created a trigger (after Update)

Is it possible with a trigger to do this?

code:

global class RequestClass {
     @Future(callout=true)
   
     Public static void myMethod(string xml)
     {
         Http http= new Http();
        HttpRequest req=new HttpRequest();
        req.setEndpoint('http://test.salesforce.com');
        req.setMethod('POST');
        //Second, invoke web service call
        HttpResponse res=http.send(req);
        //Last, handling the response
        req.setBody(xml);
        //string deb=string.valueOf(res.getBody());
        string deb=res.getBody();
        string username='';
        string passwd='';
        blob headerValue=Blob.valueOf(username+':'+passwd);
        string autHeader='Basic'+Encodingutil.base64Encode(headerValue);
        req.setHeader('Authorization',autHeader);
        system.debug(res);
        system.debug(xml);
        //system.debug(req);
        system.debug(deb+'**********************deb*************************');   
     }
 
}

Trigger

trigger SentToAsw on Opportunity (after update) {
    for (Opportunity opp: Trigger.new){
        if (opp.StageName == 'Closed Won')
        {
                
        string xml='<oppOwner>'+opp.OwnerId+'<oppOwner>'+'<oppName>'+opp.Name+'<oppName>'

+'<oppAccountName>'+opp.AccountId+'<oppAccountName>'+'<oppType>'+opp.Type+'<oppType>'

+'<oppCloseDate>'+opp.CloseDate+'<oppCloseDate>'+'<oppStage>'+opp.StageName+'<oppStage>'

+'<oppApproved>'+opp.Approved__c+'<oppApproved>'+'<oppExpectedRevenue>'+opp.ExpectedRevenue+'<oppExpectedRevenue>'

+'<oppProbability>'+opp.Probability+'<oppProbability>'+'<oppBuyChange>'+opp.Buy_Change_percentage__c+'<oppBuyChange>'

+'<oppBuyChangeWestburg>'+opp.Buy_Change_Westburg_percentage__c+'<oppBuyChangeWestburg>'

+'<oppInvoiceAcc>'+opp.Invoice_Account__c+'<oppInvoiceAcc>'+'<oppDeliveryAcc>'+opp.Delivery_Account__c+'<oppDeliveryAcc>'

+'<oppGrossTotalPrice>'+opp.Gross_Total_Price__c+'<oppGrossTotalPrice>'+'<oppDiscount>'+opp.Discount_percentage__c+'<oppDiscount>'

+'<oppLeadSource>'+opp.LeadSource+'<oppLeadSource>'+'<oppNextStep>'+opp.NextStep+'<oppNextStep>'

+'<oppDescritpion>'+opp.Description+'<oppDescritpion>' +'<oppCreatedBy>'+opp.CreatedById+'<oppCreatedBy>'+'<oppLastModified>'+opp.LastModifiedById+'<oppLastModified>'

+'<oppRecordType>'+opp.RecordTypeId+'<oppRecordType>';               
        system.debug('testaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'+opp.StageName);
        RequestClass.myMethod(xml);
        System.debug('AAAAAAzzzzzzzzz');
        system.debug('*********'+xml+'!!!!!!!!!!!!!!!!!');
        }
    }
   
}

 

 

Thanks for any explaination

Message Edited by sabsi on 04-20-2009 03:31 AM
Ron HessRon Hess

yes, this can work if the endpoint is not salesforce.com.  

We prohibit the use of the remote callout feature to call directly back into salesforce.com.

 

it will work for an external system.

 

 

sabsisabsi

 

I've tried with different sites like google but the page doesn't open and I don't have any error but when I do it for the Https I have this error :

System.CalloutException: java.security.cert.CertificateException: No subject alternative names present

Class.RequestClass.myMethod: line 14, column 26

 

How do I have to do please?

Regards

Ron HessRon Hess

it looks like your ssl server is missing some certificate.

 

what is the url you are calling out to?

sabsisabsi

http://www.google.be the browser doesn't open

Thanks

 

Message Edited by sabsi on 04-15-2009 12:41 AM
sabsisabsi

Hi,

if I only want to go to an URL without security as 'www.google.be' after updating, that doesn't work. Is it a problem from my server certificate too?

I don't have any message error, in the debug logs I can see the result of my trigger who is ok.

Are they mistakes in my code?

 

thanks for replies

sabsisabsi

 I think that the problem comes from the fact that I put the IP address and not the domain name.

Regards

 

Ron HessRon Hess

the error message refers to the cert on your https server.  not google, they have a valid cert.

 

use openssl to print out the cert chain on your server, i suspect that it is self signed, which will not work with Salesforce.com https callouts.  This is a security feature of our callout capability.

Ron HessRon Hess

in firefox, open any page on the https server you are trying to communicate with, then right click, select page info.

then click on the security tab/button and view the certificate.

 

then you can know who signed the cert on your ( internal ? ) https server.

sabsisabsi
 405 Method Not Allowed

 

 

 

global class RequestClass {
     @Future(callout=true)
  
     Public static void myMethod(string xml)
     {
         Http http= new Http();
         HttpResponse rep=new HttpResponse();
        HttpRequest req=new HttpRequest();
        HttpResponse res=new HttpResponse();
        req.setEndpoint('http://www.yahoo.com');
        req.setMethod('POST');
        //Second, invoke web service call
        res=http.send(req);
        System.debug(res.getBody());
           //Last, handling the response
        req.setBody(xml);
        string deb=res.getBody();
        string username='';
        string passwd='';
        blob headerValue=Blob.valueOf(username+':'+passwd);
        string autHeader='Basic'+Encodingutil.base64Encode(headerValue);
        req.setHeader('Authorization',autHeader);
        system.debug(res);
        system.debug(xml);      
     }
 
}

sabsisabsi

Hello,

I get a 'status=ok' when I try to reach an Http but if I try for an Https => "Access Denied"

global class RequestClass {
     @Future(callout=true)
   
     Public static void myMethod(string xml)
     {
         //Build HTTP Request object
         Http http= new Http();
        HttpRequest req=new HttpRequest();
       
        req.setEndpoint('http://www.yahoo.com');
        req.setMethod('GET');
       
            //Second, invoke web service call
       
        string username='';
        string passwd='';
      
        blob headerValue=Blob.valueOf(username + ':' + passwd);
        string autHeader='Basic '+Encodingutil.base64Encode(headerValue);
        req.setHeader('Authorization ',autHeader);
        HttpResponse res=http.send(req);
       
        //Last, handling the response
        req.setBody(xml);
       
        system.debug(res+'xxxxxxxxxxxxxxxxxxxxresxxxxxxxxxxxxxxxxxxxxxxxx');
        system.debug(req.getBody()+'##################req##################');
   
     }
}

Log

20090417103349.888:Class.RequestClass.myMethod: line 31, column 9: System.HttpResponse[Status=OK, StatusCode=200]xxxxxxxxxxxxxxxxxxxxresxxxxxxxxxxxxxxxxxxxxxxxx
20090417103349.888:Class.RequestClass.myMethod: line 32, column 9: <oppName>test<oppName><oppAccountName>001R000000FXn4TIAT<oppAccountName>

Thanks a lot

Ron HessRon Hess

Yep, that is because https://www.yahoo.com does not respond to a get, instead it redirects to http://www.yahoo.com

 

 

gv007gv007

Ron

    we got same exception today but we are not hitting any public websites we are hitting an secure server ,what are the steps we need take to avoid the the situation.

 

 

System.CalloutException: java.security.cert.CertificateException: No subject alternative names present