2

How Do i need to Write APex Code for the CloseDate on Opportunity object?

 Opportunity Opp= new Opportunity();
    Opp.Name='Beginner';
    Opp.CloseDate= ?????;
    Opp.StageName='Proposal';
    insert Opp;

can someone help me out with this ?

1
  • did you check the documentation for date fields, what have you tried?
    – glls
    Commented Aug 14, 2017 at 20:03

2 Answers 2

4

You could use

Opp.CloseDate= System.today();

or

Opp.CloseDate = Date.newInstance(2017, 12, 31);

If you have a string, then you should convert by either of the following ways:

Opp.CloseDate = Date.parse('10/14/2017');

Opp.CloseDate = Date.valueOf('2017-12-15');

For more information, refer Date Class

0
0

You can also use TODAY() function as well. for example, opp.closeDate=TODAY()+1; will give you tomorrow's date or ,opp.closeDate=TODAY() will give you today's date

You must log in to answer this question.

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