• Jeff Bryant 16
  • NEWBIE
  • 25 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 3
    Replies
I have a Lightning component that deletes records as a URL button on a related list. I'm trying to find out how to get the URL for the Lightning component to call it to delete the related list records. Also, in order to delete the records would I have the call the Lightning components URL plus the recordid?
I have a lightning component that is a confirmation modal that will try to call a VF Page that will export information about a batch via a CSV file. The CSV Export VF Page when called will automatically export and download a CSV file with the batch information. I'm trying to redirect to this page from a Lightning Component but failing (the export information is null). The "Continue" code is my attempt to reference the VF Page. I'm assuming I'll have to pass the batch information or page reference when I call the VF Page? Any help is greatly appreciated!
<aura:component controller="ExportToCSVBatchPopup" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    
    <aura:attribute name="loanCount" type="integer"/>
    <aura:attribute name="batchName" type="string"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    <p>Exporting Batch Information.
    </p>
    <br/>
    <footer >
        <div class="slds-align_absolute-center">
            <lightning:button variant="brand" 
                              label="Continue"
                              title="Continue"
                              onclick="{! c.Continue }"/>
        </div>
    </footer>
</aura:component>




({
   doInit: function(component, event, helper) {
      helper.GetCount(component, event, helper);
      helper.GetName(component, event, helper);
   },
 
   Continue: function(component, event, helper) {
       var urlEvent = $A.get("e.force:navigateToURL");
       urlEvent.setParams({
           "url":"/apex/ExporttoCSVBatch",
           "isredirect": "true"
       });
       urlEvent.fire();
   },
})

 
I'm trying to use a custom setting to store email addresses to be used when sending out an Excel file of an Apex job that deactivates users and I'm not exactly sure how to do so. I setup a custom setting as a string and put 'avalidemailaddress@email.com' but I keep getting "Method does not exist or incorrect signature" error.
Currently, my code is
Batch_Settings__c batchSettings = Batch_Settings__c.getInstance();
String deactivationEmails = batchSettings.DeactivatedUsersListemails__c;
// Apex batch code
Messaging.EmailFileAttachment csvAttc = new Messaging.EmailFileAttachment();
.........
email.setToAddresses(deactivationEmails); // This is where the error is occuring
Any help is appreciated!
Is there a simple way of mass cloning a record for testing purposes?
I was thinking of executing anonymous with something like...

Loan__c loanObj = [SELECT Id, Name, Status__c FROM Loan__c WHERE Name = 'L-1983549'];
List<Loan__c> loanList = new List<Loan__c>();
for(integer i = 0; i < 10; i++){
Loan__c loanObjClone = loanObj.clone(true);
loanObjClone.Name = 'loanObjClone ' + i;
loanList.add(loanObjClone);
}
insert loanList;
I'm currently writing a class that will deactivate all users that have not logged in over 60 days.
I am trying to resolve an error I'm getting when trying to deactivate a community user. I have system administrator access but still get "Insufficient Privileges" error.
Could someone point me in the right direction?
Is it possible (and if so, could I get some examples) of running a daily batch job to export a list of all users in the system to a csv file?
I'm working on batchable Apex that will deactivate a user after 90 days without logging in the system. However, if a user hasn't logged in after 90 days and currently is the Default Workflow User, then the batch will fail. Is there any way to check for this or other things like it in code (Web-to-Case Owners or Web-to-Lead Default Creators) or is this something that manually has to be changed and can't be automated? 
I am trying to write a test class that uses the LastLoginDate field but since it is read only I'm not sure as to go about creating data for it. I will share my batch class and what I currently have as a test class...




global class DeactivateUsers implements Database.Batchable<SObject>
{
       dateTime dt = date.today().addDays(-60);
    String pro1 = 'System Administrator';
    public String query = 'SELECT Name, LastLoginDate, Id, user.profile.name From User WHERE IsActive = true AND LastLoginDate <: dt AND user.profile.name <>: pro1 ';

    global Database.querylocator start(Database.BatchableContext bc)
    {
       return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext bc,List<User> records)
    {
        List<User> userList = new List<User>();
        
        for(User r : records)
        {
            User u = (user)r;
            userList.add(u);
        }
        
        if(userList.size() > 0)
        { 
            for(User usr : userList) { usr.isActive = false; }
        }
        update userList;
    }

    global void finish(Database.BatchableContext bc){}
}








