+ Start a Discussion
Aryan JhaAryan Jha 

Missing return statement required return type: String at line 3 column 22

public class YoutubeApi
{
public static String Nameoftheyoutubechannel(String ChannelName)
{
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://www.googleapis.com/youtube/v3');
request.setMethod('GET');
HttpResponse response = http.send(request);
if(response.getStatusCode()==200)
{
    Map<String,Object>jsonbody=(Map<String,Object>)JSON.deserializeUntyped(response.getBody());
    Map<String,Object>result=(Map<String,Object>)jsonbody.get('SNIPPET');
    String id=(String) result.get('ChannelId');

    return id;
}
else
{
    system.debug(+ response.getStatusCode() + '' +response.getStatus());
}
}
}
Santosh Kumar 348Santosh Kumar 348
Hi Aryan,

As your return type is String so your method must return some String value and you haven't written the return statement from else part.
Either you must have a return statement from If as well as else or create a string in if else and return should be your last statement.

I have made changes in your else part this hsould work.
public class YoutubeApi{
	public static String Nameoftheyoutubechannel(String ChannelName){
		Http http = new Http();
		HttpRequest request = new HttpRequest();
		request.setEndpoint('https://www.googleapis.com/youtube/v3');
		request.setMethod('GET');
		HttpResponse response = http.send(request);
		if(response.getStatusCode()==200){
			Map<String,Object>jsonbody=(Map<String,Object>)JSON.deserializeUntyped(response.getBody());
			Map<String,Object>result=(Map<String,Object>)jsonbody.get('SNIPPET');
			String id=(String) result.get('ChannelId');

			return id;
		}
		else{
			system.debug(+ response.getStatusCode() + '' +response.getStatus());
			return response.getStatus();
		}
	}
}

Mark this as Best Answer if it helped you.

Regards,
Santosh Kumar
Aryan JhaAryan Jha
Thanks for the answer it really helped me
Santosh Kumar 348Santosh Kumar 348
Hi Aryan,

Great it helped you, s ocould you please close this thread by marking this as Best Answer.

Regards,
Santosh Kumar