You need to sign in to do that
Don't have an account?
Sahaj
Only top-level class variables can be declared static
Hi Community,
I am trying to do callout but i am getting the below error.
Only top-level class variables can be declared static Line 39
I know there are lots of other error too as I am beginer. Please help me with the below code
Thanks
I am trying to do callout but i am getting the below error.
Only top-level class variables can be declared static Line 39
I know there are lots of other error too as I am beginer. Please help me with the below code
Thanks
global class Moogsoft { @future (callout=true) public static void getMoog(String inc,String moog) { String authT = getAuth(); system.debug('####'+authToken); String firstC = updateMoog1(inc,moog,authToken); system.debug('####'+firstC); String secondC = updateMoog2(inc,moog,authToken); system.debug('####'+secondC); } public static string authToken() { String URL1 = 'https://events5.hclmtaas.com:8080/graze/v1/authenticate?username=graze&password=graze'; HttpResponse resData = HTTPCallout(URL1, 'GET'); System.debug('Response from Moog: ('+resData.getStatusCode()+')'+resData.getBody()); if(resData.getStatusCode()>299) { String error = 'Failed getting a request token. HTTP Code = '+resData.getStatusCode()+ '. Message: '+resData.getStatus()+'. Response Body: '+resData.getBody(); system.debug('failed'+error); } else{ JSONParser parser = JSON.createParser(resData.getBody()); while (parser.nextToken() != null) { if (parser.getCurrentToken() == JSONToken.FIELD_NAME){ String fieldName = parser.getText(); parser.nextToken(); if(fieldName == 'auth_token' ) { authToken = parser.getText(); system.debug('++++++++++'+authToken); } return authtoken; } public static string firstCall(String a1,String b1,String c1) { String URL2 = 'abcd.com'; HttpResponse res = HTTPCallout(URL2, 'POST'); System.debug('Response from Code request: ('+res.getStatusCode()+')'+res.getBody()); if(res.getStatusCode()>299) { String error = 'Failed from moog.HTTP Code = '+res.getStatusCode()+ '. Message: '+res.getStatus()+'. Response Body: '+res.getBody(); System.debug('##### Failed: '+error); return error; } else{ return null; } } public static string secondCall(String a2,String b2,String c2) { String URL3 = 'qrws.com'; HttpResponse resT = HTTPCallout(EP2, 'POST'); System.debug('Response from Code request: ('+resT.getStatusCode()+')'+resT.getBody()); if(resT.getStatusCode()>299) { String error = 'Failed from moog.HTTP Code = '+resT.getStatusCode()+ '. Message: '+resT.getStatus()+'. Response Body: '+resT.getBody(); System.debug('##### Failed: '+error); return error; } else{ return null; } } public Static HttpResponse HTTPCallout(String EndPoint, String Method) { Http h = new Http(); HttpRequest req= new HttpRequest(); req.setEndpoint(EndPoint); req.setMethod(Method); HttpResponse res = null; res = h.send(req); return res; } }
[1] https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_httpcalloutmock.htm
[2] https://developer.salesforce.com/blogs/developer-relations/2013/03/testing-apex-callouts-using-httpcalloutmock.html
[3] http://blog.deadlypenguin.com/blog/testing/strategies/
All Answers
This may not work because you do not have updateMoog1 or updateMoog2 defined. As well as other variables.
Can you please let me know how can i make my code more mature and i want to write test class for this code,so please share some reference
Thanks again.
[1] https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_httpcalloutmock.htm
[2] https://developer.salesforce.com/blogs/developer-relations/2013/03/testing-apex-callouts-using-httpcalloutmock.html
[3] http://blog.deadlypenguin.com/blog/testing/strategies/