+ Start a Discussion
Andrew84Andrew84 

Argument cannot be null. Error is in expression '{!class}' in component <apex:page> in page pagename

I've been trying to find a solution for this all over with no luck. I'm trying to create a GoToMeeting meeting from Salesforce through the GoToMeeting API. I'm not too familiar with APIs in general.

 

I get the error:

Argument cannot be null. Error is in expression '{!createMeeting}' in component <apex:page> in page gotomeetingapi

 

This is what I have on my Page:

 

<apex:page controller="GoToMeetingAPI">
    <apex:form id="newmeetings">
    	<script type="text/javascript">
	function addMeeting() {
		makeMeeting(
			document.getElementById("subject").value,
			document.getElementById("starttime").value,
			document.getElementById("endtime").value,
			document.getElementById("conferencecallinfo").value,
			document.getElementById("meetingtype").value
			);
		}
	</script> 
    	<apex:actionFunction name="makeMeeting" action="{!createMeeting}">
		<apex:param name="subject" value="t" />
		<apex:param name="starttime" value="" />
		<apex:param name="endtime" value="" />
		<apex:param name="conferencecallinfo" value="" />
		<apex:param name="meetingtype" value="" />
	</apex:actionFunction>
    	subject<input type="text" id="subject"/><br />
    	starttime<input type="text" id="starttime"/><br />
    	endtime<input type="text" id="endtime"/><br />
    	conferencecallinfo<input type="text" id="conferencecallinfo"/><br />
    	meetingtype<input type="text" id="meetingtype"/><br />
    	<button type="button" onclick="addMeeting()">Submit</button>
    </apex:form>
</apex:page

 

This what I have for my class:

 

public class GoToMeetingAPI {
	public PageReference createMeeting() {
		String subject = Apexpages.currentPage().getParameters().get('subject');
		String starttime = Apexpages.currentPage().getParameters().get('starttime');
		String endtime = Apexpages.currentPage().getParameters().get('endtime');
		String conferencecallinfo = Apexpages.currentPage().getParameters().get('conferencecallinfo');
		String meetingtype = Apexpages.currentPage().getParameters().get('meetingtype');
		Http httpProtocol = new Http();
		HttpRequest request = new HttpRequest();
		HttpResponse response = new HttpResponse();
		request.setEndpoint('https://api.citrixonline.com/G2M/rest/meetings');
		request.setMethod('POST');
		request.setBody('subject='+EncodingUtil.urlEncode(subject,'UTF-8')+
						'&starttime='+EncodingUtil.urlEncode(starttime,'UTF-8')+
						'&endtime='+EncodingUtil.urlEncode(endtime,'UTF-8')+
						'&passwordrequired=false'+
						'&conferencecallinfo='+EncodingUtil.urlEncode(conferencecallinfo,'UTF-8')+
						'&timezonekey=""'+
						'&meetingtype='+EncodingUtil.urlEncode(meetingtype,'UTF-8'));
		request.setHeader('Authorization','OAuth oauth_token=123456789');
		request.setCompressed(true);
		try {
            response = httpProtocol.send(request);
        } catch(System.CalloutException e) {
            System.debug('Callout error: '+ e);
            System.debug(response.toString());
        }
        return null;
	}
}

 I apologize for the names of my function names... I've been getting frustrated and all I need to do is show that it works.

 

The GET request was so much easier!

 

If anyone knows what I'm missing I'd be very appreciative.

Best Answer chosen by Admin (Salesforce Developers) 
Coco_SdyneyCoco_Sdyney

Please do not put null variable in urlEncode method.

 

For below 4 variables, please validate whether it's null before you put them into urlEncode.

String subject = Apexpages.currentPage().getParameters().get('subject');
		String starttime = Apexpages.currentPage().getParameters().get('starttime');
		String endtime = Apexpages.currentPage().getParameters().get('endtime');
		String conferencecallinfo = Apexpages.currentPage().getParameters().get('conferencecallinfo');

All Answers

Coco_SdyneyCoco_Sdyney

Please do not put null variable in urlEncode method.

 

For below 4 variables, please validate whether it's null before you put them into urlEncode.

String subject = Apexpages.currentPage().getParameters().get('subject');
		String starttime = Apexpages.currentPage().getParameters().get('starttime');
		String endtime = Apexpages.currentPage().getParameters().get('endtime');
		String conferencecallinfo = Apexpages.currentPage().getParameters().get('conferencecallinfo');
This was selected as the best answer
Andrew84Andrew84

I stopped URL encoding them and changed the string, it worked fine. Now I'm more or less integrated with GoToMeeting.

 

 

Thank you!