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
Christos KolonisChristos Kolonis 

Render as many records as indicated in Custom Setting

Hello,

I need to create a rest api which calls an external system and gets some info which are viewed in a lightining web component. Till now, the number of records rendered was set by a for loop as above:
 
for(Integer i=0; i<3; i++){
            el_invoices dummyRecord = new el_invoices();
            dummyRecord.InvoiceNumber='0000000001'+string.valueOf(i);
            dummyRecord.InvoicePeriod='09-2020,10-2020';
            dummyRecord.InvoiceType='Clearing Bill';
            dummyRecord.InvoiceTotalAmount=100.00;
            dummyRecord.RelatedServices='Related Services';
....

However, now i need to render as many records as a custom setting indicates. I created a custom setting with a value of number but i don't know how to make it function through this way. Can anyone help?

Thank you!
Best Answer chosen by Christos Kolonis
Christos KolonisChristos Kolonis
I found a workaround like this:
el_PageSize__c ps = [select Page_Size__c from el_PageSize__c];
        Decimal dValue = ps.Page_Size__c;
        Integer pageSizeNum = dValue.intValue();
            for (Integer i=1; i<= pageSizeNum; i++) { 
}

All Answers

abhishek gupta 299abhishek gupta 299

Hi Christos Kolonis,

Try this code :
for (Custom_Setting__c item : Custom_Setting__c .getAll().values()) { 
}

Hope this Helps.
Thanks

Christos KolonisChristos Kolonis
My custom setting is this: 
 
el_PageSize__c ps = [select Page_Size__c from el_PageSize__c];

where the Page_Size__c is the field which indicates a number. So i have to do it like this? :
for (el_PageSize__c item : el_PageSize__c .getAll().values()) { 
}

Thank you for your time
Christos KolonisChristos Kolonis
I found a workaround like this:
el_PageSize__c ps = [select Page_Size__c from el_PageSize__c];
        Decimal dValue = ps.Page_Size__c;
        Integer pageSizeNum = dValue.intValue();
            for (Integer i=1; i<= pageSizeNum; i++) { 
}
This was selected as the best answer