2

I am trying to remove the section of the apex class that references the close date but I am getting an error that record creation failed when selecting my button. Do you have any suggestions?

{public class New_Clinical_Opp_Controller { @AuraEnabled public static string createClinicalOpportunity(Id AccountrecId) { String returnValue = ''; List oppList = new List(); Opportunity oppObject = new Opportunity();

    oppObject.Name = 'Do Not Delete'; 
    oppObject.AccountId = AccountrecId; 
    oppObject.RecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Clinical').getRecordTypeId(); 
    oppObject.StageName = 'Qualification'; 

    Date closeDate = system.today(); 
    closeDate = closeDate.addMonths(6);
oppObject.CloseDate = closeDate;

    oppList.add(oppObject);
    if(!oppList.isEmpty())
{
Database.SaveResult[] a = Database.insert(oppList, false);
if(a[0].isSuccess())
{
  returnValue = oppList[0].id;
}
else
{
  returnValue =  'failure';
}
}

    return returnValue;

}

}

2
  • I see you've received a quality answer, but we'd still appreciate it if you edit your post to include code inline, using the {} tool to format it. Screenshots of code are unfriendly to those on mobile and using assistive technology like screen readers.
    – David Reed
    Jan 11, 2020 at 19:49
  • I apologize. I have edited the post. Thank you!
    – Michelle
    Jan 15, 2020 at 0:21

1 Answer 1

3

CloseDate is a required field for all Opportunities. It's one of those things that we can't change.

So, you can't really remove that particular piece of code. You can change it to be something else but, one way or another, CloseDate must be set.

1
  • Is there anyway for a null value? We want it as a required field but want the opportunity owner to set the close date. Or is it best to just have the default be the date the opportunity is created? Thank you!
    – Michelle
    Jan 15, 2020 at 0:21

You must log in to answer this question.

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