@isTest
private class DeactivateUsersTest {
     @testSetup
     static void setup() {
         Profile p = [SELECT Id
                        FROM Profile
                       WHERE Name = 'Standard User'];

         List<User> users = new List<User>();

         for(Integer i = 0; i < 10; i++){
             users.add(new User(Alias = 'Elvis' + i,
                                Email = 'Elvis' + i + '@testorg.com ',
                                EmailEncodingKey = 'UTF-8',
                                LastName = 'Presley',
                                LanguageLocaleKey = 'en_US',
                                LocaleSidKey = 'en_US',
                                ProfileId = p.Id,
                                TimeZoneSidKey = 'America/Los_Angeles',
                                UserName = 'ElvisPresley000' + i + '@testorg.com'));
         }
         insert users;
     }

     static testmethod void testBatch(){
         Test.startTest();
         DeactivateUsers d = new DeactivateUsers();
         Database.executeBatch(d);
         Test.stopTest();
     }
    
    static testmethod void testScheduler(){
        String cronExpr = '0 0 0 15 3 ? 2022';
        
        DeactivateUsersScheduler das = new DeactivateUsersScheduler();
        String jobId = System.schedule('jobTestName', cronExpr, das);
        das.execute(null);
    }
}
I'm trying to create a scheduled batch job that deactivates users that are older than 60 days but it seems to not be working. I believe that it's the query portion that is the culprit. 


global class DeactivateUsers implements Database.Batchable<sObject> {
     global Database.QueryLocator start(Database.BatchableContext bc) {
          return Database.getQueryLocator('SELECT Id, LastLoginDate FROM User WHERE IsActive = TRUE AND LastLoginDate > LAST_N_DAYS:60');
     }
     global void execute(Database.BatchableContext bc, List<User> records){
         List<User> userList = new list<User>{};

         for(User InactiveUser : records){
             InactiveUser.IsActive = false;
             userList.add(InactiveUser);
         }
         update userList;
     }

     global void finish(Database.BatchableContext bc){
         // execute any post-processing operations
     }
}
I'm trying to align two buttons side-by-side more closely User-added imagebut having something fierce of a problem. I've used grids, gutter grids, div widths, etc...

Here is the current look (see attachment) and code. Right now I'm trying to align them through layoutItems


<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global"> 
    <lightning:layout horizontalAlign="right">
        <lightning:layoutItem size="10">
        </lightning:layoutItem>
        <lightning:layoutItem flexibility="auto" padding="around-xxsmall">
            <c:InsertRecord/>
        </lightning:layoutItem >
        <lightning:layoutItem flexibility="auto" padding="around-xxsmall" >
            <c:FlowInsideModal />
        </lightning:layoutItem>
    </lightning:layout>   
</aura:component>






 
I'm currently writing a test class and keep getting "Method does not exist or incorrect signature errors... I'm not certain or confident that I am writing the test class properly...



public class SetEMT {
    ApexPages.StandardController stdCtrl;
    public SetEMT(ApexPages.StandardController controller) {
        stdCtrl=controller;
    }
    List<EmailTemplate> mmts;
    public String mmtid {get; set;}
    public String mmtname {get; set;}
    public String folder {get; set;}
    
    public List<EmailTemplate> getTemplates() {

        if(mmts == null) mmts = [select name, description from EmailTemplate order by Name];              
        return mmts;
    }
    
    public void changeTemplates() {
      if(folder != null && !folder.equals('')) mmts = [select name, description from EmailTemplate where FolderId = :folder order by Name];
      else mmts = [select name, description from EmailTemplate order by Name];
    }
    
    public List<SelectOption> getFolders() {
        List<Folder> folders = [select name, Id from Folder where Type = 'Email' order by name];
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('',''));
        for (Folder f : folders) {
            options.add(new SelectOption(f.Id,f.Name));
        }
        return options;
    }
    public void setTemplate() {
        EAST_Mailing__c mailing = (EAST_Mailing__c)stdCtrl.getRecord();
        mailing.PreApprovedEmailTemplateName__c = mmtname;
        mailing.PreApprovedEmailTemplateLink__c = URL.getSalesforceBaseUrl().toExternalForm() + '/' + mmtid;
        update mailing;
    }
}



