+ Start a Discussion

Error message not able to understand



Hi Friends.

 while deploying something to the production from eclipse.I got below given error and I am not sure what is the problem  and what  gonna be the solution.

This code has been written by somebody who was working for this this company prior to me so I am looking for help from you guys.


It could well be becasue of the test class which is written at the end of the code.That is where I see https://URL


Error.System.AssertException:Assertion failed:Expected :https://na1.salesforce.com/,Actual:https://na1.salesforce.com/.


Can somebody please help,It is urgently needed.







public with sharing class CMSForceSetupController {

  Map<String, CMSForceSites__c> sitesettings;
  public Map<ID,Site> sitesmap {get;set;}
  public List<sitesetup> sitesetuplist {get;set;}
  public CMSForceDomain__c currenthost {get;set;}
  public Boolean settingssaved {get;set;}

  public CMSForceSetupController() {
    //get a Map of the configured Sites in this org
    sitesmap = new Map<ID,Site>([Select s.UrlPathPrefix, s.TopLevelDomain, s.Subdomain, s.Status, s.Name, s.MasterLabel, s.Id, s.Description From Site s where Status = 'Active' limit 25]);
    //get the custom settings that already might exist
    sitesettings = CMSForceSites__c.getAll();
    //drop the Sites in the setup list
    sitesetuplist = new List<sitesetup>();
    for(Site s:sitesmap.values()) {
      sitesetup ss = new sitesetup();
      ss.siteId = s.Id;
      ss.siteName = s.MasterLabel;
      //check if we already have a preview url for this site, if so : prefill
      String siteid = s.Id;
      String shortid = siteid.substring(0,15);
      CMSForceSites__c cmsfs = sitesettings.get(shortid);
      if(cmsfs != null) { 
        ss.sitePreviewUrl = cmsfs.Site_Url__c;
        ss.customsettingId = cmsfs.Id;
    //check if we already have a configured instance
    currenthost = CMSForceDomain__c.getAll().get('cmsforcedomain');
    if(currenthost == null) currenthost = new CMSForceDomain__c(Name = 'cmsforcedomain');
  //save the preview urls back into the custom settings
  public PageReference save() {
    try {
      List<CMSForceSites__c> customsettings = new List<CMSForceSites__c>();
      for(sitesetup ss:sitesetuplist) {
        CMSForceSites__c s = new CMSForceSites__c(Id = ss.customsettingId);
        s.Site_Url__c = ss.sitePreviewUrl;
        //preview url is required
        if(ss.sitePreviewUrl == null || ss.sitePreviewUrl.length() == 0) {
          ApexPages.addMessage(new ApexPages.Message(ApexPages.SEVERITY.ERROR, 'Please fill in the Preview Url address for each of the sites below'));
          return null;
        s.Site_Name__c = ss.siteName;
        s.Site_Id__c = ss.siteId.substring(0,15);
        s.Name = ss.siteId.substring(0,15);
      if(currenthost.Url__c == null || currenthost.Url__c.length() == 0) {
          ApexPages.addMessage(new ApexPages.Message(ApexPages.SEVERITY.ERROR, 'Please fill in your Salesforce domain'));
          return null;
      if(currenthost.Url__c.endsWith('/')) currenthost.Url__c = currenthost.Url__c.substring(0,currenthost.Url__c.length()-1);
      upsert customsettings;
      upsert currenthost;
      settingssaved = true;
    catch(Exception ex) {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, ex.getMessage()));
    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Your settings have been saved. You can now continue using the console.'));
    return null;
  //internal value object
  public class sitesetup {
    public String siteId {get;set;}
    public String customsettingId {get;set;}
    public String siteName {get;set;}
    public String sitePreviewUrl {
          get { return sitePreviewUrl; }
          set {
            if(value == null) {sitePreviewUrl = null; return;}
            //remove any trailing '/'
            if(value.endsWith('/')) {sitePreviewUrl = value.substring(0, value.length()-1);}
            else {sitePreviewUrl = value;}
  /** TESTS **/
  private static testMethod void t1() {
    CMSForceSetupController csc = new CMSForceSetupController();
    //we should have at least one active Site
    //get the first site setup and fill in a custom setting (provide trailing '/' to get the cleanup code to run)
    sitesetup ss = csc.sitesetuplist[0];
    ss.sitePreviewUrl = 'http://somesite.force.com/someprefix/';
    //and provide the instance we're running in
    csc.currenthost.Url__c = 'https://na1.salesforce.com/';
    if(CMSForceDomain__c.getAll().get('cmsforcedomain') != null) System.assertEquals(CMSForceDomain__c.getAll().get('cmsforcedomain').Url__c, 'https://na1.salesforce.com');    



Anup JadhavAnup Jadhav
It means the assertion failed in the test method. The value it expects does not match the value you are testing against.


Thanks Anup,


I understand that actual and expected values should be same. It is showing expected as well as actual result to the be the same URL.However,it gives an error.


I don't know what should be done.Do u have any idea?.This is happening in production .When I run same test in sandbox I am not gettting any error.






The probem is with the test code ,as error is on the line 102 which is the last line in the test code.If somebody can help


This is after running the test class in the production:-


Could it because expected has backslash added to it which is missing in the actual and becaus of that it is giving an error?.


Actual:- https://na1.salesforce.com





Trick ,


Your first example shows the trailing backslash as being there.


If it is indeed missing, then yes, that would be the cause

Anup JadhavAnup Jadhav
Yes, that's possible.