You need to sign in to do that
Don't have an account?
Kogila Kenney
Class and Methods
Hi
I am new to Salesforce, trying to understand classes and methods.When I complied the below code it give the below error.
public class Myhelloworld
{
public static void applyDiscount(Book__c[] books)
{
for(list<Book__c[]> b:Books)
{
b.Price__c *=0.9;
}
Error: Compile Error: Initial term of field expression must be a concrete SObject: List<List<Book__c>> at line 7 column 5
Thanks
K.Kogila
I am new to Salesforce, trying to understand classes and methods.When I complied the below code it give the below error.
public class Myhelloworld
{
public static void applyDiscount(Book__c[] books)
{
for(list<Book__c[]> b:Books)
{
b.Price__c *=0.9;
}
Error: Compile Error: Initial term of field expression must be a concrete SObject: List<List<Book__c>> at line 7 column 5
Thanks
K.Kogila
For loop has the below syntax: So for your requirement the code should be something like this:
Here 'list<Book__c>' is the datatype of 'Books' , which has a collection (in this case list) of Book__c objects. And inside the loop, variable 'b' gives you 'Book__c' objects in 'Books' one by one. So, the loop does the below line: for each of the 'Book__c' inside 'Books'
Hope this helped.
Thanks!
All Answers
Additionally, I prefer to use the List<> notation instead of [] because I find it fits better with the Object Oriented nature of Apex
For loop has the below syntax: So for your requirement the code should be something like this:
Here 'list<Book__c>' is the datatype of 'Books' , which has a collection (in this case list) of Book__c objects. And inside the loop, variable 'b' gives you 'Book__c' objects in 'Books' one by one. So, the loop does the below line: for each of the 'Book__c' inside 'Books'
Hope this helped.
Thanks!