• jey well
  • NEWBIE
  • -1 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
var url = 'https://cunning-wolf-lr1avv-dev-ed--c.documentforce.com/servlet/rtaImage?eid=0012w00000Kou4b&feoid=00N2w00000FPu0u&refid=0EM2w000001JN20'

const request = https.get(url, response => {
  console.log(response.statusCode)
  if(response.statusCode === 200){

      let chunks = [];

      response.on('data', chunk => {
          chunks.push(chunk)
      }).on('end', () => {
          const buffer = Buffer.concat(chunks)
          const imageId = book.addImage({
              buffer: buffer,
              extension: 'jpg',
          });

          sheet.addImage(imageId, {
              tl: { col: 0, row: 0 },
          });
      })
  }

I want to get the image in base64 encoding from url in the code. The problem is I get statuscode 302 everytime I run the code. Is there any other way to get the image using node.js?
I have a lightning component which is used to merge the custom lead object which is a duplicate. Here, I have a requirement that if the two selected leads are marked as true for Integrated_Lead__c field, then when clicked on merge, an error should be displayed on the page that "Leads cannot be merged".

Below is my Apex Class method:
 
@auraEnabled
public Static List<cContact> contactsearch(String userinp, String userinput) {
    system.debug(userinput + '=======' + userinp);
    errormsg = false;
    errormsg2 = false;
    contactList = new List<cContact>();
    String query;
    String leadName;
    if (!String.isEmpty(userinp)) {
        leadName = userinp + '%' + userinput + '%';
        system.debug('if====' + leadName);
    } else {
        leadName = '%' + userinput + '%';
        system.debug('else====' + leadName);
    }
    system.debug('leadName===>' + leadName);
    
        for (Lead_Custom__c c : [select Name, First_Name__c, Last_Name__c, Integrated_Lead__c, Id, Cell_Phone__c, Mailing_Street__c, Mailing_City__c, Mailing_State_Province__c from Lead_Custom__c where Name like :leadName]) {
            contactList.add(new cContact(c));
        }
    
    return contactList;
}
@auraEnabled
public Static List<cContact> getresults() {
    return contactList;
}

Lightning Component:
 
<aura:component controller="SearchDuplicateLeads_Lightning" implements="force:appHostable,flexipage:availableForAllPageTypes" access="global">
  
    <aura:handler name="init" value="{!this}" action="{!c.SearchDuplicateLeads}"/>
    <aura:attribute name="userinput" type="String" default=""/>
    <aura:attribute name="userinp" type="String" default=""/>
    <aura:attribute name="render" type="Boolean" default="false"/>
    <aura:attribute name="Spinner" type="boolean" default="false"/>
    
    <aura:attribute name="contactList" type="String[]" />
   
                                <aura:iteration items="{!v.contactList}" var="contacts">
                                    <tr class="slds-hint-parent">
                                        <td role="gridcell" class="mycol">
                                            <lightning:input type="checkbox" aura:id="selected" label=" " value="{!contacts.selected}" onchange="{!c.singleChecked}"/>
                                        </td>
                                        <td role="gridcell">
                                            <ui:outputText value="{!contacts.con.Name}" />
                                        </td>
                                        
                                    </tr>
                                </aura:iteration>
                                </tbody>
                            </table>
                        </div>
                        <lightning:button variant="brand" onclick="{!c.processrecSelected}" label="Next" class="cus-button"/>
                        <lightning:button variant="brand" onclick="{!c.Cancel}" label="Cancel" class="cus-button"/>
                    </aura:renderIf>
                </div>
            </div>
        </div>
    </div>
</aura:component>

Js:
 
processrecSelected: function(component, event, helper) {
    var action = component.get('c.processSelected');
    var strData = JSON.stringify(component.get('v.contactList'));
    console.log('strData===>'+strData);
    action.setParams({ 'contactstr' : strData});
    action.setCallback(this,function(response){
        if (response.getState() === "SUCCESS") {
            var res = response.getReturnValue();
            console.log('res===>'+res.length);
            if(res.length==2){
                redirecttoMerge(res[0].Id,res[1].Id);
            }else if(res.length>2){
                toastEvt('Please select at most two records to proceed');
            }else if(res.length==1){
                toastEvt('Please select at most two records to proceed');
            }else{
                toastEvt('Please select a record to proceed.');
            }
        }
    })
    $A.enqueueAction(action);
    function toastEvt(msg){
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams({
            "title": "Error!",
            "type":"Error",
            "message": msg
        });
        toastEvent.fire();
    }
},

Now, from the above contactList, the merging will be done when two Custom Leads are selected. As per my requirement, if the selected two leads are having Integrated_Lead__c = True, then an error message should be displayed on the screen that "Leads cannot be merged" on click on next button.
​​​​​​​
Can anyone please suggest the changes so that I can get the error message displayed on screen
Hello, 

I have a Apex class that select records where a field > 0. It then loops through these leads and creates a record in a custom object (Metrics__c). Based on the date it creates a record with a 0 value or with a value > 0. The class works great (tested in Dev Console as a batch) but I'm going in cirlces trying to get the test class past 61%. Any help would be appreciated!

Apex Class

global class MetricProcessor implements Database.Batchable <SObject>,Schedulable {
//START METHOD
global Database.QueryLocator start(Database.BatchableContext bc){

    
    String Query= 'select Id, Console_Logins__c, Console_Last_Logins_Date_Field__c, EP_Catalog__c, EP_Catalog_Date_Field__c, EP_Designer__c, EP_Designer_Date_Field__c, EP_Discovery__c,EP_Discovery_Date_Field__c From Lead where Console_Logins__c > 0';

    return Database.getQueryLocator(Query);

        }

//EXECUTE METHOD

global void execute(Database.BatchableContext bc, List<Lead> scope){

    for(Lead l: scope){

        IF (l.Console_Last_Logins_Date_Field__c > (system.today() - 1))
   {
        //insert record
         
    Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='ConsoleLogins',

        Metric_Value__c=l.Console_Logins__c,

        Metric_Date__c= system.today());

       
    insert met;

    }
    Else
       {//insert 0 record
         Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='ConsoleLogins',

        Metric_Value__c= 0,

        Metric_Date__c= system.today());
        
         insert met;
    }
            IF (l.EP_Catalog_Date_Field__c > (system.today() - 1))
   {
        //insert record
         
    Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='EPCatalog',

        Metric_Value__c=l.EP_Catalog__c,

        Metric_Date__c= system.today());

       
    insert met;

    }
    Else
       {//insert 0 record
         Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='EPCatalog',

        Metric_Value__c= 0,

        Metric_Date__c= system.today());
        
         insert met;
    }
            IF (l.EP_Designer_Date_Field__c > (system.today() - 1))
   {
        //insert record
         
    Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='EPDesigner',

        Metric_Value__c=l.EP_Designer__c,

        Metric_Date__c= system.today());

       
    insert met;

    }
    Else
       {//insert 0 record
         Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='EPDesigner',

        Metric_Value__c= 0,

        Metric_Date__c= system.today());
        
         insert met;
    }
            IF (l.EP_Discovery_Date_Field__c > (system.today() - 1))
   {
        //insert record
         
    Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='EPDiscovery',

        Metric_Value__c=l.EP_Discovery__c,

        Metric_Date__c= system.today());

       
    insert met;

    }
    Else
       {//insert 0 record
         Metrics__c met = new Metrics__c(
    
         Lead__c=l.ID,

        Name='EPDiscovery',

        Metric_Value__c= 0,

        Metric_Date__c= system.today());
        
         insert met;
    }
    }

    update scope;

}


   

