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
Tom SimmonsTom Simmons 

Need help with error unexpected token

All, need help. I`m getting an error at line 17 unexpected token: ')' and I cant figure out why. Can someone please help?
 
public class callout {


Settings__c ts = [SELECT Name, Client_Secret__c, ConsumerKey__c, Password__c, SecurityToken__c,Username__c from Settings__c];



String clientId = ts.ConsumerKey__c;
String clientSecret = ts.Client_Secret__c;
String username=ts.Username__c;
String password=ts.Password__c+ts.SecurityToken__c; 

String reqbody = 'grant_type=password&client_id='+clientId+'&client_secret='+clientSecret+'&username='+username+'&password='+password;

Http h = new Http ();
HttpRequest req = new HttpRequest ();
req.setBody(reqbody);
req.setMethod('POST');
req.setEndpoint(ts.URL__c+'/services/oauth2/token');

HttpResponse res = h.send(req);
OAuth2 objAuthenticationInfo = (OAuth2)JSON.deserialize(res.getbody(), OAuth2.class);
RequestWrapper reqst=new RequestWrapper();
if(objAuthenticationInfo.access_token!=null){
Http h1 = new Http();
HttpRequest req1 = new HttpRequest();

req1.setHeader('Authorization','Bearer '+objAuthenticationInfo.access_token);
req1.setHeader('Content-Type','application/json');
req1.setHeader('accept','application/json');
req1.setBody(jsonstr);//Send JSON body
req1.setMethod('POST');
req1.setEndpoint(ts.URL__c+URL);
HttpResponse res1 = h1.send(req1);
system.debug('RESPONSE_BODY'+res1 .getbody());
}
}

 
Best Answer chosen by Tom Simmons
Magesh Mani YadavMagesh Mani Yadav
Hi Tom,

You have missed defining a method for the callout. Just copy the updated code should work now.
public class callout {

public static void calloutMethod(){
	Settings__c ts = [SELECT Name, Client_Secret__c, ConsumerKey__c, Password__c, SecurityToken__c,Username__c from Settings__c];



    String clientId = ts.ConsumerKey__c;
    String clientSecret = ts.Client_Secret__c;
    String username=ts.Username__c;
    String password=ts.Password__c+ts.SecurityToken__c; 
    
    String reqbody = 'grant_type=password&client_id='+clientId+'&client_secret='+clientSecret+'&username='+username+'&password='+password;
    
    Http h = new Http ();
    HttpRequest req = new HttpRequest ();
    req.setBody(reqbody);
    req.setMethod('POST');
    req.setEndpoint(ts.URL__c+'/services/oauth2/token');
    
    HttpResponse res = h.send(req);
    OAuth2 objAuthenticationInfo = (OAuth2)JSON.deserialize(res.getbody(), OAuth2.class);
    RequestWrapper reqst=new RequestWrapper();
    if(objAuthenticationInfo.access_token!=null){
    Http h1 = new Http();
    HttpRequest req1 = new HttpRequest();
    
    req1.setHeader('Authorization','Bearer '+objAuthenticationInfo.access_token);
    req1.setHeader('Content-Type','application/json');
    req1.setHeader('accept','application/json');
    req1.setBody(jsonstr);//Send JSON body
    req1.setMethod('POST');
    req1.setEndpoint(ts.URL__c+URL);
    HttpResponse res1 = h1.send(req1);
    system.debug('RESPONSE_BODY'+res1 .getbody());
    }
}
}

 

All Answers

Magesh Mani YadavMagesh Mani Yadav
Hi Tom,

You have missed defining a method for the callout. Just copy the updated code should work now.
public class callout {

public static void calloutMethod(){
	Settings__c ts = [SELECT Name, Client_Secret__c, ConsumerKey__c, Password__c, SecurityToken__c,Username__c from Settings__c];



    String clientId = ts.ConsumerKey__c;
    String clientSecret = ts.Client_Secret__c;
    String username=ts.Username__c;
    String password=ts.Password__c+ts.SecurityToken__c; 
    
    String reqbody = 'grant_type=password&client_id='+clientId+'&client_secret='+clientSecret+'&username='+username+'&password='+password;
    
    Http h = new Http ();
    HttpRequest req = new HttpRequest ();
    req.setBody(reqbody);
    req.setMethod('POST');
    req.setEndpoint(ts.URL__c+'/services/oauth2/token');
    
    HttpResponse res = h.send(req);
    OAuth2 objAuthenticationInfo = (OAuth2)JSON.deserialize(res.getbody(), OAuth2.class);
    RequestWrapper reqst=new RequestWrapper();
    if(objAuthenticationInfo.access_token!=null){
    Http h1 = new Http();
    HttpRequest req1 = new HttpRequest();
    
    req1.setHeader('Authorization','Bearer '+objAuthenticationInfo.access_token);
    req1.setHeader('Content-Type','application/json');
    req1.setHeader('accept','application/json');
    req1.setBody(jsonstr);//Send JSON body
    req1.setMethod('POST');
    req1.setEndpoint(ts.URL__c+URL);
    HttpResponse res1 = h1.send(req1);
    system.debug('RESPONSE_BODY'+res1 .getbody());
    }
}
}

 
This was selected as the best answer
Ajinkya1225Ajinkya1225
Hi Tom,

It looks like you are not querying URL__c which you are using in line 19. You need to add it in your query at line 4. Also, as mentioned by Magesh, you are missing the defining method. Apart from that, code looks fine to me.

Can you take a moment to  upvote and mark this answer as solved, if it helped you.
Cheers!
Ajinkya Deshmukh
Magesh Mani YadavMagesh Mani Yadav
and also update your soql for the URL__c field
Tom SimmonsTom Simmons
Thank you Mangesh/Ajinkya, that resolved the issue but now I`m getting "Error: Compile Error: Invalid type: RequestWrapper at line 23 column 32" and the class still wont save. Any idea why this is happening?
Magesh Mani YadavMagesh Mani Yadav
Do you have a class called RequestWrapper ?
Magesh Mani YadavMagesh Mani Yadav
I dont see any usage of Class RequestWrapper in your method.. so try removing line "RequestWrapper reqst=new RequestWrapper();"  and save it