• James Golding
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
So basically i have a page that is going through case creation, if the contact doesn't exist it, there is a button that shows the user a contact creation section.
When I press save I get errors that make no sense.

Visualforce
<apex:page Controller="CaseProcess" lightningStylesheets="true" >
    <apex:form >
        <apex:pageBlock Title ="Case Creation">
            <apex:pageMessages></apex:pageMessages>
            <apex:pageBlockSection title="Case Setup" id="caseSetup">
                <apex:inputField value="{!newCase.Subject}" required="true"/>
                <apex:inputField value="{!newCase.Origin}" required="true"/>
                <apex:inputField value="{!newCase.AccountId}" required="true"/>
                <apex:inputField value="{!newCase.RecordTypeId}" required="true"/>
                <apex:inputField value="{!newCase.ContactId}" required="true"/>
                <apex:inputField value="{!newCase.EntitlementId}" />
            </apex:pageBlockSection>
            <apex:pageBlockSection>
                <apex:commandButton value ="New Contact" action = "{!showCreateContact}" rendered = "{!notWizardContactSection}" immediate="true" html-formnovalidate="formnovalidate" style="align-content: center">
                	<apex:actionSupport reRender="contactCreation" />
            	</apex:commandButton>
            </apex:pageBlockSection> 
            <apex:commandbutton value="Save Case" action="{!saveCase}"/> 
    		<apex:commandbutton value="Cancel" action="{!cancelCase}" immediate="true" html-formnovalidate="formnovalidate"/>
        </apex:pageBlock> 
        <apex:pageBlock id="contactCreation" rendered="{!wizardContactSection}" title="Contact Creation">
            <!-- create contact section -->   
            <apex:pageBlockSection >
                <apex:inputField value="{!newContact.Name}"/>
            	<apex:inputField value="{!newContact.FirstName}" />
                <apex:inputField value="{!newContact.LastName}" id="lastName" />
                <apex:inputField value="{!newContact.AccountId}" id="accountId"/>
                <apex:inputField value="{!newContact.Email}" />
                <apex:inputField value="{!newContact.MobilePhone}" />
            </apex:pageBlockSection>  
            <apex:pageBlockSection>
                <apex:commandButton value ="Save Contact" action = "{!saveContact}" immediate="true" html-formnovalidate="formnovalidate">
                    <apex:actionSupport reRender="contactCreation" />
                </apex:commandButton>
            </apex:pageBlockSection>
            <!-- buttons section -->
        </apex:pageBlock>
    </apex:form>
</apex:page>
Controller
 
public class CaseProcess {

    public Contact newContact{get; set;}
    public Case newCase{get; set;}

    
    // assign variables for the different sections of the form
    public boolean wizardContactSection{get; set;}
    public boolean notWizardContactSection{get; set;}
    
    public CaseProcess(){
        // assign variables for hidding and showing sections of the form
        newCase = new Case();
        newContact = new Contact();
        wizardContactSection = false;
        notWizardContactSection = true;
    }
    public pagereference cancelCase(){
        return new pagereference('/lightning/o/Case/list');
    }
    public pagereference saveCase(){
        newCase.Status = 'New';
        insert newCase;
        return new pagereference('/lightning/o/Case/list');
    }
    
    public void showCreateContact(){
        wizardContactSection = true;
        notWizardContactSection = false;
        newContact.AccountId = newCase.AccountId;
    }
    public void saveContact(){
        /*
        if (newContact.AccountId == null){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'Please add an account to the contact.'));
            return;
        }*/
        try{
            insert newContact;    
        	newCase.ContactId = newContact.Id;
        	wizardContactSection = false;
        }
        catch(DmlException ex){
        	ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, ex.getDmlMessage(0)));   
        }
    }

}

And error message
User-added image
I can't work out why, I have tried moving all the contact related stuff into an extention but that doesn't work either 

 
I have a Record Choice Set looking at accounts filtered by postcode, my users will be entering the postcode. In my sandbox it returns the records that have that postcode. In live it returns nothing. 

