Anyone give any guidance into why this error would be occuring, code is pasted below.
public class RampOtherCostsBatch implements Schedulable {
public void execute(SchedulableContext SC) {
makeCallout();
}
@future(callout=true)
public static void makeCallout() {
Ramp_Token__c rampTokenSetting = Ramp_Token__c.getValues('Ramp Token');
//String rampToken = rampTokenSetting.Ramp_Token__c: null ? rampTokenSetting != null;
String rampToken = rampTokenSetting != null ? rampTokenSetting.Ramp_Token__c: null;
System.debug('------- security token--- '+rampToken);
if (rampToken != null) {
HTTP h1 = new HTTP();
HTTPRequest req1 = new HTTPRequest();
req1.setEndpoint('https://2nzuzzpdkdldfe3eh77gyq3fiy0ewkrv.lambda-url.us-east-1.on.aws');
req1.setMethod('GET');
req1.setHeader('Authorization', rampToken);
HttpResponse response1;
try {
response1 = new Http().send(req1);
if (response1.getStatusCode() == 200) {
Map<String, Object> parsedData = (Map<String, Object>)JSON.deserializeUntyped(response1.getBody());
List<Object> dataArray = (List<Object>)parsedData.get('data');
List<Other_Cost__c> otherCostList = new List<Other_Cost__c>();
Set<String> rampIds = new Set<String>(); // To store Ramp_ID__c values already processed
for (Object dataObj : dataArray) {
Map<String, Object> dataMap = (Map<String, Object>)dataObj;
String rampId = (String)dataMap.get('id');
// Check if the Ramp_ID__c value already exists
if (!rampIds.contains(rampId)) {
String memo = (String)dataMap.get('memo');
String createdAt = (String)dataMap.get('created_at');
Other_Cost__c oc = new Other_Cost__c();
oc.Subject__c = (String)dataMap.get('merchant');
oc.Ramp_Submitter__c = (String)dataMap.get('user_full_name');
oc.Date__c = Date.today();
oc.Ramp_ID__c = rampId;
oc.Ramp_Integration_Id__c = rampId;
oc.Ramp_Status__c = (String)dataMap.get('state');
oc.Description__c = (String)dataMap.get('memo');
oc.Ramp_Amount__c = (Decimal)dataMap.get('amount');
otherCostList.add(oc);
// Add the Ramp_ID__c to the set to avoid duplicates
rampIds.add(rampId);
}
}
if(!otherCostList.isEmpty()){
//insert otherCostList;
Database.upsert(otherCostList, Other_Cost__c.Fields.Ramp_Integration_Id__c, false);
// Insert Other_Cost_Line__c records
List<Other_Cost_Line__c> otherCostLineList = new List<Other_Cost_Line__c>();
for(Other_Cost__c oc : otherCostList) {
Other_Cost_Line__c ocLine = new Other_Cost_Line__c();
ocLine.Other_Cost__c = oc.Id;
ocLine.Quantity__c = 1;
ocLine.Cost_Amount__c = oc.Ramp_Amount__c;
ocLine.Billable_Amount__c = oc.Ramp_Amount__c;
ocLine.Description__c = oc.Description__c;
ocLine.Ramp_Integration_Id__c = oc.Ramp_Integration_Id__c;
otherCostLineList.add(ocLine);
}
if(!otherCostLineList.isEmpty()) {
Database.upsert(otherCostLineList, Other_Cost_Line__c.Fields.Ramp_Integration_Id__c, false);
}
}
} else {
System.debug('HTTP Request failed with status code: ' + response1.getStatusCode());
System.debug('Response body: ' + response1.getBody());
}
} catch (Exception e) {
System.debug('Exception: ' + e.getMessage());
}
} else {
System.debug('Ramp Token is not available. Please check the custom setting.');
}
}
}
This is the class the error is referring to, below is the trigger that is also within the error message,
trigger slack_Other_Cost on Other_Cost__c (after insert, after update, before delete) {
if(trigger.isAfter && trigger.isInsert || trigger.isAfter && trigger.isUpdate || trigger.isBefore && trigger.isDelete) {
slackv2__.utilities.startSubscriptionQueue(trigger.newMap, trigger.oldMap, trigger.operationType, ‘Other_Cost__c’);
}
}
Tried integrating the trigger into the overall class as well as removing the future. The future
needs to be there to get code coverage as well. This is supposed to be a Ramp integration in which it isn’t working on production while seeming to work in sandbox. Any suggestions would be welcome.
Amritpal Rajput is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.