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
Gunwinder Singh 4Gunwinder Singh 4 

Dynamic URL in visualorce page not populating

I am facing an issue with fetching the path of image stored in documents (available for external user). 

When the visualforce page is rendered the image shows broken upon inspecting the element it does not capture URL generated from String variable "imageURL". 

Here I am trying to adjust the URL based of image because of enhanced domains release update.

Please suggest as what I may be doing wrong. 

Class: 
public class BBH_Survey {
    public boolean hidecmtbtn{get;set;}
    public boolean modibtn {get;set;} //
    Public String CasId;
    Public String Survey_comments {get;set;} 
    public boolean flag{get;set;}
    public list<BBH_Surveys__c> lstbbhsury;
    public Decimal survyeExpired {get;set;}
    public String btncss{get;set;}
    public String ratingCss{get;set;}
   // Public New_Surveys__c surveyName {get;set;}//
   // public String modifySurvey{get;set;}//
    public string surveyId;
    public String imageURL{get;set;}//
    //public String modiRes {get;set;}//
        
    public BBH_Survey(apexPages.StandardController std) 
    {
        // fetch instance Id : NA169.. etc
        String instanceName = [select InstanceName from Organization limit 1].InstanceName; 
        hidecmtbtn=true;
        Survey_comments='';
        flag=false;
        CasId=ApexPages.currentPage().getParameters().get('CaId'); 
        surveyId = Apexpages.currentPage().getParameters().get('id');
        lstbbhsury=[select id from BBH_Surveys__c where CaseId__c =:CasId]; 
        
        List<New_Surveys__c> schoolsurvey =[select Rating_Css__c,Button_css__c,Survey_Expired__c,School_URL__c,School_Logo__c from New_Surveys__c where id=:surveyId]; 
        
        if(schoolsurvey.size()>0){      
       
       // String orgid='&oid=00Dd0000000dwdA';
         Organization organizationInfo = [Select id from Organization];
         string organizationId= organizationInfo.id; 
         String orgid='&oid='+organizationId;
            
         survyeExpired=schoolsurvey[0].Survey_Expired__c;
         btncss=schoolsurvey[0].Button_css__c;  
         ratingCss=schoolsurvey[0].Rating_Css__c;
         
         // fetch baseURL & convert to respect Enhanced domain changes
         
         string baseURL = URL.getSalesforceBaseUrl().toExternalForm() +'/'; 
         string baseimageURL;
         // target Sanbdbox envoirnment
         
         if (baseURL.contains('sandbox.my.salesforce.com')){
         baseURL=baseURL.replace('sandbox.my.salesforce.com', 'sandbox.my.salesforce-sites.com');
         baseimageURL=baseURL.replace('sandbox.my.salesforce-sites.com', 'sandbox.file.force.com');
        
         }
         
         // target Production envoirnment 
         
         else if (baseURL.contains('ceai.my.salesforce.com')){
         baseURL=baseURL.replace('ceai.my.salesforce.com', 'ceai.my.salesforce-sites.com');
         baseimageURL=baseURL.replace('ceai.my.salesforce-sites.com', 'ceai.file.force.com');
         }
         system.debug(' baseURL  :' +baseURL);
         system.debug(' imageURL  :' +baseimageURL);   
         
     // imageURL='Https://ceai--c.'+instanceName+'.content.force.com/servlet/servlet.ImageServer?id='+schoolsurvey[0].School_Logo__c+orgid;
        imageURL=baseimageURL+'/servlet/servlet.ImageServer?id='+schoolsurvey[0].School_Logo__c+orgid;
        } 
        else {
        system.debug('Error in fetching School survey record configuration, check if the New Survey record is created');
        }
        
            
     linkExpire();
    
    }  
    
