You need to sign in to do that
Don't have an account?
Validation error message not displaying correctly.
I have an issue where the validation rule error message on a custom object doesn't appear at the top or field level but instead on a separate page with a DML exception error. I know I could use a catch statment but not sure where to put it.
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The Alternative Delivery date must be after the Delivery Date. Please adjust the Alternative Delivery date.: []
Class.NewRenterOpportunity.Save: line 12, column 1
Class:
public class NewRenterOpportunity { public Opportunity opp{get;set;} public Renter__c rentr{get;set;} public NewRenterOpportunity(ApexPages.StandardController controller) { rentr = (Renter__c)controller.getRecord(); Id id = ApexPages.currentPage().getParameters().get('id'); } public PageReference Save(){ insert rentr; opp = new Opportunity(); opp.Name = rentr.Renter_s_First_Name__c + ' ' + rentr.Name; opp.Renters_Email__c = rentr.Renters_Email__c; opp.Renters_Phone__c = rentr.Renters_Phone__c; opp.StageName = 'Proposal/Price Quote'; opp.CloseDate = System.today()+2; opp.Classification__c = rentr.Classification__c; opp.Lease_Term__c = rentr.Lease_Terms__c; opp.Residential_Opportunity_Source__c = rentr.Source__c; opp.Renter_s_Price_Range__c = rentr.Budget__c; opp.Need_Office_Furniture__c = rentr.Need_Office_Furniture__c; opp.Need_Housewares__c = rentr.Need_Housewares__c; opp.Need_Finishing_Touches__c = rentr.Need_Finishing_Touches__c; opp.Need_Electronics_Appliances__c = rentr.Need_Electronics_Appliances__c; opp.Description_of_Items__c = rentr.Details_of_what_they_need__c; opp.Other_Potential_Renters__c = rentr.Other_that_need_to_rent__c; opp.Pertainent_Notes__c = rentr.Why_the_need_to_rent_furniture__c; opp.Potential_Renters__c = rentr.Other_Potential_Renters__c; opp.Delivery_Date__c = rentr.Delivery_Date__c; opp.Alternate_Delivery_Date__c = rentr.Alternate_Delivery_Date__c; opp.Delivery_Street__c = rentr.Delivery_Street__c; opp.Delivery_City__c = rentr.Delivery_City__c; opp.Delivery_State__c = rentr.Delivery_State__c; opp.Delivery_Zip__c = rentr.Delivery_Zip__c; opp.Showroom__c = rentr.Showroom__c; String AccountId; opp.Corporation__c = rentr.Company__c; insert opp; PageReference ref = new PageReference('/'+opp.id); return ref; } public PageReference NewRenters(){ return null; } public PageReference Cancel(){ return null; } }
just try this
Hello,
We should always write a code by proper exception handling. In your code please use the try catch in save method.
For e.g.
And finally on VF page, please add the following code -
I tried both suggestions and I still get the same error.