1

i am using the controller for a vf page where string variable of currentpage id are getting null value.

controller-

public class CreateGiftButtonPageExtension
{
    public Gift__c gift{get;set;}
    public string RecordId{get;set;}
    public string leadid{get;set;}
    public string conid{get;set;}
    public CreateGiftButtonPageExtension()
    {
      conid=Apexpages.currentPage().getParameters().get('ContactId');  
      leadid=Apexpages.currentPage().getParameters().get('LeadId'); 
      system.debug('leadid------>'+leadid);
      system.debug('conid------>'+conid);
        gift = new Gift__c();
        if(conid!=null){
        gift.Contact__c = Apexpages.currentPage().getParameters().get('ContactId'); 
                RecordId = conid;
        }
        else { 
         gift.Lead__c = leadid; 
        RecordId = leadid; 
          }
        gift.Gift_Id__c = ApexPages.currentPage().getParameters().get('gift_id');
        gift.Interest_Idea__c= ApexPages.currentPage().getParameters().get('gift_interest');
        gift.Work_Location__c= ApexPages.currentPage().getParameters().get('gift_work');
        gift.Gift_Reason__c= ApexPages.currentPage().getParameters().get('gift_Reason');
        gift.Relationship__c= ApexPages.currentPage().getParameters().get('gift_relationship');
        gift.City__c= ApexPages.currentPage().getParameters().get('gift_city');
        gift.State__c= ApexPages.currentPage().getParameters().get('gift_state');      
        gift.Age__c= ApexPages.currentPage().getParameters().get('gift_age'); 
        gift.Status__c='Researching'; 
            }

    public pageReference toReceiveParameters()
    {

            insert gift;
            system.debug('gift---------->'+gift);
            return new pageReference('https://ap4.salesforce.com/'+gift.id);
    }
}

1 Answer 1

2

In the code you have posted here, you never actually call get('id'), and I assume that the parameter isn't being set in the url when you request the page.

When you call the code to get parameters from the current page,

Apexpages.currentPage().getParameters().get('ContactId');

it gets the corresponding parameter from the page url. In this case, the ContactId. If you set the ContactId parameter in the url, you should see it being retrieved in your page controller. For ContactId it would look something like:

https://...?ContactId=003XXXXXXXXXXXX&...

Also, if this is an extension, and not an independent page controller,

<apex:page StandardController="Gift__c" extensions="CreateGiftButtonPageExtension">

vs

<apex:page controller="CreateGiftButtonPageExtension">

you should define the constructor with a standard controller as a parameter:

public CreateGiftButtonPageExtension(ApexPages.StandardController controller)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .