You need to sign in to do that
Don't have an account?
Steve Cairney
IF isNotEmpty insert?
Hi, I'm working on creating records using a visualforce page.
I would like the option of creating more than one record (of the same type) if neccessary by adding variables to the class and having declaring them in different columns on the page. It works well, in fact too well! Even if the field is NULL it will create the record.
Here's the class code
What I'd like to do is add something to the class that will ignore the insert of ItsApprovedProduct2, ItsApprovedProduct3 if they are NULL. I'm guessing that might be an IF isNotEmpty statement around the {get;set;} of the variables? I'm not too sure on the syntax though...
I would like the option of creating more than one record (of the same type) if neccessary by adding variables to the class and having declaring them in different columns on the page. It works well, in fact too well! Even if the field is NULL it will create the record.
Here's the class code
public class CreateIABookingController{ public ItsApproved_Booking__c ItsApprovedBooking {get; set;} //Name the objects as a variables public ItsApproved_Product__c ItsApprovedProduct {get; set;} //test variables for columns public ItsApproved_Product__c ItsApprovedProduct2 {get; set;} public ItsApproved_Product__c ItsApprovedProduct3 {get; set;} //end of test variables public ItsApproved_Design__c ItsApprovedDesign {get; set;} public ItsApproved_Delivery__c ItsApprovedDelivery {get; set;} private string OpportunityId; public CreateIABookingController() { opportunityId = ApexPages.currentPage().getParameters().get('oppId'); ItsApprovedBooking = new ItsApproved_Booking__c(); ItsApprovedProduct = new ItsApproved_Product__c(); //test variables for columns ItsApprovedProduct2 = new ItsApproved_Product__c(); ItsApprovedProduct3 = new ItsApproved_Product__c(); //end test variables for columns ItsApprovedDesign = new ItsApproved_Design__c(); ItsApprovedDelivery = new ItsApproved_Delivery__c(); } public PageReference Save() { ItsApprovedBooking.Opportunity__c = opportunityId; insert ItsApprovedBooking; ItsApprovedProduct.Booking_Reference__c = ItsApprovedBooking.Id; //insert the reference field for the parent and declare variable id ItsApprovedProduct.Opp__c = opportunityId; //relate the Opp to the Product insert ItsApprovedProduct; //test for columns ItsApprovedProduct2.Booking_Reference__c = ItsApprovedBooking.Id; ItsApprovedProduct2.Opp__c = opportunityId; insert ItsApprovedProduct2; ItsApprovedProduct3.Booking_Reference__c = ItsApprovedBooking.Id; ItsApprovedProduct3.Opp__c = opportunityId; insert ItsApprovedProduct3; //end test for columns ItsApprovedDesign.Opportunity__c = opportunityId; //relate the Opp to the Design ItsApprovedDesign.Product_Reference__c = ItsApprovedProduct.Id; ItsApprovedDelivery.Product__c = ItsApprovedProduct.Id; insert ItsApprovedDesign; ItsApprovedDelivery.ItsApproved_Design__c = ItsApprovedDesign.Id; ItsApprovedDelivery.Opportunity__c = opportunityId; //relate the Opp to the Delivery insert ItsApprovedDelivery; return new PageReference ('/' + opportunityId); } }
What I'd like to do is add something to the class that will ignore the insert of ItsApprovedProduct2, ItsApprovedProduct3 if they are NULL. I'm guessing that might be an IF isNotEmpty statement around the {get;set;} of the variables? I'm not too sure on the syntax though...
All Answers
However, when I test it, it doesn't seem to work. Perhaps the fields aren't NULL before? They're actually a PICKLIST
They look like this on the VF page
I tried using the code
But that throws up an error
Comparison arguments must be compatible types: ItsApproved_Product__c, String at line 38 column 25
So it looks like I'm going to have to add the
ItsApprovedProduct3.Product_Code__c in there somwhere. I'll run some tests