• Michael M
  • SMARTIE
  • 925 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 107
    Questions
  • 224
    Replies
Hello, I'm trying to merge 2 person accounts, and getting an error. The error is this:

"Line: 21, Column: 1
System.DmlException: Merge failed. First exception on row 0 with id 0016300000lyQrIAAU; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Unable to create/update fields: Name. Please check the security settings of this field and verify that it is read/write for your profile or permission set.: [Name]"


The code is this:
         //** Tweak your account selection ... aka where clause ..
List<AggregateResult> MyMergeList = [SELECT Count(ID) , name, patient_dob__c
FROM Account 
WHERE IsPersonAccount=TRUE
and name like '%James Dean%'
GROUP BY Name, Patient_DOB__c
HAVING Count(ID) > 1 
ORDER BY Count(ID) desc
LIMIT 2000];


For (AggregateResult Agm : MyMergeList){
   //** Tweak the string parameters to match your preference (confidence)....
   //String accName = '%'+ string.valueOf(agm.get('Name')) + '%';
   String accName = string.valueOf(agm.get('Name'));
   Account ToAccount = [Select id, name from account where name like :accName limit 1];
   Account FromAccount = [Select id, name from account where Id != :ToAccount.Id and name like :accName Limit 1];

   system.debug(LoggingLevel.Info,'*** FromAccount: ' + FromAccount.Name+' ('+FromAccount.Id+')');
   system.debug(LoggingLevel.Info,'*** ToAccount  : ' + ToAccount.Name+' ('+ToAccount.Id+')');
   database.merge(ToAccount , FromAccount );
}
 
Hello, How would I write the SOQL query for the following . I want to get all person accounts where the first name does NOT start with letters A through D? 
Hello, I need to find all of our duplicate person accounts. Specifically, I want to find all Person Accounts where EITHER:
1) Name AND Date of Birth (custom field) match, OR
2) Custom ID Number (custom field) matches.

How would I write both of those SOQL queries? 
I have a simple controller, but am not sure how to write a test class for it. Can anyone please help? 

Here is the controller:
public class LeadsInfoController {
  //capture the user id
    public ID salesRepID {get; set;}
    public List<Lead_Ownership__c> ClsInfo = new List<Lead_Ownership__c>();

    public List<Lead_Ownership__c> getInactiveLeads() {
        ClsInfo = [select Source__c, Facility_Region__c, Lead_Owner__r.name  from Lead_Ownership__c where  ownerId =: salesRepID];
        return ClsInfo;
    }
}
Hello, I have a class that is supposed to send a VF template. The debug logs are saying it is sent, but the email is not going out. Can someone help to fix my email class? What am I missing? 

CLASS
Global class LeadOwnerEmail implements Schedulable{
 Global void execute(SchedulableContext SC) {
        
List<User> uList = [select id, email from user where id in (select  ownerid from community_lead__c)];    
List<Id> listids= new List<Id>();

for(User u :uList) {
 EmailTemplate et=[Select id from EmailTemplate where name = 'LeadOwnerEmail'];
 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();     
mail.setTargetObjectId(u.id);
mail.setSenderDisplayName('Lead Ownership');
 mail.setTemplateId(et.id);
    mail.setSaveAsActivity(false);
 String[] toAddresses = new String[] {u.email};
mail.setToAddresses(toAddresses);
     system.debug('**To Addresses: ' + u.email);
//mail.setReplyTo(liaisonEmail);
       try { 
 Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
           system.debug('**SENT!!!');
   return;
    } catch (Exception e) {
    System.debug(e.getMessage());
   }
    }
}
}


VF EMAIL
<messaging:emailTemplate subject="Your Team's Leads- Owner Assignments" recipientType="User" relatedToType="User">

 <messaging:htmlEmailBody >
   Hi {!RelatedTo.firstName},
  <p>The following leads have not yet been updated:</p>
   <c:leadsinfo ToID="{!RelatedTo.Id}" />
 <p>To update these leads, click on the "Lead Status" field located  in the upper right on the lead page layout.</p>
 </messaging:htmlEmailBody>

