You need to sign in to do that
Don't have an account?

Method must define a body
I m getting this error...Method must define a body at line 12 column 17
This is my class code
What should be my code??
public with sharing class GmailIntegrationController{
public List<AccountWrapper> accountswrappers { get; set; }
String code;
String key;
String secret;
String redirect_uri;
String CheckFlag;
public GmailIntegrationController(ApexPages.StandardController controller){
init();
}
public void init();
{
code=null;
key = '195939611313-5cr46086hm5db9m17aqjuo6gqpok9a0j.apps.googleusercontent.com';
secret = '2LX5IFSaXhh87gfjaLzz8tz1';
redirect_uri = 'https://gmail.google.com';
System.debug('shhdhshdhshdhshdhhd' + ApexPages.currentPage().getUrl());
code = ApesPages.currentPage().getParameters().get('code');
System.debug('dsdsjdsjdjsjdjsjdsjd' + code);
accountWrappers = new List<AccountWrapper>();
if(code != '' && code != null){
authenticationAndUpload();
return;
}
}
public void authenticationAndUpload(){
System.debug('codesdd:::' + code);
if(code != '' && code != null)
{
System.debug('codesdd:::' + code);
AccessToken();
}
}
public void AccesToken(){
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setEndpoint('https://accounts.google.com/o/oauth2/token');
req.setHeader('content-type', 'application/x-www-form-urlencoded');
String messageBody = 'code='+code+'&client_id='+key+'&client_secret='+secret+'&redirect_uri='+redirect_uri+'&grant_type=authorization_code';
System.debug('messageBody::::' + messageBody );
req.setHeader('Content-length', String.valueOf(messageBody.length()));
req.setBody(messageBody);
req.setTimeout(60*1000);
Http h = new Http();
String resp;
HttpResponse res = h.send(req);
resp = res.getBody();
System.debug(' This is the reponse from google: ' + resp );
String str = resp;
List<String> lstStr = str.split(',');
System.debug('@@@'+lstStr[0]);
List<String> lstStr1 = lstStr[0].split(':');
System.debug('###'+lstStr1[1]);
String st = lstStr1[1].remove('"').trim();
System.debug('@#@'+st);
System.debug('JHSDHSDJSJDJSD' + st + 'TETTETTETTE');
Http http = new Http();
req = new HttpRequest();
req.setMethod('POST');
req.setEndpoint('');
req.setHeader('content-type', 'text/csv');
req.setHeader('Authorization','Bearer '+st);
String contentGmail = gmailContent();
req.setBody(contentGmail);
req.setTimeout(60*1000);
HttpResponse respp = http.send(req);
}
public PageReference GmailAuth()
{
PageReference pg = new PageReference(GmailAuthUri (key , redirect_uri)) ;
return pg;
}
public String GmailAuthUri(String Clientkey,String redirect_uri)
{
String key = EncodingUtil.urlEncode(Clientkey,'UTF-8');
String uri = EncodingUtil.urlEncode(redirect_uri,'UTF-8');
String authuri = '';
authuri = 'https://accounts.google.com/o/oauth2/v2/auth?'+
'scope = https://gmail.google.com/' +
'state=security_token%3D138r5719ru3e1%26url%3Dhttps://oa2cb.example.com/myHome&'+
'redirect_uri=' +uri+
'&response_type=code&'+
'client_id='+key+
'&access_type=offline';
return authuri;
}
private String gmailContent(){
String messageBodies = 'Number ,PTC,Last,First,Mid,Gender,Nationality,DOB,Passport No,Email,Phone\r';
messageBodies+= 'Hello, Test , test, Test,Test, Test, Test,TEst\r';
return messageBodies;
}
public class AccountWrapper{
public Account account{get;set;}
public AccountWrapper(Account account) {
this.account = account;
}
}
}
This is my class code
What should be my code??
public with sharing class GmailIntegrationController{
public List<AccountWrapper> accountswrappers { get; set; }
String code;
String key;
String secret;
String redirect_uri;
String CheckFlag;
public GmailIntegrationController(ApexPages.StandardController controller){
init();
}
public void init();
{
code=null;
key = '195939611313-5cr46086hm5db9m17aqjuo6gqpok9a0j.apps.googleusercontent.com';
secret = '2LX5IFSaXhh87gfjaLzz8tz1';
redirect_uri = 'https://gmail.google.com';
System.debug('shhdhshdhshdhshdhhd' + ApexPages.currentPage().getUrl());
code = ApesPages.currentPage().getParameters().get('code');
System.debug('dsdsjdsjdjsjdjsjdsjd' + code);
accountWrappers = new List<AccountWrapper>();
if(code != '' && code != null){
authenticationAndUpload();
return;
}
}
public void authenticationAndUpload(){
System.debug('codesdd:::' + code);
if(code != '' && code != null)
{
System.debug('codesdd:::' + code);
AccessToken();
}
}
public void AccesToken(){
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setEndpoint('https://accounts.google.com/o/oauth2/token');
req.setHeader('content-type', 'application/x-www-form-urlencoded');
String messageBody = 'code='+code+'&client_id='+key+'&client_secret='+secret+'&redirect_uri='+redirect_uri+'&grant_type=authorization_code';
System.debug('messageBody::::' + messageBody );
req.setHeader('Content-length', String.valueOf(messageBody.length()));
req.setBody(messageBody);
req.setTimeout(60*1000);
Http h = new Http();
String resp;
HttpResponse res = h.send(req);
resp = res.getBody();
System.debug(' This is the reponse from google: ' + resp );
String str = resp;
List<String> lstStr = str.split(',');
System.debug('@@@'+lstStr[0]);
List<String> lstStr1 = lstStr[0].split(':');
System.debug('###'+lstStr1[1]);
String st = lstStr1[1].remove('"').trim();
System.debug('@#@'+st);
System.debug('JHSDHSDJSJDJSD' + st + 'TETTETTETTE');
Http http = new Http();
req = new HttpRequest();
req.setMethod('POST');
req.setEndpoint('');
req.setHeader('content-type', 'text/csv');
req.setHeader('Authorization','Bearer '+st);
String contentGmail = gmailContent();
req.setBody(contentGmail);
req.setTimeout(60*1000);
HttpResponse respp = http.send(req);
}
public PageReference GmailAuth()
{
PageReference pg = new PageReference(GmailAuthUri (key , redirect_uri)) ;
return pg;
}
public String GmailAuthUri(String Clientkey,String redirect_uri)
{
String key = EncodingUtil.urlEncode(Clientkey,'UTF-8');
String uri = EncodingUtil.urlEncode(redirect_uri,'UTF-8');
String authuri = '';
authuri = 'https://accounts.google.com/o/oauth2/v2/auth?'+
'scope = https://gmail.google.com/' +
'state=security_token%3D138r5719ru3e1%26url%3Dhttps://oa2cb.example.com/myHome&'+
'redirect_uri=' +uri+
'&response_type=code&'+
'client_id='+key+
'&access_type=offline';
return authuri;
}
private String gmailContent(){
String messageBodies = 'Number ,PTC,Last,First,Mid,Gender,Nationality,DOB,Passport No,Email,Phone\r';
messageBodies+= 'Hello, Test , test, Test,Test, Test, Test,TEst\r';
return messageBodies;
}
public class AccountWrapper{
public Account account{get;set;}
public AccountWrapper(Account account) {
this.account = account;
}
}
}
Remove ";" from public void init(); Line number 12
It will Work
Thanks,
Nachiket
you got this error becuase you have a ';' on line no 12
public void init();
you can not put a semi colan ';' after class function name
after remove ';' semi colan you can save your class code
thanks
i hope it helps you
bt getting this error Variable does not exist: accountWrappers at line 21 column 9
use below line on 21 thanks
Thnku very much Piyush...
kindly mark it best answer if it helps you so it make proper soltuions for others
thanks
http://sfdcmonkey.com