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
Mack DsozaMack Dsoza 

insert values in custom objects

Suppose I have two custom objects named AMC_Name__c & Fund__c.

In AMC_Name__c object has 1 custom field as,
1) AMC_Field__c Text(200)

In Fund__c object has 3 custom field as,
1) AMCName__c [Lookup(AMC_Name__c)]
2) AMC_Name__c Text(200)
3) Scheme_Name__c Text(200)

Now I putted some values in AMC_Field__c then by using select list i displays all these values as select option.
Now I want that whenever I select any AMC_Field__c field value then I need its appropriate list of values should appear in another select list field which are stored in Scheme_Name__c of Fund__c object.

Like : Reliance is a AMC_Field__c value then Realiance has many scheme_name__c values like Reliance Life insurance, Realiance Mediculam,....etc above 1000 values of Reliance.

So How I will put the data in Scheme_Name__c in Fund__c so that it will not throw any exception/error of this...Bcoz it is not matching ID...

Error is : System.DmlException: Upsert failed. First exception on row 0 with id a0QN00000000HuCMAU; first error: FIELD_INTEGRITY_EXCEPTION, Fund: id value of incorrect type: a06N00000009bJ2IAI: [Fund__c]
Class.InvestmentAssetServices.save: line 98, column 9 Class.InvestmentAssetController.save: line 113, column 13 External entry point


Please tell me how to insert values for this & please specify the query so that it will be easy for me to track the concept...
For more details requirements then plz let me know....so i can give...



Shashikant SharmaShashikant Sharma

The error message suggests me you have assigned a id which either do not belongs to any of AMC_Name__c  object record.

 

You data should be entered like this.

 

Insert data like this

 

AMC_Name__c amc1 =  new AMC_Name__c (Name = 'AMC1');
insert amc1;

AMC_Name__c  amc2 =  new AMC_Name__c (Name = 'AMC2');
insert amc2;

 

Create public property for option and selected values

 

public List<SelectOption> listAMC {get;set;}

 

Public String selectedAMC{get;set;}

 

Fill list of options

 

                //create a list of select options for AMC records
                 listAMC = new List<SelectOption>();
                for(AMC_Name__c amcObj : [Select Id, Name from AMC_Name__c])
                   {
                       //add location in location list
                       listAMC.add(new SelectOption(amcObj.Id, amcObj.Name));
                   }
                   

 

 

Use this option list on your VFP

 

<apex:selectList value="{!slectedAMC}" size="1">
                    <apex:selectOptions value="{!listAMC}"/>
                    </apex:selectList>

 

 

Now when you select any AMC you should pick the AMC records id like then you should query like

 

Fund__c listfuncd = [Select AMCName__c , AMC_Name__c , Scheme_Name__c  from Fund__c where AMCName__c =: slectedAMC];

 But here after I am not able to understand your issue please let me know how do you want to save your date, are you showing this fund without having AMCName__c  lookup ? Do you want to save fund__c record based on selection of both the pick lists?