------------------------------------------------------------------------------------------------------------ public class AlertConId { public Contact ct {get;set;} public string fname {get;set;} public string lname {get;set;} public void save() { string first = ApexPages.currentPage().getParameters().get('fname'); string last = ApexPages.currentPage().getParameters().get('lname'); system.debug(first + last); ct = new Contact(); ct.firstname = first; ct.lastname = last; try{ insert ct; } catch(Exception e){} } }", "answerCount": 2, "upvoteCount": 0, "datePublished": "2018-03-13T12:27:34.000Z", "author": { "@type": "Person", "name": "Sandeep Yadav", "url": "https://trailblazers.salesforce.com/profileView?u=0053A00000DLJbrQAH", "affiliation": { "@type": "Organization", "name": "Salesforce" } }, "suggestedAnswer": [ { "@type": "Answer", "text": "Hi Sandeep, When you have set the value in the variables with the help of the param then why did you tried to get it from the URL. You should directly use the variables as set in the page. Please change your code as below : public class AlertConId { public Contact ct {get;set;} public string fname {get;set;} public string lname {get;set;} public void save() { // In your VF page you have set the vaues in the variables fname and lname so directly use them system.debug(fname + lname); ct = new Contact(); ct.firstname = fname; ct.lastname = lname; try{ insert ct; } catch(Exception e){} } } Please let us know if you need any further information or help on this. Thanks, Abhishek Bansal.", "upvoteCount": 1, "url": "https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007T4LEuSAN", "datePublished": "2018-03-13T12:53:39.000Z", "author": { "@type": "Person", "name": "Abhishek Bansal", "url": "https://trailblazers.salesforce.com/profileView?u=0054S000002zQLfQAM", "affiliation": { "@type": "Organization", "name": "Techemega Technology opc Pvt Ltd" } } } ] } } Skip to main content
Sandeep Yadav (Salesforce) 님이 #Apex에 질문했습니다
Hi everyone,

Here is my code--

when I debug it shows null value.

Any suggestion ??

<apex:page controller="AlertConId" >

<script type="text/javascript">

function demo(fst,lst)

{

var fn = document.getElementById(fst).value;

var ln = document.getElementById(lst).value;

myFunction(fn,ln);

}

</script>

<apex:form >

<apex:actionFunction name="myFunction" action="{!save}">

<apex:param value="" name="fname" assignTo="{!fname}"/>

<apex:param value="" name="lname" assignTo="{!lname}"/>

</apex:actionFunction>

<apex:pageBlock id="ref">

<apex:pageBlockSection >

<apex:inputText id="fname" label="FirstName"/>

<apex:inputText id="lname" label="LastName"/>

<apex:commandButton value="Go" onclick="demo('{!$Component.fname}','{!$Component.lname}')" reRender="ref"/>

</apex:pageBlockSection>

</apex:pageBlock>

</apex:form>

</apex:page>

------------------------------------------------------------------------------------------------------------

public class AlertConId

{

public Contact ct {get;set;}

public string fname {get;set;}

public string lname {get;set;}

public void save()

{

string first = ApexPages.currentPage().getParameters().get('fname');

string last = ApexPages.currentPage().getParameters().get('lname');

system.debug(first + last);

ct = new Contact();

ct.firstname = first;

ct.lastname = last;

try{

insert ct;

}

catch(Exception e){}

}

}

 
답변 2개
  1. 2018년 3월 13일 오후 12:53
    Hi Sandeep,

    When you have set the value in the variables with the help of the param then why did you tried to get it from the URL. You should directly use the variables as set in the page. Please change your code as below :

    public class AlertConId

    {

    public Contact ct {get;set;}

    public string fname {get;set;}

    public string lname {get;set;}

    public void save()

    {

    // In your VF page you have set the vaues in the variables fname and lname so directly use them

    system.debug(fname + lname);

    ct = new Contact();

    ct.firstname = fname;

    ct.lastname = lname;

    try{

    insert ct;

    }

    catch(Exception e){}

    }

    }

    Please let us know if you need any further information or help on this.

    Thanks,

    Abhishek Bansal.