</messaging:emailTemplate>
Hello, we have a VF email template. We need to send this out automatically once a month, with a few conditions:
1) It must ONLY send to users that own at least 1 Lead record
2) It must only send ONE email to each of those users
3) it must send once a month (as mentioned)

If it is helpful, here are the details of my VF email. (I am using a component and controller)

VF TEMPLATE
<messaging:emailTemplate subject="Your Team's Leads- Owner Assignments" recipientType="User" relatedToType="User">

 <messaging:htmlEmailBody >
   Hi {!RelatedTo.firstName},
  <p>The following leads have not yet been updated:</p>
   <c:leadsinfo ToID="{!RelatedTo.Id}" />
 <p>To update these leads, click on the "Lead Status" field located  in the upper right on the lead page layout.</p>
 </messaging:htmlEmailBody>

</messaging:emailTemplate>

COMPONENT
<apex:component controller="LeadsInfoController" access="global">
    <apex:attribute name="ToID" type="ID" description="the lead owner ID" assignTo="{!salesRepID}"/>
     
        <apex:datatable value="{!InactiveLeads}" var="item" border="1">
                    <apex:column headervalue=" Name ">
                        <apex:outputText value="{!item.name}"/>
                    </apex:column>

                     <apex:column headervalue=" Created Date ">
                        <apex:outputText value="{!item.CreatedDate}"/>
                    </apex:column>
       </apex:datatable>
</apex:component>

CONTROLLER
public class LeadsInfoController {
  //capture the user id
    public ID salesRepID {get; set;}
    public List<community_lead__c> ClsInfo = new List<community_lead__c>();

    public List<community_lead__c> getInactiveLeads() {
        ClsInfo = [select Name, CreatedDate  from community_lead__c where  ownerId =: salesRepID];
        return ClsInfo;
    }
}
I need to send out a monthly email, to every record owner (for 1 of our custom objects), which contains a list of all of their records, with 3 columns (each different fields on each of those records.) Can you please post an example of code that would work for the correct queries? 
Hello, some of our contacts have multiple email addresses. If we add a custom email field to the Contact object, is there any way to include that AND the standard email field in our campaign, to send it to both of their email addresses? What would you recommend? 
Hello, I know that the standard functionality is that you cannot send a List Email from an org wide address. Is there any possible workaround? We need to be able to do this...

Hello, I'm new to Einstein Bots so this may be a basic question. We need our einstein bot to generate records of a CUSTOM object. I only see choices for standard objects. How can I get to to generate custom object records? 
Hello, I am new to Integrations/ SOAP API, so apologize if this is an elementary question. I received documentation on how to fill the body of the http request, but I realize that I also need to add authorization into the request. I have the key and secret, but I don't know where to put that in the code. 
1. Where would I put it in the request?
2. What would the key/value pair look like in the JSON? 
Here is what my request looks like so far:

       public Object  makePostCallout() {
    Lead ref =[Select Id, firstname, lastname, gender__c, patient_dob__c, patient_ssn__c from Lead where Id = :ApexPages.currentPage().getParameters().get('id')]; 
           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);
           
           Map<string, string> patientInfoMap = new Map<string, string>();
                          patientInfoMap.put('social_security_number', ssnReplace);
                          patientInfoMap.put('birthdate', dob);
                          patientInfoMap.put('gender', genderLetter);
                          patientInfoMap.put('last_name', ref.lastname);
                          patientInfoMap.put('first_name', ref.firstname);
           List<Object> patientInfoList = new List<Object>();
           patientInfoList.add(patientInfoMap);
           
           JSONGenerator gen = JSON.createGenerator(true);   
            gen.writeStartObject();     
             gen.writeStringField('processing_mode', 'Realtime');
             gen.writeStringField('request_type', '270');
             gen.writeStringField('information_source_id', '1');
             gen.writeStringField('submitter_system_id', '2');
             gen.writeStringField('submitter_system_type', 'api');
             gen.writeStringField('submitter_request_id', 'R1');
                 gen.writeStringField('submitter_user_id', '99');
            gen.writeObjectField('subscribers', patientInfoList);
              gen.writeEndObject();   
         String jsonS = gen.getAsString();
        System.debug('***jsonMaterials***'+jsonS);
          
       // Continuation con = new Continuation(40);
        //con.continuationMethod='processResponse';

       HttpRequest req = new HttpRequest();
        req.setEndpoint('https://...(left out)');
        req.setMethod('POST');
        req.setBody(jsonS);
       Http http = new Http();  
       //  this.requestLabel = con.addHttpRequest(req);
     HTTPResponse res = http.send(req);
      // return con; 
           
  String result = null;
    Integer statusCode = res.getStatusCode();
          system.debug('***statusCode is***: ' + statusCode);
   if(statusCode == 200){
             system.debug('***API invoked successfully***');
    result = res.getBody();
          system.debug('***RESULT***: ' + result);
      }   
           return result;   
        
    }
 
