I am pretty stumped - I have a trigger on a custom object that calls a helper class that calls a future callout method. When I call the trigger, the helper class is called but I can't seem to get into the future method with the callout in it. It does work when I try getting into a future method with no callout. Is there a rule with trigger/future/callouts that I am unaware of?
I have also tried calling the future method with the callout from a process builder & @InvocableMethod
with no success.
It seems to really hate the HTTP callout. Any ideas why it is getting caught up on this?
Also - the debug logs are not showing any future calls and nothing is showing in Apex Jobs so I know it is not running at all.
calcLink()
is called from the trigger.
I know the http is working because I am able to invoke it manually with a button that calls to calcLinkGeneratorOnDemand()
I also know having a query in the loop is bad practice but it is not the cause of any blockers, I can see that a.Name
has a value.
global with sharing class CalculatorClass {
public void calcLink(Map<Id, FPC_Funding_del__c> newfundIds, Map<Id, FPC_Funding_del__c> oldFundIds){
for(FPC_Funding_del__c currentFunding : newfundIds.values()){
Account a = [Select Id, Name from Account where Id = :currentFunding.Lender_ID__c LIMIT 1];
if(a.Name.contains('Company Name')){
callTokenizer(currentFunding.Id);
}
}
}
@InvocableMethod
global static void pbToTokenizer(List<Id> fundingIdList) {
system.debug('pbToTokenizer ' + fundingIdList);
if(!System.isFuture()) {
for(Id fID: fundingIdList){
system.debug('what is this value: ' + fID);
callTokenizer(fID);
}
}
}
@future(callout=true)
global static void callTokenizer(Id funderId){
Map<String, String> tokenCredMap = new Map<String, String>();
Id parsedId;
String parsedToken;
try{
//------->Authorization<--------------
HttpRequest req = new HttpRequest();
List<LinkShorteningAPI__C> mcs = LinkShorteningAPI__c.getall().values();
String endpoint = mcs[0].Endpoint__c ;//STS
String apikey = mcs[0].Authorization__c;
String token = mcs[0].Service_Endpoint__c ;
req.setMethod('POST');
req.setEndpoint(Endpoint);
req.setHeader('Content-Type', 'application/json');
req.setBody('"' + apikey + '"');
Http h = new Http();
HttpResponse res = h.send(req);
String authcred = res.getBody();
String svcAuth = 'token ';
svcAuth += authcred;
if(svcAuth == 'token {"Message":"An error has occurred."}'){
throw new GenericException('STS Service is down. Please contact your system admin.');
}
//------->POST<-----------------
HttpRequest req1 = new HttpRequest();
req1.setMethod('POST');
req1.setEndpoint(token);
req1.setHeader('Authorization', svcAuth);
req1.setHeader('Content-Type', 'application/json');
req1.setBody('[{"ID":"' + funderId + '","Properties":{"fundingId":"' + funderId + '"}}]');
Http h1 = new Http();
HttpResponse res1 = h1.send(req1);
String tokencred = res1.getBody();
JSONParser parser = JSON.createParser(tokencred);
//parse and map the returned string
while (parser.nextToken() != null) {
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'Id')) {
parser.nextToken();
parsedId = parser.getText();
}
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'Token')) {
parser.nextToken();
parsedToken = parser.getText();
}
tokenCredMap.put(parsedId,parsedToken);
}
String tokenCredentialString = tokenCredMap.get(funderId);
if(tokenCredentialString != null && tokenCredentialString != ''){
fpc_funding_del__c f = new fpc_funding_del__c(Id= funderId,CalculatorLink__c= tokenCredentialString);
update f;
}
}
catch(Exception e){
system.debug('there has been an error: ' + e);
throw e;
}
}
public PageReference calcLinkGeneratorOnDemand(){
String funderId = ApexPages.currentPage().getParameters().get('funderId');
callTokenizer(funderId);
return new pageReference('/' + funderId);
}
}
a.Name
does not containCompany Name
, the future should start