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
BerginBergin 

Data from Apex callout doesnt work in VF Page with Standard Controller

I have a visual force page that gets data from a webservice through Apex callout. I want to display that in  the Account page in a section.
The page works fine if I access the page independently, it shows the below error if I embed the visualforce page in the Account Page Layout.

Content cannot be displayed: Web service callout failed: Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found 'http://www.w3.org/1999/xhtml:html'

Anybody else faced this issue? What could be the fix?

NehalNehal (Salesforce Developers) 
Hi,


This error usually occurs if there is some issue in communication with the external webservice.

Check the following:

1. Check if external webservice is really available and working.
2. Check if Salesforce's IP addresses are included in whitelist in the firewall of the network where the external wabservice is located.
3. Validate the endpoint address of the webservice.
4. Check if the endpoint's server is enabled as a Remote Site in Salesforce.
5. Remember that web service must be accesible from Internet to a public and valid IP address.

I hope this helps. Please mark this as a ""Best Answer"" if this has resolved your issue.
Mahsa KMahsa K
I am getting the same error:
Web service callout failed: Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found 'http://www.w3.org/1999/xhtml:html'
The problem is that a send email button on one of our VF pages works perfectely well for some users while some other users get this error:

Web service callout failed: Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found 'http://www.w3.org/1999/xhtml:html'
Error is in expression '{!checkSend}' in component <apex:page> in page emailconfirmation


The code that the error is refering too is:

System.debug('SendPDFByEmail - accId = ' + accId + ' contactEmail = ' + contactEmail + ' attach.Id = ' + attach.Id + ' subject = ' + subject + ' usr.email = ' + usr.email + ' companyName = ' + companyName+ + ' IsTest? = ' + test.isRunningTest());
            if(!(test.isRunningTest()))
            CalcSoapWrapper.SendPDFByEmail(accId,contactEmail,attach.Id,subject,body,usr.email,companyName,'00X7000000185oO');
           
            String retUrl = ApexPages.currentPage().getParameters().get('retUrl');
            if(retUrl != null && retUrl != '') {
                PageReference pageRef = new PageReference(retUrl);
                pageRef.setRedirect(true);
                return pageRef;
            } else {
            
              string additionalParameter = '';
              if(!string.isEmpty(ApexPages.currentPage().getParameters().get('range'))){
                additionalParameter = '&range='+ApexPages.currentPage().getParameters().get('range');
              }
              if(!string.isEmpty(ApexPages.currentPage().getParameters().get('start'))){
                additionalParameter += '&start='+ApexPages.currentPage().getParameters().get('start');
              }
              if(!string.isEmpty(ApexPages.currentPage().getParameters().get('end'))){
                additionalParameter += '&end='+ApexPages.currentPage().getParameters().get('end');
              }
                PageReference pageRef = new PageReference('/apex/CP_ManageMyAccount?id=' +accId +'&accid=' +accId +'&printmode=pdf'+mode+additionalParameter);
                pageRef.setRedirect(true);
                return pageRef;
            }

I tried changing those users profiles to the ones that are working but I still get the same error. Those users have access to the email templates used in the code. Does anyone know what could have caused this? Ant help would be appreciated.