• Onur Kaya 9
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies
Hi,

I have inbound email code, I am collecting emails from Bank Account. I need to fetch the Id from the long text field. I have sample record here. Can anyone please share sample code with me to fetch the Fed Reference #. ?

ABXDEFGHIJKLMN12345
In accordance with your instructions, we have DEBITED your account: **********XXX
for $1.00. If you have any questions, please contact your banker.


Fed Reference #: ABXDEFGHIJKLMN12345


Sender Bank Information:
ABA #: 111111111111
Bank Name: Sample Bank

Thank you in adance.
I am getting this error message: 

caused by: System.AsyncException: Future method cannot be called from a future or batch method: EMedCalloutsExtension.makePostCallout2(List<Id>, String)

Trigger.ReferralCreateContact: line 35, column 1: []

Class.EMedCalloutsExtension.makePostCallout1: line 77, column 1


How can I fix it?

Here is my code  (trigger and class)

TRIGGER
    trigger  ReferralCreateContact on Lead (after insert, after update) { 
        if (trigger.isInsert){
     List<string> leadIds = new List<string>();
    for (lead ref : trigger.new){
      if(system.isFuture()) return;
        if (ref.Epaces_Checked__c != true && (ref.Emed_Request_Id__c == null || ref.Emed_Request_Id__c == '')){
          lead newl = new lead();
          newl.Id = ref.id;
          leadIds.add(newl.id);
         EMedCalloutsExtension.makePostCallout1(leadIds); 
        }
    }}
    
    if (trigger.isUpdate){
      List<string> leadIds = new List<string>();
        for (lead ref: trigger.new){
              //   if(system.isFuture()) return;
            if (ref.Epaces_Checked__c != true && ref.Emed_Request_Id__c != null && trigger.oldmap.get(ref.id).emed_request_id__c == null){
           lead newl = new lead();
          newl.Id = ref.id;
          leadIds.add(newl.id);
         EMedCalloutsExtension.makePostCallout2(leadIds, ref.Emed_Request_Id__c); 
            }
            
        }
    }

CLASS
public class EMedCalloutsExtension {

    public final Lead referral;
    public String requestLabel;
    public String result {get;set;}
    public List<Object> emedData {get;set;}
    
     @future(callout = true)
       public static void  makePostCallout1(list<id> refIds) {
   List <Lead> refs =[Select Id, firstname, lastname, gender__c, patient_dob__c, patient_ssn__c from Lead where Id in :refIds]; 
     List<lead> reftoupdate = new list<lead>();   
           for (lead ref : refs){
           system.debug('***NAME OF REFERRAL***: '+ ref.firstname + ' ' + ref.lastname);
    String ssnReplace; 
           if (ref.Patient_SSN__c != null){
            ssnReplace = ref.Patient_SSN__c.replace('-','');
           }
    String genderLetter;
           if (ref.Gender__c == 'Male'){
               genderLetter = 'M';
           } else if (ref.Gender__c == 'Female'){
               genderLetter = 'F';
           }
           
           String first;
           String second;
           String third;
            String d = String.valueOf(ref.Patient_DOB__c);
           system.debug('***dob string raw: ' + d);
                first = d.substring(0,4);
                second = d.substring(5,7);
                third = d.substring(8,10);
           String dob = first + second + third;
           system.debug('***dob formatted: ' + dob);


 //    Continuation con = new Continuation(40); //number is timeout in seconds
// con.continuationMethod='processResponse';

//below returned 200 success code in anonymous block  
 string reqbody;
     StaticResource r =[Select Id,Body from StaticResource where Name='EMedCalloutBody' limit 1];
      reqBody=r.body.toString();         
       HttpRequest req = new HttpRequest();
           req.setHeader('Content-Type', 'application/json');
                req.setMethod('POST');
                req.setBody(reqBody);
                req.setEndpoint('callout:Emed');
                req.setTimeout(2 * 60 * 1000);
system.debug('ENDPOINT: ' + req.getendpoint());
  //  system.debug('FULL REQUEST: ' + req);
         system.debug('BODY: '+ req.getBody());
         Http http = new Http();
           HttpResponse response = http.send(req);
        if (response.getStatusCode() != 200) {
            System.debug('The status code returned was not expected: ' +
                response.getStatusCode() + ' ' + response.getStatus());
        } else {
            system.debug(response.getstatuscode());
           System.debug(response.getBody());
             string requestId = response.getbody().substringAfter('"request_id": ').substringBefore(',');
            
            ref.Emed_Request_Id__c = requestId;
            reftoupdate.add(ref);
            
        

        }
// this.requestLabel = con.addHttpRequest(req);
          system.debug('FULL REQUEST: ' + req);
// return con;   
       } update reftoupdate;
           return;
       }
   
    
    
     @future(callout = true)
       public static void  makePostCallout2(list<id> refIds, string reqId) {
  
       List <Lead> refs =[Select Id, firstname, lastname, gender__c, patient_dob__c, patient_ssn__c from Lead where Id in :refIds]; 
           for (lead ref : refs){
              string reqbodyResp;   
              StaticResource r2 =[Select Id,Body from StaticResource where Name='EmedResponseBody' limit 1];
               reqbodyResp=r2.body.toString();
              reqbodyResp=reqbodyResp.replace('{{requestId}}', reqId);
                  HttpRequest req2 = new HttpRequest();
           req2.setHeader('Content-Type', 'application/json');
                req2.setMethod('POST');
                req2.setBody(reqbodyResp);
                req2.setEndpoint('callout:Emed_Response');
                req2.setTimeout(2 * 60 * 1000);
            system.debug('ENDPOINT2: ' + req2.getendpoint());
            system.debug('BODY2: '+ req2.getBody());
             Http http2 = new Http();
           HttpResponse response2 = http2.send(req2);
        if (response2.getStatusCode() != 200) {
            System.debug('The status code returned was not expected: ' +
                response2.getStatusCode() + ' ' + response2.getStatus());
        } else {
            system.debug(response2.getstatuscode());
           System.debug(response2.getBody());
lainTextBody(response2.getBody());

        
        }
               
           }
       }
    
    
}


 
Hi,

I have inbound email code, I am collecting emails from Bank Account. I need to fetch the Id from the long text field. I have sample record here. Can anyone please share sample code with me to fetch the Fed Reference #. ?

ABXDEFGHIJKLMN12345
In accordance with your instructions, we have DEBITED your account: **********XXX
for $1.00. If you have any questions, please contact your banker.


Fed Reference #: ABXDEFGHIJKLMN12345


Sender Bank Information:
ABA #: 111111111111
Bank Name: Sample Bank

Thank you in adance.
Hi,
I have a custom visualforce page and I want a to enable a button only after all the required fields have been entered.
Any example code?
Thanks. 
Hello everyone.
 
I've successfully created my first page that required a custom controller extension. Thanks to everyone who help me fumbled through it.
 
I have a current page on a custom object (Implementation__c) with a extension containing SOQL to build a list of related objects (Implementation_Issue__c). The Implementation_Issue__c is a standard object with a look up to Implementation__c, a detail object with a master to Account.
 
The page works perfectly. Originally, I had planned on Rendering the page as PDF and attaching the PDF to an email to our clients. It has been requested that the page becomes the body of the email and not an attachment.
 
I'm struggling here, it doesn't appear I can use <Apex:page> within a visualforce email template. So I'm not sure how can I call the controller extension for my relatedto:Implementation__c object.
 
Anyone have an idea how I can accomplish this? My thoughts are:
 
1. Somehow call my Implementation__c extension within the email template (not sure how or if I can do this)
2. Change the Implementation__c extension to by an extension for the email template (<messaging:emailTemplate> ?)
3. Keep my extension and page as is, but use code to set it as an email (not sure if this is possible either)
 
Again, my goal is to use this page as the body of the email and not as an attachment. I haven't been able to see how to call a custom controller or an extension within an Visualforce Email template, or what the controller for an email template is to create a new extension to give me the functionality I need.
 
Any help, suggestions are most welcomed!