Notes
Utility Class
public class TokenUtility {
public static String getTokenByLabel(String label){
TokenList__mdt mytoken = TokenList__mdt.getInstance(label);
return mytoken.token__c;
}
}
Get token from metadata using a utility class
public class CustomerAPI {
public static String token =TokenUtility.getTokenByLabel('PTSAPIToken');
public static void getCustomers(){
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://api.pathtosalesforce.com/customerList.php?token='+token);
request.setMethod('GET');
HttpResponse response = http.send(request);
System.debug(response.getStatusCode());
System.debug(response.getStatus());
System.debug(response.getBody());
}
}