I want to update certain field while cloning certain records,please go through the comments in coding section

public class ForeignFilingWizardController {
    public List<String> lstFilingType{get;set;}
    public List<String> lst_RO{get;set;}
    public List<String> lst_ISA{get;set;}
    public List<String> lst_Agent{get;set;}
    public List<String> lst_FilingAgent{get;set;}

    public string serializedFilingTypelist {get;private set;}
    public string serializedCountrylist {get;private set;}
    public string InventionDiscId {get;set;}

    public ForeignFilingWizardController() {          

         InventionDiscId  = ApexPages.currentPage().getParameters().get('ParentPatentId'); 

        if (Schema.sObjectType.Patent__c.fields.Application_Filing_Type__c.isAccessible()){
            lstFilingType =  new List<string>();
            Schema.DescribeFieldResult MetaData_FilingType = Patent__c.Application_Filing_Type__c.getDescribe();        
            List<Schema.PicklistEntry> PicklistEntryFilingType = MetaData_FilingType.getPicklistValues();
            if(PicklistEntryFilingType.size() > 0){ 
                for( Schema.PicklistEntry f : PicklistEntryFilingType)
            // serializedFilingTypelist =  JSON.serializePretty(lstFilingType);

        if (Schema.sObjectType.Country__c.isAccessible()){           
            //List<Country__c> lst_RO_Country = [SELECT Country_Code__c,Name FROM Country__c where IS_RO__c = true]; 
            List<Country__c> lst_RO_Country = [SELECT Country_Code__c,Name FROM Country__c ];             
            if(lst_RO_Country.size() > 0){
                lst_RO = new List<String>();
                for(Country__c objCountry : lst_RO_Country ){            
                    lst_RO.add(objCountry.Name);              //map this value down

            //List<Country__c> lst_ISA_Country = [SELECT Country_Code__c,Name FROM Country__c where IS_ISA__c = true]; 
            List<Country__c> lst_ISA_Country = [SELECT Country_Code__c,Name FROM Country__c]; 
            if(lst_ISA_Country.size() > 0){
                lst_ISA = new List<String>();
                for(Country__c objCountry : lst_RO_Country ){            
                    lst_ISA.add(objCountry.Name);               //map this value down


        if (Schema.sObjectType.FilingAgent__c.isAccessible()){           
            //List<Country__c> lst_RO_Country = [SELECT Country_Code__c,Name FROM Country__c where IS_RO__c = true]; 
            List<FilingAgent__c> lst_PCT_FilingAgent = [SELECT Name FROM FilingAgent__c ];             
            if(lst_PCT_FilingAgent.size() > 0){
                lst_FilingAgent = new List<String>();
                for(FilingAgent__c objFilingAgent : lst_PCT_FilingAgent ){            
                    lst_FilingAgent.add(objFilingAgent.Name);         //map this value down

            //List<Country__c> lst_ISA_Country = [SELECT Country_Code__c,Name FROM Country__c where IS_ISA__c = true]; 



    public class PCT_lineItem {
        String RO;//Country Code - Not the name
        String ISA;
        String Agent;
        String Entity_Type;
        Integer No_Of_Pages;

    Public static string createnonpct(){
    List<string> lst_RO = new List<String>();
     String currentRecordId; 
       currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
         List<Patent__c> ListAssetToInsert = New List<Patent__c>();                 
        for(Patent__c pat : [select id,Title_of_Invention__c from Patent__c where id=:currentRecordId ])
                    Patent__c objAsset = pat.clone();
                    objAsset.Application_Filing_Type__c ='PCT Filing';

                    objAsset.Country__c = lst_RO.Country_c;     //how to map that lst_RO value here,throwing variable lst_RO does not exit
                    objAsset.Country_Code__c = lst_ISA.Country_Code__c; //how to map that lst_ISA value here,throwing variable lst_ISA does not exit
                    objAsset.FilingAgent__c=lst_FilingAgent.FilingAgent__c; //how to map that lst_FilingAgent value here,throwing variable lst_FilingAgent does not exit



            insert ListAssetToInsert;

       return currentRecordId;


1 Answer 1


Right off the bat, I see two things wrong with your code as-is.

  1. lst_RO, lst_ISA, and lst_FilingAgent are class instance variables, and you're trying to access them in a static method
  2. These variables are of type List<String>. lst_RO.Country_Code__c doesn't work because collections themselves don't have fields like Country_Code__c, and if you want to get at a specific value inside a list, you need to index into the list like lstRO[0]

It looks like the code that populates those 3 lists doesn't depend on anything you're getting from a user, so I'd say they (along with the code that populates them) are candidates to be made static. Doing so will grant you the ability to access those variables in your static string createnonpct() method.

That said, you'll still need to fix issue #2. I can't figure out what you're trying to do when you assign Country__c, Country_Code__c, and FilingAgent__c. Given the lists that you are generating, you ostensibly have some method of determining which value you want to use...but with the code and explanation that you've given so far, this is all the help I can provide.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .