function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Wajeed KhanWajeed Khan 

Can any one help me accessing more than 1000 records from my LWC ?

here is an apex code, i have provided limit as 1000 because if i give more than 1000 my LWC not fetching any records,  Any help will be appreciated . Thank you
==================

public with sharing class ND_SupportDirectMailingHCPController {
@readOnly
@RemoteAction
@AuraEnabled(Cacheable=true)
public static String findRecords(
    String lastName,
    String firstName,
    String institution,
    String professionaltitle,
    String address,
    String city,
    String oneKeyID,
    String country,
    String territory,
    String specialty,
    String individualType,
    String brickDescription,
    String workPlaceType,
    String building,
    Boolean isHCP
) {
    Map<String,String> DKSpecialityMap = new Map<String,String>();
    Map<String,String> FISpecialityMap = new Map<String,String>();
    Map<String,String> NOSpecialityMap = new Map<String,String>();
    Map<String,String> SESpecialityMap = new Map<String,String>();

    Map<String,String> DKProfessionalTitleMap = new Map<String,String>();
    Map<String,String> FIProfessionalTitleMap = new Map<String,String>();
    Map<String,String> NOProfessionalTitleMap = new Map<String,String>();
    Map<String,String> SEProfessionalTitleMap = new Map<String,String>();

    Map<String,String> DKIndividualTypeMap = new Map<String,String>();
    Map<String,String> FIIndividualTypeMap = new Map<String,String>();
    Map<String,String> NOIndividualTypeMap = new Map<String,String>();
    Map<String,String> SEIndividualTypeMap = new Map<String,String>();

    Map<String,String> DKWorkplaceTypeMap = new Map<String,String>();
    Map<String,String> FIWorkplaceTypeMap = new Map<String,String>();
    Map<String,String> NOWorkplaceTypeMap = new Map<String,String>();
    Map<String,String> SEWorkplaceTypeMap = new Map<String,String>();

    List<QIDC__OK_Codes_Translation_ims__c> translationsCodes = new List<QIDC__OK_Codes_Translation_ims__c>();
    translationsCodes=[select id,QIDC__OK_Code_ims__r.name,
    QIDC__OK_Code_ims__r.QIDC__Label_ims__c,
    QIDC__Label_ims__c,
    QIDC__OK_Code_ims__r.QIDC__Country_ims__c,
    QIDC__OK_Code_ims__r.QIDC__LIS_Code_ims__c
    from QIDC__OK_Codes_Translation_ims__c
    where
    QIDC__OK_Code_ims__r.QIDC__LIS_Code_ims__c in ('TIT','TYP','SP','LEX')
    and QIDC__OK_Code_ims__r.QIDC__Country_ims__c in ('DK','FI','NO','SE')
    and QIDC__OK_Code_ims__r.QIDC__Is_Active_ims__c =true limit 3000]; 
    
    for(QIDC__OK_Codes_Translation_ims__c eachTransCountry :translationsCodes )
    {
        if(eachTransCountry.QIDC__OK_Code_ims__r.QIDC__Country_ims__c=='DK' && eachTransCountry.QIDC__OK_Code_ims__r.QIDC__LIS_Code_ims__c=='SP')
        {
            DKSpecialityMap.put(eachTransCountry.QIDC__OK_Code_ims__r.Name,eachTransCountry.QIDC__Label_ims__c);
        }
        else if(eachTransCountry.QIDC__OK_Code_ims__r.QIDC__Country_ims__c=='FI' && eachTransCountry.QIDC__OK_Code_ims__r.QIDC__LIS_Code_ims__c=='SP')
        {
            FISpecialityMap.put(eachTransCountry.QIDC__OK_Code_ims__r.Name,eachTransCountry.QIDC__Label_ims__c);
        }
        else if(eachTransCountry.QIDC__OK_Code_ims__r.QIDC__Country_ims__c=='NO' && eachTransCountry.QIDC__OK_Code_ims__r.QIDC__LIS_Code_ims__c=='SP')
        {
            NOSpecialityMap.put(eachTransCountry.QIDC__OK_Code_ims__r.Name,eachTransCountry.QIDC__Label_ims__c);
        }
        else if(eachTransCountry.QIDC__OK_Code_ims__r.QIDC__Country_ims__c=='SE' && eachTransCountry.QIDC__OK_Code_ims__r.QIDC__LIS_Code_ims__c=='SP')
        {
            SESpecialityMap.put(eachTransCountry.QIDC__OK_Code_ims__r.Name,eachTransCountry.QIDC__Label_ims__c);
        }

        if(eachTransCountry.QIDC__OK_Code_ims__r.QIDC__Country_ims__c=='DK' && eachTransCountry.QIDC__OK_Code_ims__r.QIDC__LIS_Code_ims__c=='TIT')
        {
            DKProfessionalTitleMap.put(eachTransCountry.QIDC__OK_Code_ims__r.Name,eachTransCountry.QIDC__Label_ims__c);
        }
        else if(eachTransCountry.QIDC__OK_Code_ims__r.QIDC__Country_ims__c=='FI' && eachTransCountry.QIDC__OK_Code_ims__r.QIDC__LIS_Code_ims__c=='TIT')
        {
            FIProfessionalTitleMap.put(eachTransCountry.QIDC__OK_Code_ims__r.Name,eachTransCountry.QIDC__Label_ims__c);
        }
        else if(eachTransCountry.QIDC__OK_Code_ims__r.QIDC__Country_ims__c=='NO' && eachTransCountry.QIDC__OK_Code_ims__r.QIDC__LIS_Code_ims__c=='TIT')
        {
            NOProfessionalTitleMap.put(eachTransCountry.QIDC__OK_Code_ims__r.Name,eachTransCountry.QIDC__Label_ims__c);
        }
        else if(eachTransCountry.QIDC__OK_Code_ims__r.QIDC__Country_ims__c=='SE' && eachTransCountry.QIDC__OK_Code_ims__r.QIDC__LIS_Code_ims__c=='TIT')
        {
            SEProfessionalTitleMap.put(eachTransCountry.QIDC__OK_Code_ims__r.Name,eachTransCountry.QIDC__Label_ims__c);
        }

        if(eachTransCountry.QIDC__OK_Code_ims__r.QIDC__Country_ims__c=='DK' && eachTransCountry.QIDC__OK_Code_ims__r.QIDC__LIS_Code_ims__c=='TYP')
        {
            DKIndividualTypeMap.put(eachTransCountry.QIDC__OK_Code_ims__r.Name,eachTransCountry.QIDC__Label_ims__c);
        }
        else if(eachTransCountry.QIDC__OK_Code_ims__r.QIDC__Country_ims__c=='FI' && eachTransCountry.QIDC__OK_Code_ims__r.QIDC__LIS_Code_ims__c=='TYP')
        {
            FIIndividualTypeMap.put(eachTransCountry.QIDC__OK_Code_ims__r.Name,eachTransCountry.QIDC__Label_ims__c);
        }
        else if(eachTransCountry.QIDC__OK_Code_ims__r.QIDC__Country_ims__c=='NO' && eachTransCountry.QIDC__OK_Code_ims__r.QIDC__LIS_Code_ims__c=='TYP')
        {
            NOIndividualTypeMap.put(eachTransCountry.QIDC__OK_Code_ims__r.Name,eachTransCountry.QIDC__Label_ims__c);
        }
        else if(eachTransCountry.QIDC__OK_Code_ims__r.QIDC__Country_ims__c=='SE' && eachTransCountry.QIDC__OK_Code_ims__r.QIDC__LIS_Code_ims__c=='TYP')
        {
            SEIndividualTypeMap.put(eachTransCountry.QIDC__OK_Code_ims__r.Name,eachTransCountry.QIDC__Label_ims__c);
        }

        if(eachTransCountry.QIDC__OK_Code_ims__r.QIDC__Country_ims__c=='DK' && eachTransCountry.QIDC__OK_Code_ims__r.QIDC__LIS_Code_ims__c=='LEX')
        {
            DKWorkplaceTypeMap.put(eachTransCountry.QIDC__OK_Code_ims__r.Name,eachTransCountry.QIDC__Label_ims__c);
        }
        else if(eachTransCountry.QIDC__OK_Code_ims__r.QIDC__Country_ims__c=='FI' && eachTransCountry.QIDC__OK_Code_ims__r.QIDC__LIS_Code_ims__c=='LEX')
        {
            FIWorkplaceTypeMap.put(eachTransCountry.QIDC__OK_Code_ims__r.Name,eachTransCountry.QIDC__Label_ims__c);
        }
        else if(eachTransCountry.QIDC__OK_Code_ims__r.QIDC__Country_ims__c=='NO' && eachTransCountry.QIDC__OK_Code_ims__r.QIDC__LIS_Code_ims__c=='LEX')
        {
            NOWorkplaceTypeMap.put(eachTransCountry.QIDC__OK_Code_ims__r.Name,eachTransCountry.QIDC__Label_ims__c);
        }
        else if(eachTransCountry.QIDC__OK_Code_ims__r.QIDC__Country_ims__c=='SE' && eachTransCountry.QIDC__OK_Code_ims__r.QIDC__LIS_Code_ims__c=='LEX')
        {
            SEWorkplaceTypeMap.put(eachTransCountry.QIDC__OK_Code_ims__r.Name,eachTransCountry.QIDC__Label_ims__c);
        }

    }
    List<AccountWrapper> accountWrapperResult = new List<AccountWrapper>();
    Boolean addressUsed = false;
    String query = 'SELECT OCE__ExtendedCategory__c,OKOCE_Country__c,OCE__Specialty__c,OCE__IndividualTypes__c,OCE__UniqueIntegrationID__c,ND_Parent_Account__c,ND_Parent_ID_Name__c, OCE__AccountFullName__c,CHS_Building_Label__c,OCE__ProfessionalTitle__c,ND_Primary_Brick__c,ND_Primary_City__c,ND_Primary_Zip__c, ' +
        ' OCE__ParentAccount__r.Name, ' +
        ' OCE__ParentAccount__r.OCE__ParentAccount__r.Name,' +
        ' OCE__ParentAccount__r.OCE__ParentAccount__r.OCE__ParentAccount__r.Name, ' +
        ' OCE__ParentAccount__r.OCE__ParentAccount__r.OCE__ParentAccount__r.OCE__ParentAccount__r.Name, ' +
        ' OCE__ParentAccount__r.OCE__ParentAccount__r.OCE__ParentAccount__r.OCE__ParentAccount__r.OCE__ParentAccount__r.Name, ' +
        '  OCE__Territories__c, ' +
        ' (' +
            ' SELECT Id, OCE__Country__c, OCE__FormattedAddress__c,OCE__Address__r.CHS_Brick_Description__c,OCE__Address__r.OCE__Building__c  ' +
            ' FROM OCE__AccountAddresses__r ' +
            ' WHERE OCE__IsPrimary__c = true  ';
    if (String.isNotBlank(address)) {
        query += ' AND OCE__FormattedAddress__c LIKE \'%' + String.escapeSingleQuotes(address) + '%\' ';
        addressUsed = true;
    }
    if (String.isNotBlank(country)) {
        query += ' AND OCE__Country__c LIKE \'%' + String.escapeSingleQuotes(country) + '%\' ';
        addressUsed = true;
    }
    if(!isHCP)
    {
        query += ' And OCE__AddressType__c in (\'M\',\'P\') ';
    }
    if (String.isNotBlank(brickDescription)) {
        query += ' AND OCE__Address__r.CHS_Brick_Description__c LIKE \'%' + String.escapeSingleQuotes(brickDescription) + '%\' ';
    }
    if (String.isNotBlank(building)) {
        query += ' AND OCE__Address__r.OCE__Building__c LIKE \'%' + String.escapeSingleQuotes(building) + '%\' ';
    }
    query += ') ' +
        ' FROM Account ' +
        ' WHERE OCE__IsActive__c = true ' +
            ' AND IsPersonAccount = :isHCP ';
    if (String.isNotBlank(lastName)) {
        if (isHCP) {
            query += ' AND LastName LIKE \'%' + String.escapeSingleQuotes(lastName) + '%\' ';
        } else {
            query += ' AND OCE__AccountFullName__c LIKE \'%' + String.escapeSingleQuotes(lastName) + '%\' ';
        }
    }
    if (String.isNotBlank(firstName)) {
        query += ' AND FirstName LIKE \'%' + String.escapeSingleQuotes(firstName) + '%\' ';
    }   
    if (String.isNotBlank(institution)) {
        query += ' AND ND_Parent_ID_Name__c LIKE \'%' + String.escapeSingleQuotes(institution) + '%\' ';
    }
    if (String.isNotBlank(individualType)) {
        query += ' AND toLabel(OCE__IndividualTypes__c) LIKE \'%' + String.escapeSingleQuotes(individualType) + '%\' ';
    }
    if (String.isNotBlank(professionaltitle)) {
        query += ' AND toLabel(OCE__ProfessionalTitle__c) LIKE \'%' + String.escapeSingleQuotes(professionaltitle) + '%\' ';
    }
    if (String.isNotBlank(city)) {
        query += ' AND ND_Primary_City__c LIKE \'%' + String.escapeSingleQuotes(city) + '%\' ';
    }
    if (String.isNotBlank(oneKeyID)) {
        query += ' AND OCE__UniqueIntegrationID__c LIKE \'%' + String.escapeSingleQuotes(oneKeyID) + '%\' ';
    }
    if (String.isNotBlank(workPlaceType)) {
        query += ' AND toLabel(OCE__ExtendedCategory__c)  LIKE \'%' + String.escapeSingleQuotes(workPlaceType) + '%\' ';
    }
    if (String.isNotBlank(territory)) {
        query += ' AND OCE__Territories__c LIKE \'%' + String.escapeSingleQuotes(territory) + '%\' ';
    }
    if (String.isNotBlank(specialty)) 
    {
        query += ' AND (toLabel(OCE__Specialty__c) = :specialty OR toLabel(OCE__Specialty2__c)  = :specialty OR toLabel(OCE__Specialty3__c)  = :specialty)';
    }
    query += 'and OCE__IsPrivacyLaw__c =false and OCE__DoNotMail__c =false and OKOCE_Country__c in (\'DK\',\'FI\',\'NO\',\'SE\') LIMIT 1000 ';
    List<Account> accounts = Database.query(query);
    if (accounts == null) {
        return null;
    }
    System.debug(accounts);
    Set<id> acctIds = new Set<id>();
    List<Account> acctsListToDisplay = new List<Account>();
    if(isHCP)
    {
        for (Account acc : accounts)
        {
            acctIds.add(acc.id);
        }
        List<OCE__Affiliation__c> affLists = new List<OCE__Affiliation__c>();
        affLists=[Select id,OCE__From__c from OCE__Affiliation__c where OCE__IsPrivacyLaw__c =false and OCE__DoNotMail__c =false and OCE__From__c in :acctIds and OCE__IsPrivacyLaw__c=false and OCE__DoNotMail__c=false and CHS_Preferred_Mailing_Flag__c=false limit 10000];
        List<id> affFromIds= new List<id>();
        for(OCE__Affiliation__c thisAff : affLists)
        {
            affFromIds.add(thisAff.OCE__From__c);
        }
        for(Account acc : accounts)
        {
            if(affFromIds.Contains(acc.id))
            {
                acctsListToDisplay.add(acc);
            }
        }
    }
    else{
        acctsListToDisplay=accounts;
    }
    
    
    for (Account acc : acctsListToDisplay) 
    {
        String specTranslated;
        String professionaltitleTranslated;
        String individualTypeTranslated;
        String workPlaceTypeTranslated;
        if(acc.OKOCE_Country__c=='DK')
        {
            specTranslated=DKSpecialityMap.get(acc.OCE__Specialty__c);
            professionaltitleTranslated=DKProfessionalTitleMap.get(acc.OCE__ProfessionalTitle__c);
            individualTypeTranslated=DKIndividualTypeMap.get(acc.OCE__IndividualTypes__c);
            workPlaceTypeTranslated=DKWorkplaceTypeMap.get(acc.OCE__ExtendedCategory__c);
        }
        else if(acc.OKOCE_Country__c=='FI')
        {
            specTranslated=FISpecialityMap.get(acc.OCE__Specialty__c);
            professionaltitleTranslated=FIProfessionalTitleMap.get(acc.OCE__ProfessionalTitle__c);
            individualTypeTranslated=FIIndividualTypeMap.get(acc.OCE__IndividualTypes__c);
            workPlaceTypeTranslated=FIWorkplaceTypeMap.get(acc.OCE__ExtendedCategory__c);
        }
        else if(acc.OKOCE_Country__c=='NO')
        {
            specTranslated=NOSpecialityMap.get(acc.OCE__Specialty__c);
            professionaltitleTranslated=NOProfessionalTitleMap.get(acc.OCE__ProfessionalTitle__c);
            individualTypeTranslated=NOIndividualTypeMap.get(acc.OCE__IndividualTypes__c);
            workPlaceTypeTranslated=NOWorkplaceTypeMap.get(acc.OCE__ExtendedCategory__c);
        }
        else if(acc.OKOCE_Country__c=='SE')
        {
            specTranslated=SESpecialityMap.get(acc.OCE__Specialty__c);
            professionaltitleTranslated=SEProfessionalTitleMap.get(acc.OCE__ProfessionalTitle__c);
            individualTypeTranslated=SEIndividualTypeMap.get(acc.OCE__IndividualTypes__c);
            workPlaceTypeTranslated=SEWorkplaceTypeMap.get(acc.OCE__ExtendedCategory__c);
        }

        if (addressUsed && acc.OCE__AccountAddresses__r.isEmpty()) {
            continue;
        } else {
            String parentName;
            if (String.isNotBlank(acc.OCE__ParentAccount__r.Name)) {
                parentName = acc.OCE__ParentAccount__r.Name;
                if (String.isNotBlank(acc.OCE__ParentAccount__r.OCE__ParentAccount__r.Name)) {
                    parentName += ';' + acc.OCE__ParentAccount__r.OCE__ParentAccount__r.Name;
                    if (String.isNotBlank(acc.OCE__ParentAccount__r.OCE__ParentAccount__r.OCE__ParentAccount__r.Name)) {
                        parentName += ';' + acc.OCE__ParentAccount__r.OCE__ParentAccount__r.OCE__ParentAccount__r.Name;
                    }
                }
            }
            AccountWrapper aw = new AccountWrapper
            (
                acc.OCE__AccountFullName__c,
                acc.OCE__UniqueIntegrationID__c,
                acc.ND_Parent_ID_Name__c,
                parentName,
                acc.OCE__AccountAddresses__r[0].OCE__FormattedAddress__c,
                acc.OCE__AccountAddresses__r[0].OCE__Address__r.CHS_Brick_Description__c,
                acc.ND_Primary_Zip__c,
                acc.ND_Primary_City__c,
                professionaltitleTranslated,
                individualTypeTranslated,
                specTranslated,
                workPlaceTypeTranslated,
                acc.OCE__AccountAddresses__r[0].OCE__Address__r.OCE__Building__c
            );
            accountWrapperResult.add(aw);
        }
    }
    return JSON.serialize(accountWrapperResult);
}

public class AccountWrapper {
    @AuraEnabled
    public String name {get; set;}
    @AuraEnabled
    public String oneKeyID {get; set;}
    @AuraEnabled
    public String institution {get; set;}
    @AuraEnabled
    public String parenNames {get; set;}
    @AuraEnabled
    public String workplaceAddress {get; set;}
    @AuraEnabled
    public String brickDescription {get; set;}
    @AuraEnabled
    public String postalCode {get; set;}
    @AuraEnabled
    public String city {get; set;}
    @AuraEnabled
    public String professionaltitle {get; set;}
    @AuraEnabled
    public String individualType {get; set;}
    @AuraEnabled
    public String specialty {get; set;}
    @AuraEnabled
    public String workPlaceType {get; set;}
    @AuraEnabled
    public String building {get; set;}
    

    public AccountWrapper() {}

    public AccountWrapper(
        String name,
        String oneKeyID,
        String institution,
        String parenNames,
        String workplaceAddress,
        String brickDescription,
        String postalCode,
        String city,
        String professionaltitle,
        String individualType,
        String specialty,
        String workPlaceType,
        String building
    ) {
        this.name = name;
        this.oneKeyID = oneKeyID;
        this.institution = institution;
        this.parenNames = parenNames;
        this.workplaceAddress = workplaceAddress;
        this.brickDescription = brickDescription;
        this.postalCode = postalCode;
        this.city = city;
        this.professionaltitle=professionaltitle;
        this.individualType=individualType;
        this.specialty=specialty;
        this.workPlaceType=workPlaceType;
        this.building=building;
    }
}
}
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Wajeed,