Is there any reason this may be happening?
So basically i have a page that is going through case creation, if the contact doesn't exist it, there is a button that shows the user a contact creation section.
When I press save I get errors that make no sense.

Visualforce
<apex:page Controller="CaseProcess" lightningStylesheets="true" >
    <apex:form >
        <apex:pageBlock Title ="Case Creation">
            <apex:pageMessages></apex:pageMessages>
            <apex:pageBlockSection title="Case Setup" id="caseSetup">
                <apex:inputField value="{!newCase.Subject}" required="true"/>
                <apex:inputField value="{!newCase.Origin}" required="true"/>
                <apex:inputField value="{!newCase.AccountId}" required="true"/>
                <apex:inputField value="{!newCase.RecordTypeId}" required="true"/>
                <apex:inputField value="{!newCase.ContactId}" required="true"/>
                <apex:inputField value="{!newCase.EntitlementId}" />
            </apex:pageBlockSection>
            <apex:pageBlockSection>
                <apex:commandButton value ="New Contact" action = "{!showCreateContact}" rendered = "{!notWizardContactSection}" immediate="true" html-formnovalidate="formnovalidate" style="align-content: center">
                	<apex:actionSupport reRender="contactCreation" />
            	</apex:commandButton>
            </apex:pageBlockSection> 
            <apex:commandbutton value="Save Case" action="{!saveCase}"/> 
    		<apex:commandbutton value="Cancel" action="{!cancelCase}" immediate="true" html-formnovalidate="formnovalidate"/>
        </apex:pageBlock> 
        <apex:pageBlock id="contactCreation" rendered="{!wizardContactSection}" title="Contact Creation">
            <!-- create contact section -->   
            <apex:pageBlockSection >
                <apex:inputField value="{!newContact.Name}"/>
            	<apex:inputField value="{!newContact.FirstName}" />
                <apex:inputField value="{!newContact.LastName}" id="lastName" />
                <apex:inputField value="{!newContact.AccountId}" id="accountId"/>
                <apex:inputField value="{!newContact.Email}" />
                <apex:inputField value="{!newContact.MobilePhone}" />
            </apex:pageBlockSection>  
            <apex:pageBlockSection>
                <apex:commandButton value ="Save Contact" action = "{!saveContact}" immediate="true" html-formnovalidate="formnovalidate">
                    <apex:actionSupport reRender="contactCreation" />
                </apex:commandButton>
            </apex:pageBlockSection>
            <!-- buttons section -->
        </apex:pageBlock>
    </apex:form>
</apex:page>
Controller
 
public class CaseProcess {

    public Contact newContact{get; set;}
    public Case newCase{get; set;}

    
    // assign variables for the different sections of the form
    public boolean wizardContactSection{get; set;}
    public boolean notWizardContactSection{get; set;}
    
    public CaseProcess(){
        // assign variables for hidding and showing sections of the form
        newCase = new Case();
        newContact = new Contact();
        wizardContactSection = false;
        notWizardContactSection = true;
    }
    public pagereference cancelCase(){
        return new pagereference('/lightning/o/Case/list');
    }
    public pagereference saveCase(){
        newCase.Status = 'New';
        insert newCase;
        return new pagereference('/lightning/o/Case/list');
    }
    
    public void showCreateContact(){
        wizardContactSection = true;
        notWizardContactSection = false;
        newContact.AccountId = newCase.AccountId;
    }
    public void saveContact(){
        /*
        if (newContact.AccountId == null){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'Please add an account to the contact.'));
            return;
        }*/
        try{
            insert newContact;    
        	newCase.ContactId = newContact.Id;
        	wizardContactSection = false;
        }
        catch(DmlException ex){
        	ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, ex.getDmlMessage(0)));   
        }
    }

}

And error message
User-added image
I can't work out why, I have tried moving all the contact related stuff into an extention but that doesn't work either