    Public  PageReference survey_1(){
        
        try{ 
            
            List<case> lstCase=[select id,status ,Survey_fill__c from case where id =:CasId]; 
            List<New_Surveys__c> schoolsurvey =[select School_URL__c,School_Logo__c from New_Surveys__c where id=:surveyId];            string url=schoolsurvey[0].School_URL__c;
            PageReference myVFPage = new PageReference(url);
            BBH_Surveys__c bbh=new BBH_Surveys__c();
            
            if(lstCase.size()>0)
            {
            bbh.CaseId__c=lstCase[0].id;
            }
               bbh.Survey_Response__c= '1';
               bbh.Surveys_Name__c=surveyId;    
               bbh.Survey_Comments__c =Survey_comments;
        
              insert bbh;
             myVFPage.setRedirect(true);
              return myVFPage; 
        } 
        catch(Exception e)
        { return null; }
            
    }
        

    
Public  PageReference survey_2(){
    
  
    try{
    List<case> lstCase=[select id,status ,Survey_fill__c from case where id =:CasId];
    List<New_Surveys__c> schoolsurvey =[select School_URL__c,School_Logo__c from New_Surveys__c where id=:surveyId];               
        
        string url=schoolsurvey[0].School_URL__c;
        PageReference myVFPage = new PageReference(url);
        BBH_Surveys__c bbh=new BBH_Surveys__c();
          if(lstCase.size()>0)
            {
            bbh.CaseId__c=lstCase[0].id;
            }
               bbh.Survey_Response__c= '2';
               bbh.Surveys_Name__c=surveyId;    
        	   bbh.Survey_Comments__c =Survey_comments;
        
              insert bbh;
              myVFPage.setRedirect(true);
              return myVFPage;
        } 
       catch(Exception e) {        
       return null;
        }
 }
        

    Public  PageReference survey_3(){
  
    try{
    List<case> lstCase=[select id,status ,Survey_fill__c from case where id =:CasId];
    List<New_Surveys__c> schoolsurvey =[select School_URL__c,School_Logo__c from New_Surveys__c where id=:surveyId];               
        // PageReference myVFPage = page.Survey_saved;
        string url=schoolsurvey[0].School_URL__c;
        PageReference myVFPage = new PageReference(url);
              BBH_Surveys__c bbh=new BBH_Surveys__c();
               if(lstCase.size()>0)
            {
            bbh.CaseId__c=lstCase[0].id;
            }
               bbh.Survey_Response__c= '3';
               bbh.Surveys_Name__c=surveyId;    
               bbh.Survey_Comments__c =Survey_comments;
        
              insert bbh;
             myVFPage.setRedirect(true);
             return myVFPage;
        } 
        catch(Exception e) 
        {return null;}
            
    }
    

    
    Public  PageReference survey_4(){
      
    try{
    List<case> lstCase=[select id,status ,Survey_fill__c from case where id =:CasId];
    List<New_Surveys__c> schoolsurvey =[select School_URL__c,School_Logo__c from New_Surveys__c where id=:surveyId];               
        // PageReference myVFPage = page.Survey_saved;
        string url=schoolsurvey[0].School_URL__c;
        PageReference myVFPage = new PageReference(url);
              BBH_Surveys__c bbh=new BBH_Surveys__c();
               if(lstCase.size()>0)
            {
            bbh.CaseId__c=lstCase[0].id;
            }
               bbh.Survey_Response__c= '4';
               bbh.Surveys_Name__c=surveyId;    
               bbh.Survey_Comments__c =Survey_comments;
      
              insert bbh;
                 
             myVFPage.setRedirect(true);
                   
              return myVFPage;
        } catch(Exception e) 
        { return null; }
            
    }
        
    public  PageReference survey_5()
    {
        
     try{
    List<case> lstCase=[select id,status ,Survey_fill__c from case where id =:CasId];
    List<New_Surveys__c> schoolsurvey =[select School_URL__c,School_Logo__c from New_Surveys__c where id=:surveyId];               
        // PageReference myVFPage = page.Survey_saved;
        string url=schoolsurvey[0].School_URL__c;
        PageReference myVFPage = new PageReference(url);
              BBH_Surveys__c bbh=new BBH_Surveys__c();
               if(lstCase.size()>0)
            {
            bbh.CaseId__c=lstCase[0].id;
            }
               bbh.Survey_Response__c= '5';
               bbh.Surveys_Name__c=surveyId;    
               bbh.Survey_Comments__c =Survey_comments;
      
              insert bbh;
                 
             myVFPage.setRedirect(true);
                   
              return myVFPage;
        } catch(Exception e) 
        { return null; }
            
}
     
 
   public PageReference modifyResponce1() 
    {
     List<BBH_Surveys__c> BBHSurList =[select id,Survey_Response__c from BBH_Surveys__c where CaseId__c=:CasId limit 1];
         List<New_Surveys__c> schoolsurvey =[select School_URL__c,School_Logo__c from New_Surveys__c where id=:surveyId];               
        // PageReference myVFPage = page.Survey_saved;
        string url=schoolsurvey[0].School_URL__c;   
       PageReference myVFPage = new PageReference(url);  
       BBH_Surveys__c bbt=new BBH_Surveys__c();
        if(BBHSurList.size()>0)
        {
        bbt.id=BBHSurList[0].id;
        }   
        bbt.Survey_Response__c='1';
        update bbt;
        myVFPage.setRedirect(true);
        return myVFPage;
    }
        