Hello, I was wondering if someone can help me write the apex to parse a string like this (changed the details of it, but the concept is still what I need):

https://abc-park-store.facilities.facilities.org/contact-form-block/

From that string, I only want everything between "https://" and ".facilities...". Also, I want to replace the "-" with spaces, and capitalize each word. So from the above string, I would want it to say "Abc Park Store". How can I parse the string as such? Thank you.
Hello, we need to give access to a user to login as other users. However, we do not want them to be able to edit meta-data, and preferably we don't want them to be able to login as system administrators. 

 I am trying to use the "delegated administrator" feature, however, I don't see how to give them the ability to login as other users without giving them the "modify all data" permission, but the problem is that gives them access to metadata. Is there any way around this? 
Hello, I am getting this error message when click on the button on my VF page:
List has no rows for assignment to SObject
Error is in expression '{!makePostCallout}' in component <apex:commandButton> in page emedspage: Class.EMedCalloutsExtension.makePostCallout: line 15, column 1
How can I fix this? 

Here is my page and controller. I will bold the line 15 of the controller. 
PAGE

CONTROLLER
public class EMedCalloutsExtension {
    
    public final Lead referral;
    public String requestLabel;
        public String result {get;set;}
        public List<Object> emedData {get;set;}
    

     Public EMedCalloutsExtension(ApexPages.StandardController stdController){
        this.referral = (Lead)stdController.getRecord();
          //   Lead ref =[Select Id, Name from Lead where Id = :this.referral.id];   
         
  }
       public Object  makePostCallout() {
    Lead ref =[Select Id, firstname, lastname, gender__c, patient_dob__c, patient_ssn__c from Lead where Id = :ApexPages.currentPage().getParameters().get('id')];   
         

           String ssnReplace = ref.Patient_SSN__c.replace('-','');
           String genderLetter;
           if (ref.Gender__c == 'Male'){
               genderLetter = 'M';
           } else if (ref.Gender__c == 'Female'){
               genderLetter = 'F';
           }
            String d = String.valueOf(ref.Patient_DOB__c);
                 d.replace('-','');
           
           Map<string, string> patientInfoMap = new Map<string, string>();
                           patientInfoMap.put('first_name', ref.firstname);
                          patientInfoMap.put('last_name', ref.lastname);
                          patientInfoMap.put('gender', genderLetter);
                          patientInfoMap.put('birthdate', d);
                          patientInfoMap.put('social_security_number', ssnReplace);
           List<Object> patientInfoList = new List<Object>();
           patientInfoList.add(patientInfoMap);
           
           JSONGenerator gen = JSON.createGenerator(true);   
              gen.writeStartObject();     
             gen.writeStringField('processing_mode', 'Realtime');
             gen.writeStringField('request_type', '270');
             gen.writeStringField('information_source_id', '1');
             gen.writeStringField('submitter_system_id', '2');
             gen.writeStringField('submitter_system_type', 'api');
             gen.writeStringField('submitter_request_id', 'R1');
            gen.writeObjectField('subscribers', patientInfoList);
                 gen.writeEndObject();   
            String jsonS = gen.getAsString();
        System.debug('jsonMaterials'+jsonS);
          
        Continuation con = new Continuation(40);
        con.continuationMethod='processResponse';

       HttpRequest req = new HttpRequest();
        req.setEndpoint('https://............(intentionally left out)');
        req.setMethod('POST');
        req.setBody(jsonS);
       Http http = new Http();  
         this.requestLabel = con.addHttpRequest(req);
     // HTTPResponse res = http.send(req);
       return con; 
   
 /*   String result = null;
    Integer statusCode = res.getStatusCode();
          system.debug('statusCode is ' + statusCode);
   if(statusCode == 200){
             system.debug('API invoked successfully');
    result = res.getBody();
      } 
           return result;      */     
    }
    
