• Karthikeya Mullunja Ramakrishna
  • NEWBIE
  • 10 Points
  • Member since 2016


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
Hello , 

I have developed vf page and emulated it to a managed package for deployment. When moved from a SandBox to Developer org. , The functionality is working as expected. But the problem arises with the mapping of custom fields. The custom fields are annoted as ManagedPackage.Custom_field__c in the code and it does not get mapped to the developer org custom_field . How do I take care of this issue. How do I map the managed package custom filed to the developer org custom field. Any inputs are appreciated.I am newbie to managed packages. 

Public Class ContactUpdateServer { 
    public Contact objContact{get;set;}
    public String currentRecordId {get;set;}
    public Contact con{get;set;}
   
    public List<contact> up = new List<Contact>();
    
    List<ContactCreationCalloutParser.Profile> lstProfilemain = new List<ContactCreationCalloutParser.Profile>() ;
    
    public ContactUpdateServer(ApexPages.StandardController controller) {
     Boolean isValid = False;
    currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
        con = [select SSO_Number__c,Name from Contact where id =: currentRecordId ];
        system.debug('----- sso --- ' +con);
        string searchstring = con.SSO_Number__c;
        if(searchString.length() == 9){
                // Check if search string is 9 digit long numeric value. i.e SSO number.
                   if(searchString.isNumeric()){
                     isValid = True;
       }}
       if(isValid){
       system.debug('----isvalid----' +isValid);
        HttpResponse s = ContactServer();
        string token = ParseJSON(s);
        ContactServer1(token);
        }
    }


    
Public HttpResponse ContactServer() {
       
        REST CALL 
}


    public Pagereference updateContact(){
       Contact objContact = new Contact();
        for(ContactCreationCalloutParser.Profile objProfile : lstProfilemain) 
              {
                
                  objContact.Id = ApexPages.CurrentPage().getparameters().get('id');
                  objContact.Supervisorname__c = objProfile.supervisorname;
                  objContact.Type__c = objProfile.type_Z;
                  objContact.title = objProfile.title;
                  objContact.firstname = objProfile.firstname;
                  objContact.lastName = objProfile.lastName;
                  objContact.Email= objProfile.Email;
                  objContact.SSO_Number__c = objProfile.sso;
                  objContact.Phone= objProfile.workphone;
                  objContact.MailingStreet = objProfile.cdilocation;
                  objContact.Business__c = objProfile.business;
                  objContact.Url__c = objProfile.url;
                  objContact.Jobtitle__c = objProfile.jobtitle;
                  objContact.preferredname__c = objProfile.preferredname; 
                  system.debug('----email --- '+ objContact.Email);}
        try {
       
        update objContact;
        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Update Successful'));
 
      
        system.debug('---- update success ---');

        }
       catch(DmlException e) 
       {
       System.debug('An unexpected error has occurred: ' + e.getMessage());
       Apexpages.addMessage(new ApexPages.message(ApexPages.severity.ERROR, 'Update Failed. Please Contact Administrator.'));
       }
       
     
       return null;

    }
    
    Public Pagereference Goback(){
    Contact objContact = new Contact();
    objContact.Id = ApexPages.CurrentPage().getparameters().get('id');
    PageReference pageRef = new PageReference('/' + objContact.Id);
     pageRef.setRedirect(true);
      return pageRef;
      }
    
}

Please guide me to write a test class for updateContact() function 
My controller class -- 

