4

We are having utility class where we are fetching session Id using visualforcePage.getContent() which we are further using in updating custom metadata records.

we released our last version around Nov - 2018 till now same code was working fine but now when we released our new beta version we started getting this issue where it says

Maximum redirects (100) exceeded.

we checked couple of solutions online and we did update our code based on solution suggested here Asynchronous getContent hit org.apache.commons.httpclient.RedirectException: Maximum redirects (100) exceeded

but still the same case.

We found out known issue around it and it says its resolved but its not working for us. any help will be greatly appriciated Summer 14 Regression- Under some circumstances PageReference.getContent() or getContentAsPDF()fails the error- System.VisualforceException: org.apac

Here is the code we are using

/**
 * @description Method to fetch session id from GetSessionIdVF visualforce page
 * @param NA
 * @return  string  returns valid session id
 *
*/
public static String fetchUserSessionId(){
     String sessionId = '';
     // Get the content of the VF page
     String vfContent;
     String ns = MyApexClass.getNamespacePrefix();

    /* Old code we were using
    // Refer to the Page
    PageReference reportPage = Page.GetSessionIdVF;
    try{
        if(!test.isRunningTest()){
            vfContent = reportPage.getContent().toString();
        }
        else {
            vfContent = String.valueOf('Start_Of_Session_Id Test End_Of_Session_Id');
        }
        // Find the position of Start_Of_Session_Id and End_Of_Session_Id
        Integer startP = vfContent.indexOf('Start_Of_Session_Id') + 'Start_Of_Session_Id'.length(),
        endP = vfContent.indexOf('End_Of_Session_Id');
        // Get the Session Id
        sessionId = vfContent.substring(startP, endP);
    }
    catch(Exception ex) {
        System.debug('***** ex: ' + ex);            
    }
    */
    //End of Old code , we commented out for now

    // After updating logic as per online solution new code
    try{
        String vf_url = '/apex/';
        if(String.isNotBlank(ns)) {
            vf_url += ns + '__' + 'getsessionidvf';    
        }
        else {
            vf_url += 'getsessionidvf';       
        }


        PageReference pg = new PageReference(vf_url);

        if(!test.isRunningTest()){
            vfContent = pg.getContent().toString();
        }
        else {
            vfContent = String.valueOf('Start_Of_Session_Id Test End_Of_Session_Id');
        }

        Integer startP = vfContent.indexOf('Start_Of_Session_Id') + 'Start_Of_Session_Id'.length(),
        endP = vfContent.indexOf('End_Of_Session_Id');
        // Get the Session Id
        sessionId = vfContent.substring(startP, endP);
    }
    catch(Exception ex) {
        System.debug('***** ex: ' + ex);
    }

    // Return Session Id
    return sessionId;
 }
9
  • We'll probably need to see your code. – gNerb Mar 6 '19 at 16:41
  • @gNerb added code snippet – Nachiket Deshpande Mar 6 '19 at 16:58
  • @NachiketDeshpande have u had any success and able to get past this error? – VarunC Apr 17 '19 at 13:20
  • @VarunC nope not yet – Nachiket Deshpande Apr 25 '19 at 5:36
  • Running into the same issue. Seems to have started recently for us. – Eric May 4 '19 at 2:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.