I am creating a url to prepopulate values on a custom form by parsing the labels from the html of the form. I am using the getContent() method of the page reference class to get the html of the form I want to pre-populate. The issue is that not all the fields on the form are present in the html returned using this method. If I view the source code of the form once it is on the screen, all the fields are represented. Is this a timing issue? Why can't I get the entire html of the page?
This is what is on my page:
<apex:page standardController="DCS_Request__c" extensions="CRM_Kathy" showHeader="false" sidebar="false" standardStylesheets="false">
<apex:includeScript value="{!URLFOR($Resource.JQueryUI, 'js/jquery-1.8.0.min.js')}"/>
<apex:pageblock >
<apex:pageMessages />
<apex:outputLink value="{!ReturnIdPath}" id="theLink">Return</apex:outputLink>
</apex:pageblock>
<script type="text/javascript">
if ("{!url}") {
window.location = '{!url}';
}
</script>
</apex:page>
And this is part of the class:
public CRM_Kathy(ApexPages.StandardController controller) {
this.controller = controller;
url = createurl();
}
public string url{get;set;}
private Map<String, String> createDefaultValues() {
PageReference p = new PageReference('/' + DCS_Request__c.SObjectType.getDescribe().getKeyPrefix() + '/e?nooverride=1');
String html = p.getContent().toString();
system.debug('this is the html = ' + html);
Map<String, String> labelToId = new Map<String, String>(); //gets label of field and the field id from the html of the selected request
Matcher m = Pattern.compile('<label for="(\\w+?)">(<span class="requiredMark">\\*</span>)?(.*?)</label>').matcher(html);
while (m.find()) {
String label = m.group(3);
system.debug('this is the label from the html = ' + label);
String id = m.group(1);
system.debug('this is the id from the html = ' + id);
labelToId.put(label, id);
}
system.debug('this is the label to id = ' + labeltoid);
return labelToId;
}
}