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
NikithaNikitha 

Salesforce Integration call external api from button and response should be updated course Ids

Hi, I am struggling  in integration. I have created a code and the response is internal server err.  please can anybody tell me what I have done wrong? I'm new to integration. my requirement is I have to create a javascript button. when I am clicking the button should send a request to Api and response should be updated Course Ids. How can I achieve that. I have  referred some posts but I didn't able to find what i have done wrong.
 my code.

global with sharing class CreateCourseInMoodle 
{
    public static final String token = PROFG_LMS_Setting__c.getValues('LMS_WS_Token').Value__c;
    public static final string categoryid = PROFG_LMS_Setting__c.getValues('BE_CategoryId').Value__c;
    public static final String endPoint = PROFG_LMS_Setting__c.getValues('LMS_EndPoint').value__c ;
    webservice static string requestMoodleCourse(String courseId)
    {
        system.debug('Ids'+courseId);
       List< Moodle_course__c> course = ((MoodleCoursesSelector_PG) Application_PG.selector.newInstance(Moodle_Course__c.SObjectType)).selectById(new Set<Id> {courseId});
        Map<String, String> inputsForCourse = new Map<String, String>();
        inputsForCourse.put('wstoken ', token);
        inputsForCourse.put('moodlewsrestformat', 'json');
        inputsForCourse.put('wsfunction','core_course_create_courses');
        inputsForCourse.put('courses[0][fullname]',course[0].Name);
        inputsForCourse.put('courses[0][shortname]',course[0].Name);
        inputsForCourse.put('courses[0][categoryid]', categoryid);
        inputsForCourse.put('courses[0][idnumber]',courseId);
        inputsForCourse.put('courses[0][summary]', course[0].Description__c);
        inputsForCourse.put('courses[0][summaryformat]','1');
        inputsForCourse.put('courses[0][format]','topics');
        inputsForCourse.put('courses[0][showgrades]','0');
        inputsForCourse.put('courses[0][newsitems]','0');
        inputsForCourse.put('courses[0][numsections]','2');
        inputsForCourse.put('courses[0][maxbytes]','2');
        inputsForCourse.put('courses[0][showreports]','0');
        inputsForCourse.put('courses[0][visible]','1');
        inputsForCourse.put('courses[0][hiddensections]','0');
        inputsForCourse.put('courses[0][enablecompletion]','1');
        inputsForCourse.put('courses[0][lang]','en');
        inputsForCourse.put('courses[0][groupmode]','0');
        inputsForCourse.put('courses[0][groupmodeforce]','0');
        inputsForCourse.put('courses[0][defaultgroupingid]','0');
        inputsForCourse.put('courses[0][customfields][0][shortname]','Country');
        inputsForCourse.put('courses[0][customfields][0][value]',course[0].Country__c);
        system.debug('mapOfcourse '+inputsForCourse);
        
        
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint(endPoint);
        system.debug('endpoint'+endPoint);
        request.setMethod('GET');
        HttpResponse response = http.send(request);
          
        response = http.send(request);
        System.debug(response.getStatus());
        System.debug(response.getBody());
        if(response.getStatusCode() == 200)
        {
            system.debug('Success');
        }else
        {
            system.debug('Failure');
        }
        return response.getStatus();
    }
}
SwethaSwetha (Salesforce Developers) 
HI Swathi,
Can you share the complete error message of the Internal server error by including the GACK ID so that the community can suggest better?

See what is a GACK on https://developer.salesforce.com/blogs/engineering/2015/02/gack.html#