 public Object processResponse() {  
        HttpResponse response = Continuation.getResponse(this.requestLabel);
 Integer statusCode = response.getStatusCode();
    system.debug('statusCode is ' + statusCode);
        // Set the result variable that is displayed on the Visualforce page
        if (statusCode == 200) {
             system.debug('statusCode is ' + statusCode);
            this.result = response.getBody();
            Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
            emedData = (List<Object>) results.get('emedData');
        }
        return null;
     
     
     
    }

}
 
Hello,
I'm getting this error when I use the below code. The bold part below is the line where it says the error occurred. Here is the error message: 

"execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 00Q3l00000vUpy4EAC; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: [] "


List<id> refToDelete = new List<id>();
Lead refToUpdate;      
Set<Id> oldReferral =  new Set<id>();
Id cldId;
      for (lead thisLead : trigger.new){
          if (thislead.Existing_Referral__c !=null  && thislead.Community_Lead__c !=null ){
              refToDelete.add(thisLead.id);
              oldReferral.add(thislead.existing_referral__c);
              cldId = thislead.Community_Lead__c;
          }
      }
     //delete new referral
          if (!refToDelete.isempty()){
              system.debug('*****DELETED REFERRAL:  ' + reftodelete);
              database.delete(refToDelete);     }
      
     //populate community lead of existing referral
        if (!oldReferral.isempty()){
refToUpdate = [Select Id, community_lead__c from lead where id in :oldReferral];
            list<lead> updateExisting = new list<lead>();
            if (refToUpdate.community_lead__c == null){
              refToUpdate.Community_Lead__c = cldId;
              //updateExisting.add(l);
           system.debug('****************EXISTING LeadTO UPDATE:  ' + reftoupdate);
            } update refToUpdate;  
Hello, in our Recycle bin, we have SEVERAL ContentDocuments (We have scheduled apex that deletes files every day.) Why, then, does the below query return 0 results? Do i need to structure the query differently? 

SELECT id,IsDeleted,LastModifiedDate FROM ContentDocument WHERE IsDeleted = true and lastmodifieddate >= LAST_N_DAYS:2 ALL rows
Hello, we recently delete several files from our org. Some of those files were related to unconverted Leads, and others were deleted from converted Leads. We want to Undelete the files that were related to Converted Leads. How would I write that query?  Thank you.
Hello, we want to have 2 lightning paths, representing 2 different picklists, on the same record type, on the same lightning page. We also want the button at the end of the path, so would need to use the "Lighting:path" component (and not the "Lighting:picklist" component, which seems does not have the button.) Is this possible to do? 
Hello, when I open my developer console, lots of old tabs are open, which I don't want to see/ am not working on right now. How can I control what tabs show by default upon opening the Developer Console? Thank you!
Hello, I have a lightning component that uses liglhtning:card. I need this part of the component to pop up as a small modal window. Is that possible? Here is the snipper from the component:


  <aura:if isTrue="{!v.displayRecordTypes}">   
            <lightning:card>
            <div class="slds-align_absolute-center" >
                <lightning:formattedText class="inlineTitle slds-p-horizontal--medium slds-text-heading--medium" value="New Lead" />
            </div>
            <hr/>
            <lightning:formattedText class="slds-p-horizontal--medium" value="Select a record type"/>
            <div class="slds-p-around--medium">
                <div class="slds-p-left_xx-large">
                    <aura:iteration items="{!v.recordTypes}" var="item">
                        <lightning:input type="radio"  class="slds-radio" label="{!item.Name}" aura:id="radioId" name="{!item.Id}" onclick="{!c.onSelect}" />
                        <div class="slds-p-left_xx-large">
                        <lightning:formattedText value="{!item.Description}" />
                        </div>
                        <br/>
                    </aura:iteration>
                </div>
           </div>
        <footer>
            <div class="modal-footer slds-modal__footer attach-to-bottom">
                <lightning:button label="Cancel" onclick="{!c.cancelDialog}"/>
                <lightning:button label="Next" variant="brand" onclick="{!c.createNewRecord}" disabled="{!v.selectedRecordTypeId==null}"/>
             </div>
        </footer>
           </lightning:card>                  
    </aura:if>
Hello, Would someone be able to assist in writing a test class for the following apex class:
global class purgeFiles implements Schedulable{
    
    global void execute(SchedulableContext SC) {
        
    List<ContentDocumentLink > docs;
        docs = [SELECT Id, Linkedentity.name, Linkedentity.id,ContentDocument.CreatedDate  
                FROM contentDocumentLink 
                WHERE Linkedentityid 
                IN (SELECT Id FROM lead where createddate < Last_N_Days:7 and isconverted = false) ];  
                //may want to change to include ALL leads
                //AND ContentDocument.CreatedDate < Last_N_Days:7];
                if(!docs.isEmpty())
            delete docs;
    }
}

Thank you very much
When I try to drag my VF page to the lightning record page, and try to save, it gives this error: "Component 'Visualforce' has an invalid value for property 'Visualforce Page Name'."  What is the problem?
Hello, I'm trying to merge 2 person accounts, and getting an error. The error is this:

"Line: 21, Column: 1
System.DmlException: Merge failed. First exception on row 0 with id 0016300000lyQrIAAU; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Unable to create/update fields: Name. Please check the security settings of this field and verify that it is read/write for your profile or permission set.: [Name]"


The code is this:
         //** Tweak your account selection ... aka where clause ..
List<AggregateResult> MyMergeList = [SELECT Count(ID) , name, patient_dob__c
FROM Account 
WHERE IsPersonAccount=TRUE
and name like '%James Dean%'
GROUP BY Name, Patient_DOB__c
HAVING Count(ID) > 1 
ORDER BY Count(ID) desc
LIMIT 2000];


For (AggregateResult Agm : MyMergeList){
   //** Tweak the string parameters to match your preference (confidence)....
   //String accName = '%'+ string.valueOf(agm.get('Name')) + '%';
   String accName = string.valueOf(agm.get('Name'));
   Account ToAccount = [Select id, name from account where name like :accName limit 1];
   Account FromAccount = [Select id, name from account where Id != :ToAccount.Id and name like :accName Limit 1];

   system.debug(LoggingLevel.Info,'*** FromAccount: ' + FromAccount.Name+' ('+FromAccount.Id+')');
   system.debug(LoggingLevel.Info,'*** ToAccount  : ' + ToAccount.Name+' ('+ToAccount.Id+')');
   database.merge(ToAccount , FromAccount );
}
 
Hello, How would I write the SOQL query for the following . I want to get all person accounts where the first name does NOT start with letters A through D? 
Hello, I need to find all of our duplicate person accounts. Specifically, I want to find all Person Accounts where EITHER:
1) Name AND Date of Birth (custom field) match, OR
2) Custom ID Number (custom field) matches.

