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
Joseph Gillick 5Joseph Gillick 5 

Apex Class Post Request problem: sending a list between separate public classes

Dear Salesforce community,

I'm trying to send a Post request to an external system. In this json I am sending fields from an opportunity. I ran in to a problem when trying to add all the product line item, product codes in to the class that generates the json. I keep getting this error message: static can only be used on methods of a top level type. This is what my code looks like at the moment:
 
public class LeopardSubscriptionUpdate {
    public static HttpResponse makeGetCallout() {

 

Opportunity o= [Select Id ,AVSFQB__Primary_Contact__r.name, Account.name, Account.Market_Segment__c, AVSFQB__Billing_State__c, AVSFQB__Primary_Contact__r.Email from Opportunity Limit 1] ; 
JSONGenerator gen = JSON.createGenerator(true); 
    gen.writeStartObject();      
    gen.writeStringField('Customer User Full Name', o.AVSFQB__Primary_Contact__r.name);
    gen.writeStringField('Customer Name',o.Account.name);
    gen.writeStringField('Organization Type',o.Account.Market_Segment__c);
    gen.writeStringField('State',o.AVSFQB__Billing_State__c);
    gen.writeStringField('Email', o.AVSFQB__Primary_Contact__r.Email);
    gen.writeEndObject();    
    String jsonS = gen.getAsString();
System.debug('jsonMaterials'+jsonS);
string returnValue = generateStringArray();
System.debug(returnValue);

 

// Sending the http body with JSON 

 

String endpoint = 'myurl.com';
HttpRequest req = new HttpRequest();
req.setEndpoint(endpoint);
req.setMethod('POST');
req.setbody(jsonS);
Http http = new Http();
HTTPResponse response = http.send(req);
  return response;  }
    
   public void generateStringArray(){
        List<OpportunityLineItem> prodCodeList = [Select ProductCode from OpportunityLineItem];
    }
}

I feel like i'm failing to understand the relationship between public classes, public static classes and public void classes. I'm not a developer and kind of just winging it.

Thank you!

 
Raquib SFRaquib SF
Hello,

Try putting:
public static void generateStringArray() instend.

Thanks!