You need to sign in to do that
Don't have an account?
Soql query error!
I have a 2 custom object 1 for customer and other for product.i just wan to retrieve all the possible combination of customer and product, say one customer relates to all product.
if i have 2 customer a,b
3 product c,d,e
i want following combination
Customer product
a c
a d
a e
b c
b d
b e
but none of my query belows working fine can anyone please correct my query, there is no relation between customer and product objects.
Select Name,(select name from newproduct__c) FROM NewCustomer__c
Select Name, newproduct__r.name FROM newcustomer__c.
If there is no relationship between customer and product, you won't be able to build this information in a single query.
To find out all possible combinations of customer and product, you'll have to query all customers, then query all products, then execute a repeat for all customers, and in the body execute another repeat for all products.
E.g.
In the controller: List<NewCustomer__c> customers=[select name from NewCustomer__c]; List<NewProduct__c> products=[select name from NewProduct__c]; In the page: <table> <apex:repeat value="{!customers}" var="customer"> <apex:repeat value="{!products}" var="product"> <tr> <td>{!customer.Name}</td> <td>{!product.Name}</td> </tr> </apex:repeat> </apex:repeat> </table>
Thanks for your help.I have solved my UI part,im sending u my code.Can u please help me out to create save functionality?
I have a custom object named newforecast__c with
1)Customer_entry
2)Item_entry
3)Month
4)Forecastqty
when user click save data should be saved in this above custom object where customer_entry will have customer name,item_entry have item name ,Month will be the header (say jan,feb,mar.....or dec) below user enter forecastqty and forecastqty will be the qty that user will enter.
In case if user enter qty for jan ,feb , nov in single row then there will be 3 seperate (loop) entry will go in above mentioned custom object with same custmer_entry,Item_entry but different month here jan,feb,nov and forecastqty will be respective monthwise qty that he enters.
There is no data binding hence i think we need to use geter,seter but dont know how to loop for table!
Let me know ur feedback.i will wait....
//Controller
public with sharing class ForecastController{
private List<newcustomer__c> Customer;
Private List<newproduct__c> Product;
public List<newcustomer__c> getCustomer() {
Customer=[SELECT name FROM newcustomer__c a ];
return Customer;
}
public List<newproduct__c> getProduct() {
Product=[SELECT name FROM newproduct__c a ];
return Product;
}
}
//Page
<apex:page controller="ForecastController">
<apex:form >
<apex:pageBlock title="Forecast Entry Form">
<apex:pagemessages />
<apex:pageblockButtons >
<apex:commandButton Value="Save" />
<apex:commandButton value="Cancel" />
</apex:pageblockButtons>
<table>
<tr>
<td >Customer</td>
<td >Product</td>
<td align="Center">Jan</td>
<td align="Center">Feb</td>
<td align="Center">Mar</td>
<td align="Center">Apr</td>
</tr>
<apex:repeat value="{!customer}" var="cst">
<apex:repeat value="{!product}" var="prd">
<tr>
<td><apex:inputField value="{!cst.Name}"/></td>
<td><apex:inputField value="{!prd.Name}"/></td>
<td><input maxlength="80" name="janqty" size="3" type="text" /></td>
<td><input maxlength="80" name="febqty" size="3" type="text" /></td>
<td><input maxlength="80" name="marqty" size="3" type="text" /></td>
<td><input maxlength="80" name="aprqty" size="3" type="text" /></td>
</tr>
</apex:repeat>
</apex:repeat>
</table>
</apex:pageBlock>
</apex:form>
</apex:page>
Thanks again.
Rather than having a wrapper class model a single month, you'd need to store all months for the customer product information inside. I'd suggest a class called Month with attributes Name and ForecastQty. Then change the Wrapper class to hold a list of months.
Then you'd build your full list of wrapper classes first, iterate through them in a repeat and then bind on the contents of wrapper.
E.g.
controller: //Controller public with sharing class ForecastController{ private List<Wrapper> wrappers; private List<newcustomer__c> Customer; Private List<newproduct__c> Product; public List<newcustomer__c> getCustomer() { Customer=[SELECT name FROM newcustomer__c a ]; return Customer; } public List<newproduct__c> getProduct() { Product=[SELECT name FROM newproduct__c a ]; return Product; } public List<Wrapper> getWrappers() { wrappers=new List<Wrapper>(); for (NewCustomer__c customer : getCustomers()) { for (NewProduct__c product : getProducts()) { Wrapper wrapper=new Wrapper(); wrapper.product=product.Name; wrapper.customer=customer.Name; wrapper.months[0].Name='Jan'; wrapper.months[0].forecastqty=0.0; wrapper.months[1].Name='Feb'; wrapper.months[1].forecastqty=0.0; // repeat the above for each month. Could create an array // of months and iterate instead if required wrappers.add(wrapper); } } return wrappers; } In the page: <table> <tr> <td >Customer</td> <td >Product</td> <td align="Center">Jan</td> <td align="Center">Feb</td> <td align="Center">Mar</td> <td align="Center">Apr</td> </tr> <apex:repeat value="{!wrapper}" var="wrapper"> <tr> <td><apex:inputField value="{!wrapper.customer}"/></td> <td><apex:inputField value="{!wrapper.product}"/></td> <apex:repeat value="{!wrapper.months}" var="month"> <td><apex:inputText value="{!month.forecastqty}"/></td> </apex:repeat> </tr> </apex:repeat> </table>
Really thanks a lot but the controller gives error
I think we are missing something,please help.
Thanks again.
Im sorry but i didnt created any wrapper class.please help me out how to create wrapper class?
Thanks.
You'll need a wrapper class that contains the customer, product, forecast information etc. That is what this is based on.
I'm happy to take a look at your code once you've had a stab at it, but I can't spend time writing your code from scratch for you - sorry.
Hi,
Yeah you are very much true.i have tried somewhat like below but dont know how to add month and qty to it!
Please suggest some links or something where i can learn the things, as i cant find wrapper class example except adding cheekboxes.I've been struggling to get this work from more then last 2 weeks!Please help me out.
public class MyCategoryWrapper {
public newcustomer__c cst { get; set;}
public newproduct__c Prd{ get; set; }
public MyCategoryWrapper(){
cst = new newcustomer__c();
prd= new newproduct__c();
}
}
A wrapper class is simply a class that wraps Force sObjects with other information. In normal programming parlance, its just a class. I've added a Month example inner class to your code.
public class MyCategoryWrapper { public newcustomer__c cst { get; set;} public newproduct__c Prd{ get; set; } public List<Month> months {get; set;} public MyCategoryWrapper(){ cst = new newcustomer__c(); prd= new newproduct__c(); months=new List<Month>(); } public void addMonth(Month mon) { months.add(month); } public class Month { public String name {get; set;} public Double qty {get; set;} } }
Thanks a lot for all your help. i have some error in page can u please see this
Error: Could not resolve the entity from <apex:inputField> value binding '{!wrp.customer}'. inputField can only be used with SObject fields.
Thanks again.
//page <apex:page controller="ForecastController"> <apex:form > <apex:pageBlock title="Forecast Entry Form"> <apex:pagemessages /> <apex:pageblockButtons > <apex:commandButton Value="Save" /> <apex:commandButton value="Cancel" /> </apex:pageblockButtons> <table> <tr> <td >Customer</td> <td >Product</td> <td align="Center">Jan</td> <td align="Center">Feb</td> <td align="Center">Mar</td> <td align="Center">Apr</td> </tr> <apex:repeat value="{!Wrappers}" var="wrp"> <tr> <td><apex:inputField value="{!wrp.customer}"/></td> <td><apex:inputField value="{!wrp.product}"/></td> <apex:repeat value="{!wrp.months}" var="month"> <td><apex:inputText value="{!month.forecastqty}"/></td> </apex:repeat> </tr> </apex:repeat> </table> </apex:pageBlock> </apex:form> </apex:page>
//controller
public with sharing class ForecastController{ private List<MycategoryWrapper> wrappers; private List<newcustomer__c> Customer; Private List<newproduct__c> Product; public List<newcustomer__c> getCustomer() { Customer=[SELECT name FROM newcustomer__c a ]; return Customer; } public List<newproduct__c> getProduct() { Product=[SELECT name FROM newproduct__c a ]; return Product; } public List<MycategoryWrapper> getWrappers() { wrappers=new List<MycategoryWrapper>(); for (NewCustomer__c customer : getCustomer()) { for (NewProduct__c product : getProduct()) { MycategoryWrapper wrapper=new MycategoryWrapper(); wrapper.prd.name=product.Name; wrapper.cst.name=customer.Name; wrapper.months[0].Name='Jan'; wrapper.months[0].qty=0.0; wrapper.months[1].Name='Feb'; wrapper.months[1].qty=0.0; // repeat the above for each month. Could create an array // of months and iterate instead if required wrappers.add(wrapper); } } return wrappers; } } // wrapper public class MyCategoryWrapper { public newcustomer__c cst { get; set;} public newproduct__c prd { get; set;} public List<Month> months {get; set;} public MyCategoryWrapper(){ cst = new newcustomer__c(); prd= new newproduct__c(); months=new List<Month>(); } public void addMonth(Month mon) { months.add(mon); } public class Month { public String name {get; set;} public Double qty {get; set;} } }
wrp.customer is an entire sObject containing customer details.
You will need to use a field from the sObject, e.g. wrp.customer.Name
I have changed page code as below now getting some other error .please help.
System.ListException: List index out of bounds: 0
Class.ForecastController.getWrappers: line 26, column 28 External entry point
Thanks.
<table>
<tr>
<td >Customer</td>
<td >Product</td>
<td align="Center">Jan</td>
<td align="Center">Feb</td>
<td align="Center">Mar</td>
<td align="Center">Apr</td>
</tr>
<apex:repeat value="{!Wrappers}" var="wrp">
<tr>
<td><apex:inputField value="{!wrp.cst.name}"/></td>
<td><apex:inputField value="{!wrp.prd.name}"/></td>
<apex:repeat value="{!wrp.months}" var="mon">
<td><apex:inputText value="{!mon.qty}"/></td>
</apex:repeat>
</tr>
</apex:repeat>
</table>
Thanks for your everything.
//Error: System.ListException: List index out of bounds: 0 Class.ForecastController.getWrappers: line 26, column 28 External entry point // page <apex:page controller="ForecastController"> <apex:form > <apex:pageBlock title="Forecast Entry Form"> <apex:pagemessages /> <apex:pageblockButtons > <apex:commandButton Value="Save" /> <apex:commandButton value="Cancel" /> </apex:pageblockButtons> <table> <tr> <td >Customer</td> <td >Product</td> <td align="Center">Jan</td> <td align="Center">Feb</td> <td align="Center">Mar</td> <td align="Center">Apr</td> </tr> <apex:repeat value="{!Wrappers}" var="wrp"> <tr> <td><apex:inputField value="{!wrp.cst.name}"/></td> <td><apex:inputField value="{!wrp.prd.name}"/></td> <apex:repeat value="{!wrp.months}" var="mon"> <td><apex:inputText value="{!mon.qty}"/></td> </apex:repeat> </tr> </apex:repeat> </table> </apex:pageBlock> </apex:form> </apex:page> //controller public with sharing class ForecastController{ private List<MycategoryWrapper> wrappers; private List<newcustomer__c> Customer; Private List<newproduct__c> Product; public List<newcustomer__c> getCustomer() { Customer=[SELECT name FROM newcustomer__c a ]; return Customer; } public List<newproduct__c> getProduct() { Product=[SELECT name FROM newproduct__c a ]; return Product; } public List<MycategoryWrapper> getWrappers() { wrappers=new List<MycategoryWrapper>(); for (NewCustomer__c customer : getCustomer()) { for (NewProduct__c product : getProduct()) { MycategoryWrapper wrapper=new MycategoryWrapper(); wrapper.prd.name=product.Name; wrapper.cst.name=customer.Name; wrapper.months[0].Name='Jan'; wrapper.months[0].qty=0.0; wrapper.months[1].Name='Feb'; wrapper.months[1].qty=0.0; // repeat the above for each month. Could create an array // of months and iterate instead if required wrappers.add(wrapper); } } return wrappers; } } // wrapper public class MyCategoryWrapper { public newcustomer__c cst { get; set;} public newproduct__c prd { get; set;} public List<Month> months {get; set;} public MyCategoryWrapper(){ cst = new newcustomer__c(); prd= new newproduct__c(); months=new List<Month>(); } public void addMonth(Month mon) { months.add(mon); } public class Month { public String name {get; set;} public Double qty {get; set;} } }
Change:
wrapper.months[0].Name='Jan';
wrapper.months[0].qty=0.0;
wrapper.months[1].Name='Feb';
wrapper.months[1].qty=0.0;
to:
Month mon=new Month();
mon.name='Jan';
mon.qty=0.0;
wrapper.addMonth(mon);
mon=new Month();
mon.name='Feb';
mon.qty=0.0;
wrapper.addMonth(mon);
Now Getting Error:
Thanks.
Thaks a lot Bob! I will be really very thakful to you and my bad that i couldnt figure that mistake.
Need more of your favour about mapping and its save functionality to a custom object named NewForecast__c having
1)Customer_Entry__c
2)Item_Entry__c
3)Month__c
4)ForecastQty__c
Can u please, finally help me out in this issue?im will be really inspired to move further.
Any suggestion is heartly welcomed.
Thanks again.
Jha
Not sure quite what you are asking here.
Are you wanting to save the contents of your list of wrappers to the database?
yes.you are very much true.
In case if user enter qty for jan ,feb , nov in single row then there will be 3 seperate (loop) entry will go in above mentioned custom object with same custmer_entry,Item_entry but different month here jan,feb,nov and forecastqty will be respective monthwise qty that he enters.
Thanks & Regards,
You'll need to do the following:
Iterate the wrapper object list
For each wrapper object, iterate the month list
For each month, create an instance of your custom object, populate the customer and product from the wrapper object, populate the month name and quantity from the month object.
As before, if you write some code I'll help you to get it working.
Thanks a lot for your evrything.
Do i need to do all that u said to my save method?
I will my best.
Thanks
I reckon you do need to do this in your save method.
Also, you'll need to insert all the new custom objects to the database.
Store them in a list and insert in one go.
I tried as below i know its not upto the mark ,dont know how to iterate for month .
Please do me a favour.im in deep trouble,please i beg you.your this help will be a great help for me.
Moreover when i tried to use my save functionality without month and forecastqty on UI it says error like:
System.NullPointerException: Attempt to de-reference a null object
Class.ForecastController.save: line 59, column 19 External entry point
public with sharing class ForecastController{ private List<MycategoryWrapper> wrappers; private List<newcustomer__c> Customer; Private List<newproduct__c> Product; public List<newcustomer__c> getCustomer() { Customer=[SELECT name FROM newcustomer__c a ]; return Customer; } public List<newproduct__c> getProduct() { Product=[SELECT name FROM newproduct__c a ]; return Product; } public List<MycategoryWrapper> getWrappers() { wrappers=new List<MycategoryWrapper>(); for (NewCustomer__c customer : getCustomer()) { for (NewProduct__c product : getProduct()) { MycategoryWrapper wrapper=new MycategoryWrapper(); wrapper.prd.name=product.Name; wrapper.cst.name=customer.Name; MycategoryWrapper.Month mon=new MycategoryWrapper.Month(); mon.name='Jan'; mon.qty=0.0; wrapper.addMonth(mon); mon =new MycategoryWrapper.Month(); mon.name='Feb'; mon.qty=0.0; wrapper.addMonth(mon); mon =new MycategoryWrapper.Month(); mon.name='Mar'; mon.qty=0.0; wrapper.addMonth(mon); mon =new MycategoryWrapper.Month(); mon.name='Apr'; mon.qty=0.0; wrapper.addMonth(mon); wrappers.add(wrapper) ; } } return wrappers; } public PageReference save() { for( MycategoryWrapper Mywrp:getWrappers()) { NewForecast__c feTmp; feTmp.Customer_Entry__c = Mywrp.cst.name; feTmp.Item_Entry__c = Mywrp.prd.name; /* feTmp.Month__c = Mywrp.mon.name; feTmp.ForecastQty__c = Mywrp.mon.qty; */ insert feTmp; } return null; } }
public PageReference save()
{
for( MycategoryWrapper Mywrp:getWrappers())
{
for (MycategoryWrapper.Month mon L Mywrp.monthList)
{
NewForecast__c feTmp;
feTmp.Customer_Entry__c = Mywrp.cst;
feTmp.Item_Entry__c = Mywrp.prd;
feTmp.Month__c = mon.name;
feTmp.ForecastQty__c = mon.qty;
insert feTmp;
}
}
return null;
}
I have changed some of your code because of error.
Now getting another error as below,please help
//Error
Variable does not exist: monthList at line 59 column 48.
public PageReference save() { for( MycategoryWrapper Mywrp:getWrappers()) { for (MycategoryWrapper.Month mon : Mywrp.monthList) // changed here also removing L & put : { NewForecast__c feTmp; feTmp.Customer_Entry__c = Mywrp.cst.name; feTmp.Item_Entry__c = Mywrp.prd.name; feTmp.Month__c = mon.name; feTmp.ForecastQty__c = string.valueof(mon.qty); //illgal assignment from Double to String at line 65 column 17,so changed insert feTmp; } } return null; }
So this indicates that the property of the wrapper class containing the list of months is not called monthList - you will need to replace this with the correct property name.
As I said before, don't expect just to cut and paste my code in - I'm not building the page myself and sending it to you.