How would I write both of those SOQL queries? 
I have a simple controller, but am not sure how to write a test class for it. Can anyone please help? 

Here is the controller:
public class LeadsInfoController {
  //capture the user id
    public ID salesRepID {get; set;}
    public List<Lead_Ownership__c> ClsInfo = new List<Lead_Ownership__c>();

    public List<Lead_Ownership__c> getInactiveLeads() {
        ClsInfo = [select Source__c, Facility_Region__c, Lead_Owner__r.name  from Lead_Ownership__c where  ownerId =: salesRepID];
        return ClsInfo;
    }
}
Hello, I have a class that is supposed to send a VF template. The debug logs are saying it is sent, but the email is not going out. Can someone help to fix my email class? What am I missing? 

CLASS
Global class LeadOwnerEmail implements Schedulable{
 Global void execute(SchedulableContext SC) {
        
List<User> uList = [select id, email from user where id in (select  ownerid from community_lead__c)];    
List<Id> listids= new List<Id>();

for(User u :uList) {
 EmailTemplate et=[Select id from EmailTemplate where name = 'LeadOwnerEmail'];
 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();     
mail.setTargetObjectId(u.id);
mail.setSenderDisplayName('Lead Ownership');
 mail.setTemplateId(et.id);
    mail.setSaveAsActivity(false);
 String[] toAddresses = new String[] {u.email};
mail.setToAddresses(toAddresses);
     system.debug('**To Addresses: ' + u.email);
//mail.setReplyTo(liaisonEmail);
       try { 
 Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
           system.debug('**SENT!!!');
   return;
    } catch (Exception e) {
    System.debug(e.getMessage());
   }
    }
}
}


