You need to sign in to do that
Don't have an account?
Saving a list
Hi,
I have implemented a case in which a user can select a list of Feature object to add to a Car object. Right now ,the apex code generates a dynamic list of feature objects that the user can select and add to a custom list. My problem is that I would like this list to be tied to the Car object permanently after the user makes it (right now if the user refreshes the page, everything is reset and the list is emptied). How do I go about making this apex variable persistant to the custom object? Essentially it would be a List variable that gets saved into the database with the Car Object, kind of how the custom fields are.
Thanks!
Hi Vivo,
Please find code with the below assumptions;
car object:- car__c
feature obect: feature__c
junctionObject :- yourJunctionoObject__c(replace this with your junction object name)
all you to do is create a class and then the VF page with the below code and then open this link /apex/youVfpagename?carId=(Id of an existing Car record),
I hope this help!
-ಸಮಿರ್
All Answers
Ram
Hi,
From what you have mentioned I gather that there is a Many -to- Many relationship between Car and feature object i.e., one car can be associated to many features and similarly one feature can be associated to many Cars. In this case you would need a junction object like Car_Feature_Association. In this junction object create 2 master detail relations one to cars and another to features. This junction object is seen as a related list both the objects.
Now you display the list of features for a particular car ,users selects only 2 features out of the list and clicks on save. Now You have to add 2 records in the junction object where you populate the 2 master detail relationship fields one with Car Id and other with the feature Id.
Hope this helps!
-ಸಮಿರ್
Thanks for your help so far!
I already have the junction object set up actually. I am looking for a visualforce code that will directly add the junction object to the related list. I basically need a way to access the individual elements in the related list for the Car__c object, that allows me to remove/add Feature__c objects to it. Any thoughts on this?
Thanks again for your help
Car__c car = new Car__c();
// set up car and insert it
insert car;
Feature__c f = new Feature__c();
f.car__c = car.id;
f.field1 = some user input
//assign other fields to feature
insert f;
Hope this helps.
Ram
Hi Vivo,
Please find code with the below assumptions;
car object:- car__c
feature obect: feature__c
junctionObject :- yourJunctionoObject__c(replace this with your junction object name)
all you to do is create a class and then the VF page with the below code and then open this link /apex/youVfpagename?carId=(Id of an existing Car record),
I hope this help!
-ಸಮಿರ್