+ Start a Discussion
MalakondaiahMalakondaiah 

trigger for OpportunityCompetitor and opportunity partner?

Hi,

I need to send the opportunitycompetitor and opportuntity partner records from salesforce to jira?

In this case i need to invoke the webservice call using trigger.

how to write the trigger for both  opportunitycompetitor and opportuntity partner objects?
karthikeyan perumalkarthikeyan perumal
Hello

Here  is the sample code for invoke webservice in Trigger.

Note :  its sample code. modify it for your need. 

Class: 
 
public class WebServiceCallout {

    @future (callout=true)
    public static void sendNotification(String name, String city) {

        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();

        req.setEndpoint('http://my-end-point.com/newCustomer');
        req.setMethod('POST');
        req.setBody('name='+EncodingUtil.urlEncode(name, 'UTF-8')+'&city='+EncodingUtil.urlEncode(city, 'UTF-8'));
        req.setCompressed(true); // otherwise we hit a limit of 32000

        try {
            res = http.send(req);
        } catch(System.CalloutException e) {
            System.debug('Callout error: '+ e);
            System.debug(res.toString());
        }

    }

    // run WebServiceCallout.testMe(); from Execute Anonymous to test
    public static testMethod void testMe() {
        WebServiceCallout.sendNotification('My Test Customer','My City');
    }

}

Trigger: 
 
trigger AccountCallout on Account (after insert) {

    for (Account a : Trigger.new) {
        // make the asynchronous web service callout
        WebServiceCallout.sendNotification(a.Name, a.BillingCity);
    }

}


Hope this will help you. 

Thanks
karthik


 
MalakondaiahMalakondaiah
Hi Karthik,

Thanks for your replay.  i did the invoke the webservice in trigger for opportunity.

i am stuck in below opportunity related objects.

 How to invoke  webservice in Trigger for opportunity related objects(Opportunity Partner and opportunity competetor).