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
Hector AlanisHector Alanis 

How to fill wrapper class attributes

I want to to fill this class  but I can't reach wrapper attributes:
 
public class PricingMotor_cls {
	public Double cost;
	public OrderItems[] orderItems;

//Wrapper for OrderItem
	public class OrderItems {

		public Integer quantity;
		public CashAmounts creditAmounts;
	}

	//Wrapper CashAmounts 
	public class CashAmounts {
		public Double totalPrice;
		public OrderConditions[] orderConditions;
	}
        //Wrapper OrderConditions 
        public class OrderConditions {
		public String conditionType;
		public Decimal amount;
	}

}

I try 
List<ISSM_DeserializePricingMotor_cls.OrderItems> abc = new ISSM_DeserializePricingMotor_cls.OrderItems[1];
abc[0].quantity = 1;

but told me:  FATAL_ERROR System.ListException: List index out of bounds

what I'm doing wrong...
how I fill all object?
Best Answer chosen by Hector Alanis
Adilson Arcoverde JrAdilson Arcoverde Jr
Hi Hector,

To accomplish what you want, you have to create a new instance of PricingMotor_cls and then create a new instance of List<OrderItems>. Try this code below:
 
PricingMotor_cls  pm = new PricingMotor_cls ();
pm.orderItems = new List<OrderItems>();
OrderItems item1 = new OrderItems();
item1.quantity = 1;
pm.orderItems.add( item1 );

I hope you find this solution helpful. If it does, please mark as Best Answer to help other too.

Regards.

 

All Answers

Adilson Arcoverde JrAdilson Arcoverde Jr
Hi Hector,

To accomplish what you want, you have to create a new instance of PricingMotor_cls and then create a new instance of List<OrderItems>. Try this code below:
 
PricingMotor_cls  pm = new PricingMotor_cls ();
pm.orderItems = new List<OrderItems>();
OrderItems item1 = new OrderItems();
item1.quantity = 1;
pm.orderItems.add( item1 );

I hope you find this solution helpful. If it does, please mark as Best Answer to help other too.

Regards.

 
This was selected as the best answer
Tejkaran Singh AnandTejkaran Singh Anand
Hi Adilson,
I am running into a similary query. What if there is another list inside orderItems. How can I add to it?