I have a future method called out from a trigger which passes the ifcondition to be evaluated to this method and if this evaluates to true I need to call some classes. The problem here is even if the ifcondition should be evaluated as true, it always ends up in else part i.e false.I am not sure where I am going wrong. Need urgent help on this.
global class TriggerClass
{
public class IntentionalException extends Exception{}
@future (callout=true)
Public static void ifMethod(String postal,Decimal period,Decimal principal,String lname,Decimal sal,String panNo,String LoanType,Decimal Loan,Decimal cibilscore,String operations,String sessionId,String ifcondition)
{
ToolingAPI.SforceService x = new ToolingAPI.SforceService();
x.SessionHeader = new ToolingAPI.SessionHeader_element();
x.SessionHeader.sessionId = UserInfo.getSessionId();
x.SessionHeader.sessionId = sessionId;
System.debug('inside myMethod...');
boolean result=false;
try{
//ToolingAPI.ExecuteAnonymousResult b = x.executeAnonymous(forLoopCode);
ToolingAPI.ExecuteAnonymousResult b = x.executeAnonymous(ifcondition);
//ToolingAPI.ExecuteAnonymousResult toolingResult = x.executeAnonymousUnencoded(ifcondition);
}
catch(IntentionalException ie) {
result = (ie.getMessage() == 'true') ? True : False;
}
//System.debug( 'result---' + b);
System.debug('exiting myMethod...');
System.debug('result is---------------------------------------'+result);
if(result==true)
{
System.debug('-----------In if loop');
//execute opearations belonging to the criteria Id
}
else{
System.debug('-------------In else loop');
//reject loan
}
}
}
This is my trigger which is calling the above code:
trigger appTrigger on Applicant__c (after insert,after update) {
public CustBusinessPro__Criteria__c Criteria {get;set;}
system.debug('---------- hello');
public List < CustBusinessPro__Criteria__c > criteriaList {get;set;}
ToolingAPI.SforceService x = new ToolingAPI.SforceService();
x.SessionHeader = new ToolingAPI.SessionHeader_element();
x.SessionHeader.sessionId = UserInfo.getSessionId();
String sessionId = UserInfo.getSessionId();
String test;
criteriaList=new LIST<CustBusinessPro__Criteria__c>([SELECT Id,Name,CustBusinessPro__Operations__c,CustBusinessPro__Where_Clause__c FROM CustBusinessPro__Criteria__c] );
for (CustBusinessPro__Criteria__c cd: criteriaList) {
for(CustBusinessPro__Applicant__c app:Trigger.new)
{
// System.debug('>>>>>>>>>>>>>>>>>'+ cd.CustBusinessPro__Where_Clause__c);
test=cd.CustBusinessPro__Where_Clause__c;
test=test.replaceAll('AND','&&');
test=test.replaceAll('OR','||');
test=test.replaceAll('CustBusinessPro__Age__c',String.valueOf(app.CustBusinessPro__Age__c));
test=test.replaceAll('CustBusinessPro__Gender__c ','\'' + app.CustBusinessPro__Gender__c + '\'');
test=test.replaceAll('CustBusinessPro__Country__c','\'' + app.CustBusinessPro__Country__c + '\'');
test=test.replaceAll('CustBusinessPro__City__c','\'' + app.CustBusinessPro__City__c + '\'');
test=test.replaceAll('CustBusinessPro__Salary__c','\'' + String.valueOf(app.CustBusinessPro__Salary__c) + '\'');
test=test.replaceAll('CustBusinessPro__Marital_Status__c','\'' + app.CustBusinessPro__Marital_Status__c + '\'');
System.debug('>>>>>>>>>>>>>>>>>'+ test);
String ifcondition='if('+test+')';
System.debug('---------------ifcondition'+ifcondition);
TriggerClass.ifMethod(app.CustBusinessPro__Postal_Code__c,app.CustBusinessPro__Loan_Tenure__c,app.CustBusinessPro__Loan_Amount__c,app.CustBusinessPro__Last_Name__c,app.CustBusinessPro__Salary__c,app.CustBusinessPro__PAN__c,app.CustBusinessPro__Type_of_Loan__c,app.CustBusinessPro__Loan_Amount__c,app.CustBusinessPro__CIBIL_Score__c,cd.CustBusinessPro__Operations__c,sessionId,ifcondition);
}
}
}