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
Lukesh KarmoreLukesh Karmore 

Hii problem in trigger and Integration

Hii , I Integrate with external system   Post Call , With trigger when case status is Closed send CaseID__c (Custom Object) external system . i wrote trigger but found debug like Response---Method Not Allowed. Can any one sloved this problem.

public class SendCaseToNetSuite {
     @future (callout=true) 
    public static void UpdateCaseStatus(set<id>  SendCaseId){
       if(!SendCaseId.isEmpty()){ 
    List<case> caseList=[select id,caseId__c,Status from case where caseId__c != null And Id IN :SendCaseId];
         System.debug('caseList'+caseList);
        for(case c:caseList){ 
          //  JSONGenerator gen = JSON.createGenerator(true);
          // Write data to the JSON string.
         // gen.writeStartObject();
         // gen.writeNumberField('caseId',  c.caseId__c);
         // gen.writeEndObject();
          // Get the JSON string.
         // String pretty = gen.getAsString();
         
           Map<String, Integer> tags = new Map<String, Integer>();
            tags.put('caseId',Integer.valueOf(c.caseId__c));
            string endpoint = 'https://1074624-sb1.extforms.netsuite.com/app/site/hosting/scriptlet.nl?script=913&deploy=1&compid=1074624_SB1&h=9a5b4f34527b28b1f43d';
                HttpRequest req = new HttpRequest();
                req.setEndpoint(endpoint);
                req.setMethod('POST');
                req.setHeader('Content-type', 'application/json');
                //req.setBody(pretty);
               req.setbody(JSON.serialize(tags));
                Http http = new Http();
                HttpResponse res=new HttpResponse();
            try{
                res= http.send(req);
                system.debug('Output response:  ' +res.getBody());
            }
            catch(Exception e){
             system.debug('Error......' +e.getMessage());
            }
             
}
}
        
    }


}

Trigger;

trigger SendCaseToNetsuite on Case (before Update) {
    
    if(trigger.isBefore && trigger.isUpdate){
        set<id> SendCaseId=new set<id>();
         for(Case cases:trigger.new){
        if(cases.Status!=null && cases.Status=='Closed'){
            SendCaseId.add(cases.Id);
        }
         }
         if(!SendCaseId.isEmpty()){ 
        SendCaseToNetSuite.UpdateCaseStatus( SendCaseId);
    }
}
    }

Debug is:
Debug
mukesh guptamukesh gupta
Hi Lukesh,

Please use below code:-
 
public class SendCaseToNetSuite {
		 @future (callout=true) 
		public static void UpdateCaseStatus(set<id>  SendCaseId){
		   if(!SendCaseId.isEmpty()){ 
		List<case> caseList=[select id,caseId__c,Status from case where caseId__c != null And Id IN :SendCaseId];
			 System.debug('caseList'+caseList);
			for(case c:caseList){ 
			
			 
			   Map<String, Integer> tags = new Map<String, Integer>();
				tags.put('caseId',Integer.valueOf(c.caseId__c));
				string endpoint = 'https://1074624-sb1.extforms.netsuite.com/app/site/hosting/scriptlet.nl?script=913&deploy=1&compid=1074624_SB1&h=9a5b4f34527b28b1f43d';
					
			// Instantiate a new http object
				Http http = new Http();
				 // Instantiate a new HTTP request, specify the method (POST) as well as the endpoint
				HttpRequest req = new HttpRequest(); 
				req.setEndpoint(endpoint);
				req.setMethod('POST');
				//Content-Type  header is set to let the service know that the sent data is in JSON format
				req.setHeader('Content-Type', 'application/json');
				//Specify the body to be send (contains JSON data)
				req.setBody(Body); 

				  try {  

					// Send the request, and return a response
				HttpResponse res =  http.send(req); 
				system.debug('Output response:  ' +res.getBody());
				} catch(System.CalloutException e) {  
				  system.debug('Error......' +e.getMessage());
				System.debug(res.toString()); 
				} 
					System.debug( res.getBody());

				 
	}
	}
			
		}


	}

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 
Lukesh KarmoreLukesh Karmore
 Hii mukesh,
Thank you for your reply
What u have changed in above code 
mukesh guptamukesh gupta
HI Lukesh,

Is it working or not ? please let me know 

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 

 
Lukesh KarmoreLukesh Karmore
Hii mukesh,
"System.HttpResponse[Status=Method Not Allowed, StatusCode=405]"|
caseList(Case:{Id=5002w00000IPIRIAA5, caseId__c=2113, Status=Closed})
Output response:  Method Not Allowed
Same error hai..................