//FINISH METHOD

global void finish(Database.BatchableContext bc){

    Id job= bc.getJobId();

    System.debug(job);

}

 

 global void execute(SchedulableContext SC) {

 MetricProcessor l= new MetricProcessor();

ID batchprocessid = Database.executeBatch(l);

}

}

Test Class

@istest
private class MetricProcessorTest {
    @istest

    static void tetslead(){
        List<Lead> l= new List<Lead>();
        lead l1= new Lead();
        l1.LastName='Chaytor';
        l1.Company='Solace';
        l1.Status='Working';
        l1.Console_Logins_Last_Modified__c = system.now();
        l1.Console_Logins__c = 2;
        l1.EP_Catalog_Last_Modified__c = system.now()-2;
        l1.EP_Catalog__c = 0;
        l1.EP_Designer_Last_Modified__c = system.now()-2;
        l1.EP_Designer__c = 0;
        l1.EP_Discovery_Last_Modified__c = system.now();
        l1.EP_Discovery__c = 1;
        l1.LeadSource='Dreamforce';
        l.add(l1);
        insert l;
        
      List<Metrics__c> m= new List<Metrics__c>();
        Metrics__c m1= new Metrics__c();
        m1.Lead__c = l1.Id;
        m1.Name = 'ConsoleLogins';
        m1.Metric_Value__c = 2;
       // m1.Metric_Date__c = system.today();
        
        m.add(m1);
        insert m;
        
        List<Metrics__c> m2= new List<Metrics__c>();
        Metrics__c m3= new Metrics__c();
        m3.Lead__c = l1.Id;
        m3.Name = 'EPCatalog';
        m3.Metric_Value__c = 0;
        //m3.Metric_Date__c = system.today()-;
        
        m2.add(m3);
        insert m2;
        
        List<Metrics__c> m4= new List<Metrics__c>();
        Metrics__c m5= new Metrics__c();
        m5.Lead__c = l1.Id;
        m5.Name = 'EPDesigner';
        m5.Metric_Value__c = 0;
        //m3.Metric_Date__c = system.today()-;
        
        m4.add(m5);
        insert m4;
        
        List<Metrics__c> m7= new List<Metrics__c>();
        Metrics__c m8= new Metrics__c();
        m8.Lead__c = l1.Id;
        m8.Name = 'EPDiscovery';
        m8.Metric_Value__c = 1;
        //m3.Metric_Date__c = system.today()-;
        
        m7.add(m8);
        insert m7;

        
        
    Test.startTest();
    MetricProcessor lp= new MetricProcessor();
    Id jobid= Database.executeBatch(lp);
        String sch = '0 0 * * * ?';
 
system.schedule('ReassignAccountOwner', sch, lp);

       
     
    
 
    Test.stopTest();

    }

}