Can you share us the error what you are facing if you are not limiting it to 1000.

Thanks,
 
Wajeed KhanWajeed Khan
Hi Sai Praveen ,

I am not getting any error . If i change the query limit to 10000, it will start loading for few seconds and stops displays no records . Please find the JS below

import { LightningElement, track, api } from 'lwc';
import findRecords from '@salesforce/apex/ND_SupportDirectMailingHCPController.findRecords';
export default class SupportDirectMailingHcp extends LightningElement {
    @track lastName;
    @track firstName;
    @track institution;
    @track specialty;
    @track address;
    @track city;
    @track oneKeyID;
    @track country;
    @track territory;
    @track individualType;
    @track brickDescription;
    @track professionaltitle;
    @track isLoading;
    @track data;
    @track columns;
    columns = [
        { label: 'Person Name', fieldName: 'name' },
        { label: 'One Key ID', fieldName: 'oneKeyID' },
        { label: 'Institution/Workplace name', fieldName: 'institution' },
        { label: 'Parent Institution Names', fieldName: 'parenNames' },
        { label: 'Workplace Address', fieldName: 'workplaceAddress' },
        { label: 'BrickDescription', fieldName: 'brickDescription' },
        { label: 'Postal Code', fieldName: 'postalCode' },
        { label: 'City', fieldName: 'city' },
        { label: 'Professional title', fieldName: 'professionaltitle' },
        { label: 'IndividualType', fieldName: 'individualType' },
        { label: 'Specialty', fieldName: 'specialty' }
    ];
    handleSearch() {
        this.isLoading = true;
        findRecords({
            lastName: this.lastName,
            firstName: this.firstName,
            institution: this.institution,
            specialty: this.specialty,
            address: this.address,
            city: this.city,
            oneKeyID: this.oneKeyID,
            country: this.country,
            territory: this.territory,
            individualType: this.individualType,
            professionaltitle: this.professionaltitle,
            brickDescription: this.brickDescription,
            isHCP: true
        }).then(result => {
            if (result.length > 0) {
                console.log(JSON.parse(result));
                this.data = JSON.parse(result);
            }
            this.isLoading = false;
        }).catch(error => {
            console.log('###err: ' + JSON.stringify(error));
            this.isLoading = false;
        })
    }
    handleFormInputChange(event) {
        if (event.target.name == 'lastName') {
            this.lastName = event.target.value;
        } else if (event.target.name == 'firstName') {
            this.firstName = event.target.value;
        } else if (event.target.name == 'institution') {
            this.institution = event.target.value;
        } else if (event.target.name == 'specialty') {
            this.specialty = event.target.value;
        } else if (event.target.name == 'address') {
            this.address = event.target.value;
        } else if (event.target.name == 'city') {
            this.city = event.target.value;
        } else if (event.target.name == 'oneKeyID') {
            this.oneKeyID = event.target.value;
        } else if (event.target.name == 'country') {
            this.country = event.target.value;
        } else if (event.target.name == 'territory') {
            this.territory = event.target.value;
        } else if (event.target.name == 'individualType') {
            this.individualType = event.target.value;
        } else if (event.target.name == 'brickDescription') {
            this.brickDescription = event.target.value;
        } else if (event.target.name == 'professionaltitle') {
            this.professionaltitle = event.target.value;
        }
    }