function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
shephalishephali 

how to insert value in custom object.

Hello friends,
         I have a custom object(AAA__c) with 3 fields(Name,Lname__c,Rnumber__c).in two fields i am paasing values as follow.
         <apex:inputfield value="{! AAA__c.Name }" /> <br/>
         <apex:inputfield value="{! AAA__c.Lname__c }" /> <br/>
        For last field i am generating a number "{!Rnum}" but how to pass it into the object. so that i can insert it into [AAA__c.Rnumber__c].
 
Best Answer chosen by shephali
Vishal_GuptaVishal_Gupta
Hi Shephali,

Please use below code :

Public class MyExtension
{
  AAA__c a;    
 Integer Rnum=0;
public MyExtension(ApexPages.StandardController con)
{
 a=(AAA__c)con.getRecord(); 
 a.Rnumber__c = getRnum();
}
public Integer getRnum()
   {
      double y = Math.random() ;
      y = 999999 * y;
      Rnum = Math.round((Math.random() * (900000) + 100000));    
     return Rnum;
    }
public PageReference save()

  if(a!=null)
  insert a;
  PageReference pr=new PageReference('/apex/Vpage');
  pr.setRedirect(true);
  return pr;
 }

Please let me know if I can help you more.

Thanks,
Vishal


 

All Answers

Vishal_GuptaVishal_Gupta
Hi Shephali,

You can set value of AAA__c.Rnumber__c in controller of that VF page. As I am assuming you are generating {!Rnum} in controller so its better if you set it in AAA__c.Rnumber__c in controller.

Please let me know if I can help you more.

Thanks,
Vishal
shephalishephali
Hi Vishal,
  Thanks again.here i got stuck that how to set {!Rnum} either in controller or in VF page input field.here is my controller code:--

Public class MyExtension
{
  AAA__c a;    
 Integer Rnum=0;
public MyExtension(ApexPages.StandardController con)
{
 a=(AAA__c)con.getRecord(); 
}
public Integer getRnum()
   {
      double y = Math.random() ;
      y = 999999 * y;
      Rnum = Math.round((Math.random() * (900000) + 100000));    
     return Rnum;
    }
public PageReference save()

  if(a!=null)
  insert a;
  PageReference pr=new PageReference('/apex/Vpage');
  pr.setRedirect(true);
  return pr;
 }
Vishal_GuptaVishal_Gupta
Hi Shephali,

Please use below code :

Public class MyExtension
{
  AAA__c a;    
 Integer Rnum=0;
public MyExtension(ApexPages.StandardController con)
{
 a=(AAA__c)con.getRecord(); 
 a.Rnumber__c = getRnum();
}
public Integer getRnum()
   {
      double y = Math.random() ;
      y = 999999 * y;
      Rnum = Math.round((Math.random() * (900000) + 100000));    
     return Rnum;
    }
public PageReference save()

  if(a!=null)
  insert a;
  PageReference pr=new PageReference('/apex/Vpage');
  pr.setRedirect(true);
  return pr;
 }

Please let me know if I can help you more.

Thanks,
Vishal


 
This was selected as the best answer
shephalishephali
Hi Vishal,
    Thank you so much.It Works as i wanted.
     One more problem how to send this Rnum to next Vpage on button click.
     I tried it as follow:
          pageRef.getParameters().put('R','Rnum');
          N = System.currentPagereference().getParameters().get('R');
But it returns 'Rnum' as string not as its value.