I tried the following code to insert incident from salesforce to ServiceNow but not sure what I am doing wrong here,

Can anyone guide me what changes needed in this code or do I need to create anything in ServiceNow like we have Remote site setting in salesforce?

public class sfdcTOsnow{
    public static void servicenowPost(Id CaseId){  

        Case c = [Select Id, CaseNumber from Case where Id =: CaseId limit 1];
        Http http = new Http();
        HttpRequest req =  new HttpRequest();
        HttpResponse res = new HttpResponse();
        String username = 'admin';
        String password = 'Stech1234';
        Blob headerValue = Blob.valueOf(username + ':' + password);
        String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
        req.setHeader('Authorization', authorizationHeader);
        req.setHeader('Content-Type', 'application/json');

        JSONGenerator gen = JSON.createGenerator(true);

        gen.writeStringField('number', c.CaseNumber);
        gen.writeStringField('short_description','This is Test');

        String pretty = gen.getAsString();

        res = http.send(req);


Here is my trigger code,

trigger servicenow on Case (after insert){
up vote 0 down vote accepted

Ohh I got as I was not aware of that EndPoint for the ServiceNow,

I just make changes in following line and it worked as i needed,


Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.