• mkdjns
  • NEWBIE
  • 10 Points
  • Member since 2011
  • Senior Software Engineer
  • Healthy Paws Pet Insurance


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 10
    Replies

Hello all-

 

I'm getting the following when trying to deserialize a previously serialized object:

 

System.JSONException: Invalid format: "2011-12-26T00:00:00.000+0000" is malformed at "T00:00:00.000+0000" at [Source: java.io.StringReader@1c76581e; line: 1, column: 2860]: (System Code)

 

A simple way to reproduce this is to create a before update trigger on Account with the following: Make sure you have a date field in the account object and that the date field is populated.

 

string jsStr = json.serialize(trigger.newMap);
map<id, account> test = (map<id, Account>)json.deserialize(jsstr, map<id, Account>.class);
system.debug('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ deserialized map' +  test);	

 

The interesting bit is that the deserialization only fails if the account object is updated via the UI. If the update happens via APEX, everything works as expected. What's the cause of this?

  • January 06, 2012
  • Like
  • 0

I have the following VF page that is called by a button on a Person Account record.

 

 

<apex:page standardController="Account" title="Cancel Account">
    <apex:sectionHeader title="Cancel Account"/>
    <apex:form id="theForm">
        <apex:pageBlock id="theBlock">
            <apex:pageBlockSection id="sectionOne">
                <apex:outputField value="{!Account.Name}" />
                <!-- Bound to Date Field -->                
                <apex:inputField value="{!Account.Account_Cancel_Eff_Date__c}" />
                <!-- Bound to Picklist -->
                <apex:inputField value="{!Account.Account_Cancel_Reason__c}" />
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

When the page is called for a person account, Salesforce returns:

 

Validation Errors While Saving Record(s)

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Record Type ID: value not valid for the entity: Account". 

When the page is called for a normal Account, it renders as expected. If I remove the inputField that is bound to the picklist, then call the page for a person account, everything works as expected. What's going on here?

 

  • February 09, 2011
  • Like
  • 0

I'm having an issue with saving a Visualforce page as a PDF attachment.

 

My page is (simplified):

<apex:page id="thePage" standardController="Case" extensions="customStuff" renderAs="{!renderMode}" showHeader="{!renderMode != 'pdf'}" standardStylesheets="{!renderMode != 'pdf'}">

   <apex:form id="theForm" rendered="{!renderMode != 'pdf'}">
      <apex:pageBlock id="theBlock">
         <apex:pageBlockSection id="theSection" columns="3">
            <apex:pageBlockSectionItem id="theSectionItems">
               <apex:outputLabel for="chooseTemplate" value="Choose the EOB template to use:" />
                  <apex:outputPanel >
                     <apex:selectList id="chooseTemplate" value="{!template}" size="1">
                        <apex:selectOptions value="{!templates}" />
                        <apex:actionSupport event="onchange" rerender="theBlock, theLetterBody" status="loadStatus" onsubmit="javascript&colon;document.body.style.cursor = 'wait';" oncomplete="javascript&colon;document.body.style.cursor = 'default';" />
                     </apex:selectList>
                     <apex:actionStatus id="loadStatus">
                     <apex:facet name="start"><img src="/img/loading.gif" /></apex:facet>
                  </apex:actionStatus>
               </apex:outputPanel>
            </apex:pageBlockSectionItem>
            <apex:commandButton action="{!savePDF}" value="Attach PDF" rendered="{!len(template) > 1}"/>
         </apex:pageBlockSection>
      </apex:pageBlock>
   </apex:form>

      <div id="content">
      </div>
</apex:page>

 

 

And the controller (also simplified):

 

public class customStuff {

  private string caseID;
  public Case activeCase {get; set;}
  public string renderMode {get; set;}
  public string Template {get; set;}
	
  public customStuff(ApexPages.StandardController controller) {
		
    caseID = ApexPages.currentPage().getParameters().get('id');
    if (caseID != null){
      setActiveCase();
    }
    	
    	if(ApexPages.currentpage().getParameters().get('t') != null) {
    		template = ApexPages.currentpage().getParameters().get('t');
    	}
    	
    if(ApexPages.currentPage().getParameters().get('p') != null) {
      renderMode = 'pdf';
    } else {
      renderMode = null;
    }
  }

  public pageReference setActiveCase() {
    activeCase = new Case();
    this.activeCase = [select id from Case where id = :caseID];
    return null;
  }

  public pageReference savePDF() { 
    pageReference thePage = Page.customStuff;
    thePage.getParameters().put('p','pdf');
    thePage.getParameters().put('t',Template);
    thePage.getParameters().put('id',CaseID);
    
    blob body = thePage.getContent();
    
    attachment pdf = new attachment();
    pdf.filename='my filename';
    pdf.body = body;
    pdf.ParentId = activeCase.id;
    pdf.isPrivate = false;
    
  }

  public list<selectOption> getTemplates() {
    list<selectOption> theTemplates = new list<selectOption>();
    theTemplates.add(new selectOption('', '--None--'));
    theTemplates.add(new selectOption('1', 'Item 1'));
    theTemplates.add(new selectOption('2', 'Item 2'));
    theTemplates.add(new selectOption('3', 'Item 3'));
    theTemplates.add(new selectOption('4', 'Item 4'));
    return theTemplates;
  }

}

 

 

My issue is that calling the page in the savePDF method seems to ignore the added parmeters, but only in certain instances. For example, the standard header and styles are removed, but the pageBlock is still rendered. And the page doesn't render as a pdf, even though it has received a parameter instructing it to.

 

