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
Sriram MSriram M 

Problem in Deploying files from Sandbox to Deploy

Hi all,

I am facing the following issue when making a deploy from a sandbox environment.

Deployment issue

From the problem, I could see the privilege is not sufficient to validate or deploy the test classes. 
But I have system administrator privilege to the environment. Not sure how to proceed with this.

Thanks in advance.
Sriram
Best Answer chosen by Sriram M
bob_buzzardbob_buzzard
The insufficient privilege errors look to be related to knowledge articles - does your user account have the knowledge feature license?  If not, you won't be able to do things like insert an article in a unit test.

All Answers

bob_buzzardbob_buzzard
The insufficient privilege errors look to be related to knowledge articles - does your user account have the knowledge feature license?  If not, you won't be able to do things like insert an article in a unit test.
This was selected as the best answer
Sriram MSriram M
Thanks for the quick response Bob.

My account do not have the Knowledge user privilege. Should I try the deploy with an account with Knowledge user privilege?

Thanks,
Sriram
bob_buzzardbob_buzzard
Yeah - we hit the same thing from time to time as not everyone has a knowledge feature license.  I doubt it will solve your null pointer exceptions, but should resolve the insufficient privileges problem.
Sriram MSriram M
Thank you Bob. 

The Knowledge user licence issue part is fixed. I wonder why the Null pointer exception is occuring. Since the same Controller code and its associated Test classes are running fine in the sandbox. But it is throwing the Null pointer exception when I tried to validate the Inbound change set before deploying.

Below is my Controller class
/*
* Controller Class for Case Creation and Case Confirmation
*/
public without sharing class CreateCaseController {
    public string caseIDVal = '';
    public Integer existingContactID;
    public Contact conRec{get; set;}
    public Case caseRec{get; set;}
    public String selectLanguage {get; set;}
    public String contactEmail{get; set;}
    public string langPref = ApexPages.currentPage().getHeaders().get('Accept-Language');
    List<Contact> getContactDetails;
    List<Case> CaseList;
    
    /*Constructor for the Controller Class*/
    public CreateCaseController(){
        conRec = new Contact(); 
        caseRec = new Case(); 
    }
    /*Function to return Language preference from browser*/
    public string getLangPref(){
        return langPref;
    }
    /*Function for changing the Page language on Manual language selection*/
    public void changeLanguage() {
        Cookie curLang = ApexPages.currentPage().getCookies().get('curLang');
        if(selectLanguage == null) {
            selectLanguage = langPref.substring(0,2);
            if(selectLanguage == 'nl') {
                selectLanguage = 'nl_NL';
            }
        }
        curLang = new Cookie('curLang',selectLanguage,null,-1,false);
        setSelectLanguage(curLang);
        ApexPages.currentPage().setCookies(new Cookie[]{curLang});
    }
    /*Function for getting the currently selected language*/
    public String getCurrentLanguage(){
        Cookie currentLanguage = ApexPages.currentPage().getCookies().get('curLang');
        if(currentLanguage == null) {
            if(langPref.substring(0,2) == 'nl') {
                return 'nl_NL';
            }
            else {
                return langPref.substring(0,2);
            }
        }
        return currentLanguage.getValue();
    }
    /*Function for Setting the selected language into the Dropdown box*/
    public void setSelectLanguage(Cookie selLang)
    {
        selectLanguage = selLang.getValue();
    }
    /*Function for Creating case and creating a new / update an existing contact*/
    public pagereference saveData(){
        if(conRec.lastName== null || caseRec.SuppliedCompany == null  || contactEmail == null  || caseRec.Subject == null  || caseRec.Description == null  || caseRec.Impact__c == '--What is the impact?--') {
            PageReference pageRef = new PageReference('/createcase');
            return pageRef;
        }
        else
        {
            createContactRecord();
            caseRec.ContactId = conRec.Id;
            if(caseRec.Impact__c == 'Just me') {
                caseRec.Impact__c = 'Low';
                caseRec.Urgency__c = 'Low';
            }
            else if(caseRec.Impact__c == 'Some users but not all') {
                caseRec.Impact__c = 'Low';
                caseRec.Urgency__c = 'Medium';
            }
            else if(caseRec.Impact__c == 'Everyone in the company') {
                caseRec.Impact__c = 'Low';
                caseRec.Urgency__c = 'High';
            }
            insert caseRec; 
            PageReference pageRef = new PageReference('/caseconfirmation?caseid='+caseRec.Id);
            pageRef.setRedirect(true);
            return pageRef;
        }
    }
    /*Function for getting the created Case ID*/
    public List<Case> getCaseList(){
        if ( ApexPages.currentPage().getParameters().get('caseid') != null )
            caseIDVal = ApexPages.currentPage().getParameters().get('caseid');
        CaseList = [Select id,subject,casenumber from Case where id=:caseIDVal];
        return CaseList;
    }
    /*Fuction which decided whether to create a new contact or update an existing contact*/
    public void createContactRecord() {
        try {
            getContactDetails = [SELECT ID FROM Contact WHERE Email = :contactEmail LIMIT 1];
            if(getContactDetails.size() == 0) {
                conRec.Email = contactEmail;
                insert conRec;
            }
            else {
                for(Contact cntct : getContactDetails ) {
                    conRec.Id = cntct.Id;
                }
            }
        }
        catch(System.Exception ex) {
            System.Debug(ex.getMessage());
        }
    }
}

