• Keerthana
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
Can anyone help me with the test class for below controller. I am trying to get the values of the vf page on save of a new record. standard controller will be null at that point but i need to access the values so I can save it.

public CA_SamsAccountController(ApexPages.StandardController std) {
      samsid = ApexPages.currentPage().getParameters().get('id');
       accid = ApexPages.currentPage().getParameters().get('AccountId');
       if(samsid!=null)
        cont =  (CA_SamsAccount__c)std.getRecord();  --- this line gives me error whenever I try to run the test class if i remove the above if condition
        }
        
        public PageReference save() { 
            string acctype = bc.getSamsAccountTypes();
            cont.CA_Sams_Account_Name__c = str;
            cont.CA_Account__c = acc.id;
            cont.CA_Account_name__c = accname;
            cont.CA_ApiLastName__c = '.api';
            cont.CA_Country__c = selectedCountry;
            cont.CA_contract__c = contractid;
            cont.CA_Parent_ID__c = selectedParent;
            cont.CA_MisPassword__c = temp1;
            cont.CA_ApiPassword__c = temp;
            cont.CA_AccountTypeId__c = acctype;
            con = [select lastname,firstname,phone,email from contact where id=: cont.CA_Contact__c limit 1];   --- I always have cont as null and hence not able to fetch contact
            cont.CA_First_Name__c = con.firstname;
            cont.CA_Last_Name__c = con.lastname;
            cont.CA_Telephone__c = con.phone;
            cont.CA_Email__c = con.email;
            insert cont;
        }
        
         public string getApiorgname()
    {
       string apiorgname = '';
       string api = cont.CA_Sams_Account_Name__c;  --- same issues goes here as well
       list<CA_SamsAccount__c> clist = [select CA_ApiFirstName__c from CA_SamsAccount__c where CA_ApiFirstName__c=: api];
       if(clist.size()>0)
           for(CA_SamsAccount__c c : clist)
                uniquename.add(c.CA_ApiFirstName__c);
       apiorgname = checkpattern(api);
       apiorgname = apiorgname + '.api';
       system.debug('api==='+ apiorgname);
       return apiorgname;
    }

Any quick work around is highly appreciated.
Thanks, Priya