Public Class ContactUpdateServer { 
    public Contact objContact{get;set;}
    public String currentRecordId {get;set;}
    public Contact con{get;set;}
   
    public List<contact> up = new List<Contact>();
    
    List<ContactCreationCalloutParser.Profile> lstProfilemain = new List<ContactCreationCalloutParser.Profile>() ;
    
    public ContactUpdateServer(ApexPages.StandardController controller) {
     Boolean isValid = False;
    currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
        con = [select SSO_Number__c,Name from Contact where id =: currentRecordId ];
        system.debug('----- sso --- ' +con);
        string searchstring = con.SSO_Number__c;
        if(searchString.length() == 9){
                // Check if search string is 9 digit long numeric value. i.e SSO number.
                   if(searchString.isNumeric()){
                     isValid = True;
       }}
       if(isValid){
       system.debug('----isvalid----' +isValid);
        ContactServer();}
    }
 Public Pagereference Goback(){
    Contact objContact = new Contact();
    objContact.Id = ApexPages.CurrentPage().getparameters().get('id');
    PageReference pageRef = new PageReference('/' + objContact.Id);
     pageRef.setRedirect(true);
      return pageRef;
      }
    

Test Class : 

@isTest 
private Class ContactUpdateServerTest{
static testMethod void test1()
    {
        Contact objContact = new Contact(lastname = 'test',firstname = 'firstTest', title ='titletest',type__c = 'type',SSO_Number__c = '502066194');
        insert objContact;
     
       Test.startTest();
       ContactUpdateServer obj = new ContactUpdateServer(new ApexPages.StandardController(objContact));
      ApexPages.currentPage().getParameters().put(obj.currentRecordId,objContact.id);
       
       system.assertequals(objContact.SSO_Number__c.Length(),9);
       // string searchstring = objContact.SSO_Number__c;
      //  string currentRecordId = objContact.Id;
        

     Test.stopTest();
    }
 
   Static TestMethod  void test2(){
   Contact objContact = new Contact(lastname = 'test',firstname = 'firstTest', title ='titletest',type__c = 'type',SSO_Number__c = '502066194');
        insert objContact;
   
   test.startTest();
   
            ApexPages.StandardController sc = new ApexPages.standardController(objContact);

               ContactUpdateServer obj = new ContactUpdateServer(sc);
               
                PageReference pageRef = obj.Goback();
                  Test.setCurrentPage(pageRef);
                  pageRef.getParameters().put('id',objContact.id);
            
            obj.GoBack();
            
            System.assertNotEquals(null,pageRef);

        test.stopTest();

   }
}


Please suggest where i am going wrong -- I am getting an error "List has no rows for assignment to SObject". 
My controller class -- 

Public Class ContactUpdateServer { 
    public Contact objContact{get;set;}
    public String currentRecordId {get;set;}
    public Contact con{get;set;}
   
    public List<contact> up = new List<Contact>();
    
    List<ContactCreationCalloutParser.Profile> lstProfilemain = new List<ContactCreationCalloutParser.Profile>() ;
    
    public ContactUpdateServer(ApexPages.StandardController controller) {
     Boolean isValid = False;
    currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
        con = [select SSO_Number__c,Name from Contact where id =: currentRecordId ];
        system.debug('----- sso --- ' +con);
        string searchstring = con.SSO_Number__c;
        if(searchString.length() == 9){
                // Check if search string is 9 digit long numeric value. i.e SSO number.
                   if(searchString.isNumeric()){
                     isValid = True;
       }}
       if(isValid){
       system.debug('----isvalid----' +isValid);
        ContactServer();}
    }
 Public Pagereference Goback(){
    Contact objContact = new Contact();
    objContact.Id = ApexPages.CurrentPage().getparameters().get('id');
    PageReference pageRef = new PageReference('/' + objContact.Id);
     pageRef.setRedirect(true);
      return pageRef;
      }
    

Test Class : 

@isTest 
private Class ContactUpdateServerTest{
static testMethod void test1()
    {
        Contact objContact = new Contact(lastname = 'test',firstname = 'firstTest', title ='titletest',type__c = 'type',SSO_Number__c = '502066194');
        insert objContact;
     
       Test.startTest();
       ContactUpdateServer obj = new ContactUpdateServer(new ApexPages.StandardController(objContact));
      ApexPages.currentPage().getParameters().put(obj.currentRecordId,objContact.id);
       
       system.assertequals(objContact.SSO_Number__c.Length(),9);
       // string searchstring = objContact.SSO_Number__c;
      //  string currentRecordId = objContact.Id;
        

     Test.stopTest();
    }
 
   Static TestMethod  void test2(){
   Contact objContact = new Contact(lastname = 'test',firstname = 'firstTest', title ='titletest',type__c = 'type',SSO_Number__c = '502066194');
        insert objContact;
   
   test.startTest();
   
            ApexPages.StandardController sc = new ApexPages.standardController(objContact);

               ContactUpdateServer obj = new ContactUpdateServer(sc);
               
                PageReference pageRef = obj.Goback();
                  Test.setCurrentPage(pageRef);
                  pageRef.getParameters().put('id',objContact.id);
            
            obj.GoBack();
            
            System.assertNotEquals(null,pageRef);

        test.stopTest();

   }
}


Please suggest where i am going wrong -- I am getting an error "List has no rows for assignment to SObject".