VF EMAIL
<messaging:emailTemplate subject="Your Team's Leads- Owner Assignments" recipientType="User" relatedToType="User">

 <messaging:htmlEmailBody >
   Hi {!RelatedTo.firstName},
  <p>The following leads have not yet been updated:</p>
   <c:leadsinfo ToID="{!RelatedTo.Id}" />
 <p>To update these leads, click on the "Lead Status" field located  in the upper right on the lead page layout.</p>
 </messaging:htmlEmailBody>

</messaging:emailTemplate>
Hello, we have a VF email template. We need to send this out automatically once a month, with a few conditions:
1) It must ONLY send to users that own at least 1 Lead record
2) It must only send ONE email to each of those users
3) it must send once a month (as mentioned)

If it is helpful, here are the details of my VF email. (I am using a component and controller)

VF TEMPLATE
<messaging:emailTemplate subject="Your Team's Leads- Owner Assignments" recipientType="User" relatedToType="User">

 <messaging:htmlEmailBody >
   Hi {!RelatedTo.firstName},
  <p>The following leads have not yet been updated:</p>
   <c:leadsinfo ToID="{!RelatedTo.Id}" />
 <p>To update these leads, click on the "Lead Status" field located  in the upper right on the lead page layout.</p>
 </messaging:htmlEmailBody>

</messaging:emailTemplate>

COMPONENT
<apex:component controller="LeadsInfoController" access="global">
    <apex:attribute name="ToID" type="ID" description="the lead owner ID" assignTo="{!salesRepID}"/>
     
        <apex:datatable value="{!InactiveLeads}" var="item" border="1">
                    <apex:column headervalue=" Name ">
                        <apex:outputText value="{!item.name}"/>
                    </apex:column>

                     <apex:column headervalue=" Created Date ">
                        <apex:outputText value="{!item.CreatedDate}"/>
                    </apex:column>
       </apex:datatable>
</apex:component>

CONTROLLER
public class LeadsInfoController {
  //capture the user id
    public ID salesRepID {get; set;}
    public List<community_lead__c> ClsInfo = new List<community_lead__c>();