        public PageReference modifyResponce2() 
    {
     List<BBH_Surveys__c> BBHSurList =[select id,Survey_Response__c from BBH_Surveys__c where CaseId__c=:CasId limit 1];
         List<New_Surveys__c> schoolsurvey =[select School_URL__c,School_Logo__c from New_Surveys__c where id=:surveyId];               
        // PageReference myVFPage = page.Survey_saved;
        string url=schoolsurvey[0].School_URL__c;   
       PageReference myVFPage = new PageReference(url);  
       BBH_Surveys__c bbt=new BBH_Surveys__c();
        if(BBHSurList.size()>0)
        {
        bbt.id=BBHSurList[0].id;
        }   
        bbt.Survey_Response__c='2';
        update bbt;
        myVFPage.setRedirect(true);
        return myVFPage;
    }
        
        public PageReference modifyResponce3() 
    {
     List<BBH_Surveys__c> BBHSurList =[select id,Survey_Response__c from BBH_Surveys__c where CaseId__c=:CasId limit 1];
         List<New_Surveys__c> schoolsurvey =[select School_URL__c,School_Logo__c from New_Surveys__c where id=:surveyId];               
        // PageReference myVFPage = page.Survey_saved;
        string url=schoolsurvey[0].School_URL__c;   
       PageReference myVFPage = new PageReference(url);  
       BBH_Surveys__c bbt=new BBH_Surveys__c();
      if(BBHSurList.size()>0)
        {
        bbt.id=BBHSurList[0].id;
        }   
        bbt.Survey_Response__c='3';
        update bbt;
            myVFPage.setRedirect(true);
        
        return myVFPage;
    }
        
        public PageReference modifyResponce4() 
       {
     	 List<BBH_Surveys__c> BBHSurList =[select id,Survey_Response__c from BBH_Surveys__c where CaseId__c=:CasId limit 1];
         List<New_Surveys__c> schoolsurvey =[select School_URL__c,School_Logo__c from New_Surveys__c where id=:surveyId];               
        
           // PageReference myVFPage = page.Survey_saved;
           string url=schoolsurvey[0].School_URL__c;   
           PageReference myVFPage = new PageReference(url);  
           BBH_Surveys__c bbt=new BBH_Surveys__c();
       
           if(BBHSurList.size()>0)
           {
             bbt.id=BBHSurList[0].id;
           }   
        bbt.Survey_Response__c='4';
        update bbt;
            myVFPage.setRedirect(true);
        
        return myVFPage;
    }
        
        public PageReference modifyResponce5() 
        {
         List<BBH_Surveys__c> BBHSurList =[select id,Survey_Response__c from BBH_Surveys__c where CaseId__c=:CasId limit 1];
         List<New_Surveys__c> schoolsurvey =[select School_URL__c,School_Logo__c from New_Surveys__c where id=:surveyId];               
        // PageReference myVFPage = page.Survey_saved;
         string url=schoolsurvey[0].School_URL__c;   
          PageReference myVFPage = new PageReference(url);  
          BBH_Surveys__c bbt=new BBH_Surveys__c();
       
            if(BBHSurList.size()>0)
             {
              bbt.id=BBHSurList[0].id;
             }   
        bbt.Survey_Response__c='5';
        update bbt;
        myVFPage.setRedirect(true);
        
        return myVFPage;
    }
    
    
    public  void linkExpire()
    { 
         DateTime dT = System.now();
         Date myDate = date.newinstance(dT.year(), dT.month(), dT.day());
        
             for(case cs:[select ClosedDate from case where id=:casId])
             {
             if(cs.ClosedDate+survyeExpired<myDate)
               {
                 ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Survey link has been expired'));  
                 modibtn=false;
                 hidecmtbtn=false;
           
               }
     
          else if(lstbbhsury.size()>0)
           {
           ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'We see survey is already filled for the ticket. To modify responses, rate the call and click update survey'));
             modibtn=true;
             hidecmtbtn=false;
           }        
         }
    }   
}
Upon inspecting the element User-added image
 
Shri RajShri Raj
It appears that you are having issues with the image URL in your Visualforce page. You are using the code to fetch the base URL and convert it to respect Enhanced Domain changes, however, it is not capturing the URL generated from the "imageURL" string variable.
I would suggest checking the following:
Ensure that the school survey record (New_Surveys__c) has the correct values for School_Logo__c and that it is not null.
Verify if the imageURL is being constructed correctly by checking the output of "baseimageURL" and "imageURL" variables in the debug logs.
Check if the Servlet.ImageServer is available and accessible from your org.