• Andrey
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
Hi all!
I need to pass a value from javascrip (in vf page) to inputField
Here code:
<apex:page standardController="Travel_Expenses__c" extensions="TE_Object" action="{!Parameters}">
    <apex:form >
        <apex:pageBlock title="Travel Information Edit"  mode="edit">
            <apex:pageBlockButtons >
                    <apex:commandButton action="{!Save}" value="Save"/>
                    <apex:commandButton action="{!SaveAndNew}" value="Save & New"/>
                    <apex:commandButton action="{!Cancel}" value="Cancel"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Information" columns="2">
                      <apex:inputField value="{!NewTE.Traveler__c}" id="Traveler" required="true" 
                                       onchange="TakeCountry(this.id);">
                        <apex:actionsupport event="onchange" reRender="CountryName"/>
                    </apex:inputField>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Country" for="CountryName"/>
                    <apex:inputField value="{!NewTE.Country_Name__c}" id="CountryName" />     
                </apex:pageBlockSectionItem>    
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
    <script language="JavaScript1.2" src="/js/functions.js"></script>
    <script src="/soap/ajax/9.0/connection.js" type="text/javascript"></script>
    <script type="text/javascript">
        function TakeCountry(id)
        {
            try
            {
                sforce.connection.sessionId = '{!$Api.Session_ID}';
                var cval = document.getElementById(id).value;
                if (cval!=null)
                {   
                    country=sforce.connection.query("Select Country_Names__c from Travel_Information__c WHERE name='"+cval+"'");
                    alert('Selected '+country);
                    records = country.getArray("records");
                    c=records[0].Country_Names__c;
                    alert('C '+c);//after this message I have an error
                    countryname=document.getElementById({!$Component.CountryName}).value;
                    alert('done ');
                    countryname.value='country';
                    alert('Country '+countryname.value);

                }
            }
            catch (error)
            {
                alert('Error: '+error.faultstring);
            }
        }
    </script>
    
</apex:page>
I add a comment where script failed (Error: undefined)

Thanks!

Hi all!
I created vf page and  when I try to save a new record, I get an error: "System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!Save}' in component <apex:commandButton> in page te_new". 
Can someone tell me, where I'm wrong?
Vf page code:
<apex:page standardController="Travel_Expenses__c" extensions="TE_Object">
    <apex:form >
        <apex:pageBlock title="Travel Information Edit"  mode="edit">
            <apex:pageBlockButtons >
                    <apex:commandButton action="{!Save}" value="Save"/>
                    <apex:commandButton action="{!SaveAndNew}" value="Save & New"/>
                    <apex:commandButton action="{!Cancel}" value="Cancel"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Information" columns="2" >
                <apex:pageBlockSectionItem >
                    Travel Information
                    <apex:inputField value="{!NewTE.Traveler__c}" required="true"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    Expense Type
                    <apex:inputField value="{!NewTE.Expense_Type__c}" required="true"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    Amount
                    <apex:inputField value="{!NewTE.Amount__c}" required="true"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    Country
                    <apex:inputField value="{!NewTE.Country__c}" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    Inventory Number
                    <apex:inputField value="{!NewTE.Inventory_Number__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    Description
                    <apex:inputField value="{!NewTE.Description__c}" required="true"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
apex class:
public class TE_Object 
{
    public Travel_Expenses__c NewTE{get;set;}
    public TE_Object(ApexPages.StandardController controller) {

    }
    
    public pagereference Save()
    {
        try 
        {
            insert NewTE; //Error message on this line
        } 
        catch(System.DMLException e) 
        {
            ApexPages.addMessages(e);
            return null;
        }  
        return null;
    }
    public pagereference SaveAndNew()
    {
        try 
        {  
            insert NewTE; 
        } 
        catch(System.DMLException e) 
        {
            ApexPages.addMessages(e);
            return null;
        }   
        return (new ApexPages.StandardController(new Travel_Expenses__c())).edit();   
    }
    
}



Hi all!
I created vf page and  when I try to save a new record, I get an error: "System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!Save}' in component <apex:commandButton> in page te_new". 
Can someone tell me, where I'm wrong?
Vf page code:
<apex:page standardController="Travel_Expenses__c" extensions="TE_Object">
    <apex:form >
        <apex:pageBlock title="Travel Information Edit"  mode="edit">
            <apex:pageBlockButtons >
                    <apex:commandButton action="{!Save}" value="Save"/>
                    <apex:commandButton action="{!SaveAndNew}" value="Save & New"/>
                    <apex:commandButton action="{!Cancel}" value="Cancel"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Information" columns="2" >
                <apex:pageBlockSectionItem >
                    Travel Information
                    <apex:inputField value="{!NewTE.Traveler__c}" required="true"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    Expense Type
                    <apex:inputField value="{!NewTE.Expense_Type__c}" required="true"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    Amount
                    <apex:inputField value="{!NewTE.Amount__c}" required="true"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    Country
                    <apex:inputField value="{!NewTE.Country__c}" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    Inventory Number
                    <apex:inputField value="{!NewTE.Inventory_Number__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    Description
                    <apex:inputField value="{!NewTE.Description__c}" required="true"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
apex class:
public class TE_Object 
{
    public Travel_Expenses__c NewTE{get;set;}
    public TE_Object(ApexPages.StandardController controller) {

    }
    
    public pagereference Save()
    {
        try 
        {
            insert NewTE; //Error message on this line
        } 
        catch(System.DMLException e) 
        {
            ApexPages.addMessages(e);
            return null;
        }  
        return null;
    }
    public pagereference SaveAndNew()
    {
        try 
        {  
            insert NewTE; 
        } 
        catch(System.DMLException e) 
        {
            ApexPages.addMessages(e);
            return null;
        }   
        return (new ApexPages.StandardController(new Travel_Expenses__c())).edit();   
    }
    
}