    public List<community_lead__c> getInactiveLeads() {
        ClsInfo = [select Name, CreatedDate  from community_lead__c where  ownerId =: salesRepID];
        return ClsInfo;
    }
}
I need to send out a monthly email, to every record owner (for 1 of our custom objects), which contains a list of all of their records, with 3 columns (each different fields on each of those records.) Can you please post an example of code that would work for the correct queries? 
Hello, I know that the standard functionality is that you cannot send a List Email from an org wide address. Is there any possible workaround? We need to be able to do this...
Hello, I am new to Integrations/ SOAP API, so apologize if this is an elementary question. I received documentation on how to fill the body of the http request, but I realize that I also need to add authorization into the request. I have the key and secret, but I don't know where to put that in the code. 
1. Where would I put it in the request?
2. What would the key/value pair look like in the JSON? 
Here is what my request looks like so far:

       public Object  makePostCallout() {
    Lead ref =[Select Id, firstname, lastname, gender__c, patient_dob__c, patient_ssn__c from Lead where Id = :ApexPages.currentPage().getParameters().get('id')]; 
           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);
           
           Map<string, string> patientInfoMap = new Map<string, string>();
                          patientInfoMap.put('social_security_number', ssnReplace);
                          patientInfoMap.put('birthdate', dob);
                          patientInfoMap.put('gender', genderLetter);
                          patientInfoMap.put('last_name', ref.lastname);
                          patientInfoMap.put('first_name', ref.firstname);
           List<Object> patientInfoList = new List<Object>();
           patientInfoList.add(patientInfoMap);
           
           JSONGenerator gen = JSON.createGenerator(true);   
            gen.writeStartObject();     
             gen.writeStringField('processing_mode', 'Realtime');
             gen.writeStringField('request_type', '270');
             gen.writeStringField('information_source_id', '1');
             gen.writeStringField('submitter_system_id', '2');
             gen.writeStringField('submitter_system_type', 'api');
             gen.writeStringField('submitter_request_id', 'R1');
                 gen.writeStringField('submitter_user_id', '99');
            gen.writeObjectField('subscribers', patientInfoList);
              gen.writeEndObject();   
         String jsonS = gen.getAsString();
        System.debug('***jsonMaterials***'+jsonS);
          
       // Continuation con = new Continuation(40);
        //con.continuationMethod='processResponse';

       HttpRequest req = new HttpRequest();
        req.setEndpoint('https://...(left out)');
        req.setMethod('POST');
        req.setBody(jsonS);
       Http http = new Http();  
       //  this.requestLabel = con.addHttpRequest(req);
     HTTPResponse res = http.send(req);
      // return con; 
           
  String result = null;
    Integer statusCode = res.getStatusCode();
          system.debug('***statusCode is***: ' + statusCode);
   if(statusCode == 200){
             system.debug('***API invoked successfully***');
    result = res.getBody();
          system.debug('***RESULT***: ' + result);
      }   
           return result;   
        
    }
 

I have a Visualforce template designed to pull a list of leads belonging to the recipient of the email. I'm using a component inside of the VF template to display the leads.

 

It seems the user Id is being lost somewhere in the transition from the VF page to the controller. Consequently I'm getting no records back for display by the component.

 

Email template:

<messaging:emailTemplate subject="Reminder: Inactive Opportunity Reminder for: {!Relatedto.Name}" recipientType="User"
relatedToType="User">
    
    <messaging:htmlEmailBody >
        <p>The following leads have not yet been updated:</p>
        <c:Digilant_InactiveLeads ToID="{!RelatedTo.ID}" />
        
        <p>To update these leads, click on the "Lead Status" field located in the upper right on the lead page layout.</p>
    </messaging:htmlEmailBody>
</messaging:emailTemplate>

 Component:

<apex:component controller="Digilant_findInactiveLeads" access="global">
    <apex:attribute name="ToID" type="ID" description="the lead owner ID" assignTo="{!salesRepID}"/>
    
    <apex:dataTable value="{!InactiveLeads}" var="i_lead">
        <apex:column >
            <apex:facet name="header">Name</apex:facet>
            {!i_lead.Name}
        </apex:column>
        
        <apex:column >
            <apex:facet name="header">Source</apex:facet>
            {!i_lead.LeadSource}
        </apex:column>
        
         <apex:column >
            <apex:facet name="header">Created Date</apex:facet>
            {!i_lead.CreatedDate}
        </apex:column>
    </apex:dataTable>

</apex:component>

 Controller:

public class Digilant_findInactiveLeads {
    public List<Lead> leads {get; set;}
    public ID salesRepID {get; set;}

    public Digilant_findInactiveLeads() {
       leads = [select Name, LeadSource, CreatedDate from Lead from Lead where status = 'Open' AND ownerId =: salesRepID];
    }

    public List<Lead> getInactiveLeads() {
        return leads;
    }
}