@ istest (SeeAllData=true)
public class SetEMTTest
{
    private static testmethod void validate(){
        
        List<EmailTemplate> eList = new List<EmailTemplate>();
        EmailTemplate e = new EmailTemplate (Name = 'Test Template', TemplateType= 'Text');   
        eList.add(e);
       
        ApexPages.StandardSetController setCtr = new ApexPages.StandardSetController(eList);
        SetEMT.setSelected(new EmailTemplate[]{e});
        MassUpdateSimpleController controller = new MassUpdateSimpleController(SetEMT);
        
        controller.getTemplates();
        
        System.assert(controller.getTemplates()!=null);
        
    }
    
}
 
I'm having an issue with "Method does not exist or incorrect signature" on this test class...



Public class AutoConvertLeads
{
    @InvocableMethod
    public static void LeadAssign(List<Id> LeadIds)
    {
        LeadStatus CLeadStatus= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true Limit 1];
        List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();
        for(id currentlead: LeadIds){
                Database.LeadConvert Leadconvert = new Database.LeadConvert();
                Leadconvert.setLeadId(currentlead);                
                Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
                MassLeadconvert.add(Leadconvert);
        }
        
        if (!MassLeadconvert.isEmpty()) {
            List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
        }
    }
}





@isTest
private class AutoConvertLeadsTest {
    @isTest
    public static void testLeadInsert ()
    {
        List<Id> lListIds = new List<Id>();
        List<Lead> lList = new List<Lead>();
        
        Lead objLead = new Lead (LastName = 'Test', Email = 'test@gmail.com', mobilephone = '+1234567890', Company = 'Test company');
        insert objLead; 
        
        lList = [SELECT Id FROM Lead];
        
        for(Lead l : lList){
            lListIds.add(l.Id);
        }
        
        insert lList;
        
        Test.startTest();
        AutoConvertLeadsTest.LeadAssign(lListIds);
        Test.stopTest();
    }
}
 
I'm trying to create a scheduled batch job that deactivates users that are older than 60 days but it seems to not be working. I believe that it's the query portion that is the culprit. 


global class DeactivateUsers implements Database.Batchable<sObject> {
     global Database.QueryLocator start(Database.BatchableContext bc) {
          return Database.getQueryLocator('SELECT Id, LastLoginDate FROM User WHERE IsActive = TRUE AND LastLoginDate > LAST_N_DAYS:60');
     }
     global void execute(Database.BatchableContext bc, List<User> records){
         List<User> userList = new list<User>{};

         for(User InactiveUser : records){
             InactiveUser.IsActive = false;
             userList.add(InactiveUser);
         }
         update userList;
     }

     global void finish(Database.BatchableContext bc){
         // execute any post-processing operations
     }
}
I'm having an issue with "Method does not exist or incorrect signature" on this test class...



Public class AutoConvertLeads
{
    @InvocableMethod
    public static void LeadAssign(List<Id> LeadIds)
    {
        LeadStatus CLeadStatus= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true Limit 1];
        List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();
        for(id currentlead: LeadIds){
                Database.LeadConvert Leadconvert = new Database.LeadConvert();
                Leadconvert.setLeadId(currentlead);                
                Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
                MassLeadconvert.add(Leadconvert);
        }
        
        if (!MassLeadconvert.isEmpty()) {
            List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
        }
    }
}





@isTest
private class AutoConvertLeadsTest {
    @isTest
    public static void testLeadInsert ()
    {
        List<Id> lListIds = new List<Id>();
        List<Lead> lList = new List<Lead>();
        
        Lead objLead = new Lead (LastName = 'Test', Email = 'test@gmail.com', mobilephone = '+1234567890', Company = 'Test company');
        insert objLead; 
        
        lList = [SELECT Id FROM Lead];
        
        for(Lead l : lList){
            lListIds.add(l.Id);
        }
        
        insert lList;
        
        Test.startTest();
        AutoConvertLeadsTest.LeadAssign(lListIds);
        Test.stopTest();
    }
}