You need to sign in to do that
Don't have an account?
Bogdan Pascu
Loop must iterate over collection: Id
Hello
I ahve the following controller and I get tghis error on line 27: Loop must iterate over collection: Id. Can someone help me on how to solve this pelase.
public class LightningMapListingsController {
@AuraEnabled(cacheable=true)
public static List<ListingWrapper> getAllListings(){
List<pba__Listing__c> listings = [SELECT Id, Name, pba__ListingPrice_pb__c, MonthlyRent__c,
pba__PropertyType__c, Listing_status__c, pba__Street_pb__c, pba__Address_pb__c, Location__c,
pba__Latitude_pb__c, pba__Longitude_pb__c, pba__PostalCode_pb__c
FROM pba__Listing__c ];
List<ListingWrapper> result = new List<ListingWrapper>();
//process the result in a wrapper format
//which would be easy to pass to map attriutes in lightning component
for(pba__Listing__c listing : listings){
//Creating a listingWrapper object
ListingWrapper listingWrap = new ListingWrapper();
listingWrap.Name = listing.Name;
listingWrap.Price = listing.pba__ListingPrice_pb__c;
listingWrap.MonthlyRent = listing.MonthlyRent__c;
listingWrap.PropertyType = listing.pba__PropertyType__c;
listingWrap.Status = listing.Listing_status__c;
List<ListingAddressWrapper> listingAddressList = new List<ListingAddressWrapper>();
for(pba__Property__c add : listing.pba__Property__c){
ListingAddressWrapper listingAddress = new ListingAddressWrapper();
listingAddress.icon = 'custom:custom31';
listingAddress.title = listing.Name;
//Creating a AddressWrapper object
AddressWrapper addWrap = new AddressWrapper();
addWrap.Latitude = add.pba__Latitude_pb__c;
addWrap.Longitude = add.pba__Longitude_pb__c;
addWrap.Street = add.pba__Street_pb__c;
addWrap.Address = add.pba__Address_pb__c;
addWrap.Location = add.Location__c;
addWrap.PostalCode = add.pba__PostalCode_pb__c;
listingAddress.location = addWrap;
listingAddressList.add(listingAddress);
}
listingWrap.listingAddressList = listingAddressList;
result.add(listingWrap);
}
return result;
}
/**
* Main wrapper class which will hold listing properties
* along with a list of ListingAddressWrapper class which will
* hold multiple location of a listing
* */
public class ListingWrapper{
@AuraEnabled public String Name;
@AuraEnabled public String PropertyType;
@AuraEnabled public String Status;
@AuraEnabled public Decimal Price;
@AuraEnabled public Decimal MonthlyRent;
@AuraEnabled public List<ListingAddressWrapper> listingAddressList;
}
/**
* ListingAddressWrapper class which will hold icon and title of marker
* along with multiple locations
* */
public class ListingAddressWrapper{
@AuraEnabled public String title;
@AuraEnabled public String icon;
@AuraEnabled public AddressWrapper location;
}
/**
* AddressWrapper class to hold address properties
* */
public class AddressWrapper{
@AuraEnabled public String Street;
@AuraEnabled public String Address;
@AuraEnabled public String Location;
@AuraEnabled public String PostalCode;
@AuraEnabled public String Latitude;
@AuraEnabled public String Longitude;
}
}
I ahve the following controller and I get tghis error on line 27: Loop must iterate over collection: Id. Can someone help me on how to solve this pelase.
public class LightningMapListingsController {
@AuraEnabled(cacheable=true)
public static List<ListingWrapper> getAllListings(){
List<pba__Listing__c> listings = [SELECT Id, Name, pba__ListingPrice_pb__c, MonthlyRent__c,
pba__PropertyType__c, Listing_status__c, pba__Street_pb__c, pba__Address_pb__c, Location__c,
pba__Latitude_pb__c, pba__Longitude_pb__c, pba__PostalCode_pb__c
FROM pba__Listing__c ];
List<ListingWrapper> result = new List<ListingWrapper>();
//process the result in a wrapper format
//which would be easy to pass to map attriutes in lightning component
for(pba__Listing__c listing : listings){
//Creating a listingWrapper object
ListingWrapper listingWrap = new ListingWrapper();
listingWrap.Name = listing.Name;
listingWrap.Price = listing.pba__ListingPrice_pb__c;
listingWrap.MonthlyRent = listing.MonthlyRent__c;
listingWrap.PropertyType = listing.pba__PropertyType__c;
listingWrap.Status = listing.Listing_status__c;
List<ListingAddressWrapper> listingAddressList = new List<ListingAddressWrapper>();
for(pba__Property__c add : listing.pba__Property__c){
ListingAddressWrapper listingAddress = new ListingAddressWrapper();
listingAddress.icon = 'custom:custom31';
listingAddress.title = listing.Name;
//Creating a AddressWrapper object
AddressWrapper addWrap = new AddressWrapper();
addWrap.Latitude = add.pba__Latitude_pb__c;
addWrap.Longitude = add.pba__Longitude_pb__c;
addWrap.Street = add.pba__Street_pb__c;
addWrap.Address = add.pba__Address_pb__c;
addWrap.Location = add.Location__c;
addWrap.PostalCode = add.pba__PostalCode_pb__c;
listingAddress.location = addWrap;
listingAddressList.add(listingAddress);
}
listingWrap.listingAddressList = listingAddressList;
result.add(listingWrap);
}
return result;
}
/**
* Main wrapper class which will hold listing properties
* along with a list of ListingAddressWrapper class which will
* hold multiple location of a listing
* */
public class ListingWrapper{
@AuraEnabled public String Name;
@AuraEnabled public String PropertyType;
@AuraEnabled public String Status;
@AuraEnabled public Decimal Price;
@AuraEnabled public Decimal MonthlyRent;
@AuraEnabled public List<ListingAddressWrapper> listingAddressList;
}
/**
* ListingAddressWrapper class which will hold icon and title of marker
* along with multiple locations
* */
public class ListingAddressWrapper{
@AuraEnabled public String title;
@AuraEnabled public String icon;
@AuraEnabled public AddressWrapper location;
}
/**
* AddressWrapper class to hold address properties
* */
public class AddressWrapper{
@AuraEnabled public String Street;
@AuraEnabled public String Address;
@AuraEnabled public String Location;
@AuraEnabled public String PostalCode;
@AuraEnabled public String Latitude;
@AuraEnabled public String Longitude;
}
}