• Anusha Bansal 9
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi,

I need to add two date fields in FORMULAS and get the result in number.
(Progress Date + Approved Date )

Progress Date: Type as Date
Approved Date : Type as Date

Getting below error: 
Error: Incorrect parameter type for operator '+'. Expected Number, received Date

Please suggest
I'm new to VF development. I'm trying to create a button that makes a new opportunity from an existing opportunity and uses some of the values from the old opportunity and changes others. Similar to a clone button but with control over what goes into each field.

I'm using a controller extension for this operation.

I've seen 2 examples of how to get the Id of the current record I'm starting with and I'm trying to determine method is best (or at least the pros/cons of each).  Both methods are in the controller constructor.

Method #1: Using controller.getRecord()
public class myExtension {

    Opportunity currentRecord;
    
    public myExtension(ApexPages.StandardController controller) {
        this.currentRecord = (Opportunity)controller.getRecord();
        currentRecord = [SELECT Id, Name, Amount FROM Opportunity WHERE Id = :currentRecord.Id];
    }

    public Opportunity getcurrentRecord(){
        return currentRecord;
    }
}

Method #2: using Page Parameters
public class myExtension {

    Opportunity currentRecord;
    
    public myExtension(ApexPages.StandardController controller) {
        currentRecord = [SELECT Id, Name, Amount FROM Opportunity WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    }

    public Opportunity getcurrentRecord(){
        return currentRecord;
    }
}

Alternatively, if there is another method better than either of these, please let me know.