You need to sign in to do that
Don't have an account?
Pedro Salles
Problem with static can only be used on methods of a top level type error salesforce
Hi,
I have a problem with my code:
public class contractCallout {@future (callout=true)
public static void PostCallout(String Id) {
Contract result = [SELECT Id from contract where Id = '8004D000000HAdIQAW'];
JSONGenerator gen = JSON.createGenerator(true);
gen.writeStartObject();
gen.writeStringField('Id', result.Id);
/*gen.writeStringField('Origem_Contrato__c',result.Origem_Contrato__c);
gen.writeStringField('Cotacao__r.Contact.FirstName',result.Cotacao__r.Contact.FirstName);
gen.writeStringField('Cotacao__r.Contact.LastName',result.Cotacao__r.Contact.LastName); */
gen.writeEndObject();
String jsonS = gen.getAsString();
System.debug('jsonMaterials'+jsonS);
// Sening the http body with JSON
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
request.setBody(jsonS);
HttpResponse response = http.send(request);
// Parse the JSON response
if (response.getStatusCode() != 201) {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus());
} else {
System.debug(response.getBody());
}
}
}
when I am going to take a test, it presents the following error: static can only be used on methods of a top level type
Can someone help me?
Thanks
I have a problem with my code:
public class contractCallout {@future (callout=true)
public static void PostCallout(String Id) {
Contract result = [SELECT Id from contract where Id = '8004D000000HAdIQAW'];
JSONGenerator gen = JSON.createGenerator(true);
gen.writeStartObject();
gen.writeStringField('Id', result.Id);
/*gen.writeStringField('Origem_Contrato__c',result.Origem_Contrato__c);
gen.writeStringField('Cotacao__r.Contact.FirstName',result.Cotacao__r.Contact.FirstName);
gen.writeStringField('Cotacao__r.Contact.LastName',result.Cotacao__r.Contact.LastName); */
gen.writeEndObject();
String jsonS = gen.getAsString();
System.debug('jsonMaterials'+jsonS);
// Sening the http body with JSON
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
request.setBody(jsonS);
HttpResponse response = http.send(request);
// Parse the JSON response
if (response.getStatusCode() != 201) {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus());
} else {
System.debug(response.getBody());
}
}
}
when I am going to take a test, it presents the following error: static can only be used on methods of a top level type
Can someone help me?
Thanks
how are you testing ?? Go to devloper console and execute this code
or from the trigger
All Answers
how are you testing ?? Go to devloper console and execute this code
or from the trigger
I'm starting in the development within Salesforce now.
I needed to send this information through a trigger, but I do not know how to structure the code, would you know how to do this?