Skip to main content
8 events
when toggle format what by license comment
Jun 28, 2023 at 7:40 vote accept sfdcDev
Jun 28, 2023 at 7:38 comment added sfdcDev I did try the other way suggested by you: Integer lastElementIndex = years.size() - 1; This is working as expected for me, Thanks for your time and effort on this @RubenDG
Jun 28, 2023 at 7:26 history edited RubenDG CC BY-SA 4.0
Explained the issue stated in the comment
Jun 28, 2023 at 7:19 comment added RubenDG @sfdcDev remove(index) returns the element that has been removed from the list, that's why you got that error. You don't need to reassing the result to allYearsList. Please change allYearsList = allYearsList.remove(allYearsList.size() -1 ); to allYearsList.remove(allYearsList.size() -1 );. By the way, you could try my snippet in the developer console
Jun 28, 2023 at 7:16 comment added sfdcDev Here is how i'm trying to use it: List<String> allYearsList = new List<String>{ '2023', '2024', '2025', '2026', '2027' }; allYearsList = allYearsList.remove(allYearsList.size() -1 ); It is giving me error: Illegal assignment from String to List<String>
Jun 28, 2023 at 7:13 history edited RubenDG CC BY-SA 4.0
added 158 characters in body
Jun 28, 2023 at 7:13 comment added sfdcDev Hi @rubenDG, I tried to use remove() but I'm getting this error: Illegal assignment from String to List<String>
Jun 28, 2023 at 7:07 history answered RubenDG CC BY-SA 4.0