This boggles the mind, but I'm hoping there's something simple I'm missing.

 

Thanks in advance!!

 

-Mike

  • January 13, 2011
  • Like
  • 0

I have the following VF page that is called by a button on a Person Account record.

 

 

<apex:page standardController="Account" title="Cancel Account">
    <apex:sectionHeader title="Cancel Account"/>
    <apex:form id="theForm">
        <apex:pageBlock id="theBlock">
            <apex:pageBlockSection id="sectionOne">
                <apex:outputField value="{!Account.Name}" />
                <!-- Bound to Date Field -->                
                <apex:inputField value="{!Account.Account_Cancel_Eff_Date__c}" />
                <!-- Bound to Picklist -->
                <apex:inputField value="{!Account.Account_Cancel_Reason__c}" />
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

When the page is called for a person account, Salesforce returns:

 

Validation Errors While Saving Record(s)

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Record Type ID: value not valid for the entity: Account". 

When the page is called for a normal Account, it renders as expected. If I remove the inputField that is bound to the picklist, then call the page for a person account, everything works as expected. What's going on here?

 

  • February 09, 2011
  • Like
  • 0

I'm having an issue with saving a Visualforce page as a PDF attachment.

 

My page is (simplified):

<apex:page id="thePage" standardController="Case" extensions="customStuff" renderAs="{!renderMode}" showHeader="{!renderMode != 'pdf'}" standardStylesheets="{!renderMode != 'pdf'}">

   <apex:form id="theForm" rendered="{!renderMode != 'pdf'}">
      <apex:pageBlock id="theBlock">
         <apex:pageBlockSection id="theSection" columns="3">
            <apex:pageBlockSectionItem id="theSectionItems">
               <apex:outputLabel for="chooseTemplate" value="Choose the EOB template to use:" />
                  <apex:outputPanel >
                     <apex:selectList id="chooseTemplate" value="{!template}" size="1">
                        <apex:selectOptions value="{!templates}" />
                        <apex:actionSupport event="onchange" rerender="theBlock, theLetterBody" status="loadStatus" onsubmit="javascript&colon;document.body.style.cursor = 'wait';" oncomplete="javascript&colon;document.body.style.cursor = 'default';" />
                     </apex:selectList>
                     <apex:actionStatus id="loadStatus">
                     <apex:facet name="start"><img src="/img/loading.gif" /></apex:facet>
                  </apex:actionStatus>
               </apex:outputPanel>
            </apex:pageBlockSectionItem>
            <apex:commandButton action="{!savePDF}" value="Attach PDF" rendered="{!len(template) > 1}"/>
         </apex:pageBlockSection>
      </apex:pageBlock>
   </apex:form>

      <div id="content">
      </div>
</apex:page>

 

 

And the controller (also simplified):

 

public class customStuff {

  private string caseID;
  public Case activeCase {get; set;}
  public string renderMode {get; set;}
  public string Template {get; set;}
	
  public customStuff(ApexPages.StandardController controller) {
		
    caseID = ApexPages.currentPage().getParameters().get('id');
    if (caseID != null){
      setActiveCase();
    }
    	
    	if(ApexPages.currentpage().getParameters().get('t') != null) {
    		template = ApexPages.currentpage().getParameters().get('t');
    	}
    	
    if(ApexPages.currentPage().getParameters().get('p') != null) {
      renderMode = 'pdf';
    } else {
      renderMode = null;
    }
  }

  public pageReference setActiveCase() {
    activeCase = new Case();
    this.activeCase = [select id from Case where id = :caseID];
    return null;
  }

  public pageReference savePDF() { 
    pageReference thePage = Page.customStuff;
    thePage.getParameters().put('p','pdf');
    thePage.getParameters().put('t',Template);
    thePage.getParameters().put('id',CaseID);
    
    blob body = thePage.getContent();
    
    attachment pdf = new attachment();
    pdf.filename='my filename';
    pdf.body = body;
    pdf.ParentId = activeCase.id;
    pdf.isPrivate = false;
    
  }

  public list<selectOption> getTemplates() {
    list<selectOption> theTemplates = new list<selectOption>();
    theTemplates.add(new selectOption('', '--None--'));
    theTemplates.add(new selectOption('1', 'Item 1'));
    theTemplates.add(new selectOption('2', 'Item 2'));
    theTemplates.add(new selectOption('3', 'Item 3'));
    theTemplates.add(new selectOption('4', 'Item 4'));
    return theTemplates;
  }

}

 

 

My issue is that calling the page in the savePDF method seems to ignore the added parmeters, but only in certain instances. For example, the standard header and styles are removed, but the pageBlock is still rendered. And the page doesn't render as a pdf, even though it has received a parameter instructing it to.

 

This boggles the mind, but I'm hoping there's something simple I'm missing.

 

Thanks in advance!!

 

-Mike

  • January 13, 2011
  • Like
  • 0

When we made the move from using Custom Labels to store app settings to using the new hierarchical Custom Settings to do so, our testMethods started failing due to null pointer references.  From what I've seen, when you go to install a package with Custom Settings definitions via AppExchange, even if you set defaults for it when creating the settings, they are not passed to the target org.  The target org seems to be required to hit the Manage button and accect/create/modify the default settings for the org wide defaults before they can be used.  This is a problem since these won't exist during an AppExchange install, and can't be managed until the install would be done, at which point it's already failed out our testMethods that call code referencing expected default values.

 

What is the proper way to use Custom Settings and still ensure that code coverage is achieved, and that they can be packaged for the AppExchange without defaulting to being null?