You need to sign in to do that
Don't have an account?
Aryan 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());
}
}
}
{
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());
}
}
}
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.
Mark this as Best Answer if it helped you.
Regards,
Santosh Kumar
Great it helped you, s ocould you please close this thread by marking this as Best Answer.
Regards,
Santosh Kumar