Below is my Test class:
@isTest
private class CreateCaseController_Test{

    static testmethod void m1(){
        Cookie curLang= new Cookie('curLang','nl_NL',null,-1,false);
        ApexPages.currentPage().setCookies(new Cookie[]{curLang});
        CreateCaseController ccc = new CreateCaseController();
        ccc.getLangPref();
        ccc.langPref='nl_NL';
        ApexPages.currentPage().setCookies(new Cookie[]{});
        ccc.changeLanguage();
        
        ccc.getCurrentLanguage();
        ccc.setSelectLanguage(curLang);
        ccc.conRec = new Contact();
        ccc.conRec.lastName='test';
        ccc.conRec.email='c@kcom';
        ccc.contactEmail='c@k.com';
        ccc.caseRec = new Case();
        ccc.caseRec.Subject='test';
        ccc.caseRec.SuppliedCompany='test company';
        ccc.caseRec.Description='test';
        ccc.caseRec.Impact__c='Just me';
        ccc.saveData();
        ccc.conRec = new Contact();
        ccc.conRec.lastName='test';
        ccc.conRec.email='c@kcom';
        ccc.conRec.Phone='122444';
        ccc.caseRec = new Case();
        ccc.caseRec.Impact__c='Just me';
        ccc.saveData();
        curLang= new Cookie('curLang','en',null,-1,false);
        ccc.getCaseList();
    }
    
    static testmethod void m2(){
        
        CreateCaseController ccc = new CreateCaseController();
        ccc.conRec = new Contact();
        ccc.conRec.lastName='test';
        ccc.conRec.email='c@kcom';
        ccc.contactEmail='c@k.com';
        ccc.caseRec = new Case();
        ccc.caseRec.Subject='test';
        ccc.caseRec.SuppliedCompany='test company';
        ccc.caseRec.Description='test';
        ccc.caseRec.Impact__c='Some users but not all';
        ccc.saveData();
        
        Cookie curLang= new Cookie('curLang','',null,-1,false);
        ApexPages.currentPage().setCookies(new Cookie[]{curLang});
        ccc.langPref='nl_NL';
        ccc.changeLanguage();
        
        ccc.getCurrentLanguage();
        
        ApexPages.currentPage().getParameters().put('caseid',ccc.caseRec.Id);
        ccc.getCaseList();
        ccc.contactEmail='c@k.com';
        ccc.createContactRecord();
        
        Cookie curLang1= new Cookie('curLang',null,null,-1,false);
        ApexPages.currentPage().setCookies(new Cookie[]{curLang1});
        ccc.getCurrentLanguage();
        ccc.contactEmail='';
        ccc.createContactRecord();
    }
    
    static testmethod void m3(){
        
        CreateCaseController ccc = new CreateCaseController();
        ccc.langPref='nl_NL';
        ccc.getCurrentLanguage();
        ccc.conRec = new Contact();
        ccc.conRec.lastName='test';
        ccc.conRec.email='c@kcom';
        ccc.contactEmail='c@k.com';
        ccc.caseRec = new Case();
        ccc.caseRec.Subject='test';
        ccc.caseRec.SuppliedCompany='test company';
        ccc.caseRec.Description='test';
        ccc.caseRec.Impact__c='Everyone in the company';
        ccc.saveData();
    }
    
    static testmethod void m4(){
        
        CreateCaseController ccc = new CreateCaseController();
        ccc.conRec = new Contact();
        ccc.conRec.lastName='test';
        ccc.conRec.email='c@kcom';
        //ccc.contactEmail='c@k.com';
        ccc.caseRec = new Case();
        ccc.caseRec.Subject='test';
        ccc.caseRec.SuppliedCompany='test company';
        ccc.caseRec.Description='test';
        ccc.caseRec.Impact__c='Everyone in the company';
        ccc.saveData();
    }

}

Thanks in advance.
bob_buzzardbob_buzzard
The exception appears to be coming from a trigger rather than the controller.
Sriram MSriram M
Thanks for the clarification Bob, 

I'm not sure whether what i'm saying below make sense.

In the above test class code which I have added,  in the line numbers 018, 042 and 077 the field 'contactEmail' is a form variable which i declared and used in the visual force page. I'm using this value to get the email from user rather than user the 'email' object defined in 'Contact' class. 

I'm not sure whether the particular variable could be recognized by production environment. As I could see the failure report in the deployment status, the test methods m1(), m2() and m3() are getting failed but not the method m4() in which that particular variable is commented out (092).

Please share your thoughts on this.

Thanks in advance.


bob_buzzardbob_buzzard
According to the stacktrace, the null pointer exception is coming from an after insert trigger.  Without seeing the code for that its impossible to tell what might be going wrong.
Sriram MSriram M
Hi Bob.

Thanks for the suggestion.

I checked the processes using debug Log and found the problem occurs in a trigger file as you suggested. I fixed it and the validations went succesful for all the classes. But we are struck up now in an error which doesn't have any relation with our change set.

User-added image

In the above screenshot, the class subscriptionTest is not an included component in the outbound change set. Its dependent files are also not available in the change set. But somehow it is throwing the above error when validating the inbound changeset in production environment. 

Is it possible that a class file adds itself to a change set automatically without explictly adding it? Are there any option to prevent it?

Please enlighten me.. 

Thanks in advance