I have the following incomplete(this is how far I've gotten so far before the error occurs) method:
public List<assetswrapper> getAssets() //
{
List<Pricebook2> Pbook2Id = [SELECT Name
,ID
FROM Pricebook2
WHERE Name='Support Renewal' AND IsActive=true];
List <PricebookEntry> supportRenewal = [SELECT ID
,ProductCode
,UnitPrice
FROM PricebookEntry
WHERE ProductCode Like 'MAR%'
AND Pricebook2Id in: Pbook2Id];
List <marWrapper> wrapMar = new List<marWrapper>();
for(PricebookEntry pbEntryMar : supportRenewal)
{
wrapMar.marWrapper(pbEntryMar.ID,pbEntryMar.UnitPrice,pbEntryMar.ProductCode);
}
which makes use of the following wrapper class:
public class marWrapper
{
ID marId{get;set;}
double marUnitPrice{get;set;}
String marProductCode{get;set;}
String productCode{get;set;}
public void marWrapper(ID marId, Decimal marUnitPrice, String marProductCode)
{
this.marId=marId;
this.marUnitPrice=marUnitPrice;
this.marProductCode=marProductCode;
this.productCode=marProductCode.substring(4);
}
}
so the error that I get is:
Save error: Method does not exist or incorrect signature: [LIST].marWrapper(Id, Decimal, String). I can tell that the error happens in the following line:
wrapMar.marWrapper(pbEntryMar.ID,pbEntryMar.UnitPrice,pbEntryMar.ProductCode);
All that the getAssets() method is doing so far is:
-
Create a pricebook2 list and a pricebookentry list from which I'm
gathering relevant data. -
Create a new marWrapper list which will be filled with all the data from the PricebookEntry list and add an extra column to the
marWrapper list.
Let me know if more clarification is needed. I feel like I may have butchered the explanation a little.
Best Answer
The problem you have here is that you are trying to call the method
marWrapper
on a list ofmarWrappers
. What you should be doing instead is adding an instance of yourmarWrapper
to the List ofmarWrappers
. For example:Perhaps you meant to make your marWrapper method a constructor (remove the
void
and you're there) which would have allowed you to do this?Or perhaps you wanted a static 'factory' type method?: