0

I have created a wrapper class which creates a record called Remittance_Advice_Line_Item__c, when a user selects a checkbox (called selected), and saves on a Visualforce page.

The record(s) that are created are populated with an amount, also entered by the user (called pickedValue).

There is a second checkbox on the page called pickedCheck, which if selected fires a process builder flow upon record creation. The purpose of the process builder is to overwrite the pickedValue on creation if this checkbox is selected.

I would like to incorporate the process in the class by means of an IF statement and I have attempted (see below), but I am not sure what the syntax would be to do so.

Any help would be appreciated, thanks...

public with sharing class ReconcileInvoicesController {

    public decimal pickedValue {get;set;}
    public String redirectUrl {get;set;}
    public String currentRecordID {get;set;}

    public List<wrapDeliveryNote> wrapDeliveryNoteList {get; set;}
    public List<Delivery_Note__c> selectedDeliveryNotes {get;set;}
    public Remittance_Advice__c CurrentRecordDetail {get;set;}

    public Remittance_Advice__c currentRecord {get;set;}

    public ReconcileInvoicesController() {

        currentRecord = [SELECT id,name,Account__r.name,Account__r.id,AccountId__c,Account__r.parentid FROM Remittance_Advice__c WHERE id = :ApexPages.CurrentPage().getparameters().get('ID')];
        redirectUrl = '/'+currentRecord.Id;

        if(wrapDeliveryNoteList == null) {
            wrapDeliveryNoteList = new List<wrapDeliveryNote>();
            for(Delivery_Note__c d: [
                SELECT id,Name,zRemittancePositiveBalance__c,zRemittanceType__c FROM Delivery_Note__c WHERE AccountId__c = :currentRecord.AccountId__c
            ]){
                wrapDeliveryNoteList.add(new wrapDeliveryNote(d));
                }
        }
    }

    public void processSelected() {
        selectedDeliveryNotes = new List<Delivery_Note__c>();

        List<Remittance_Advice_Line_Item__c> remAdLineItemsTobeInserted = new List<Remittance_Advice_Line_Item__c>();
            for(wrapDeliveryNote wrapDeliveryNoteObj : wrapDeliveryNoteList) {
                if(wrapDeliveryNoteObj.selected == true) {
                    selectedDeliveryNotes.add(wrapDeliveryNoteObj.dn);

                    Remittance_Advice_Line_Item__c newRemItem = new Remittance_Advice_Line_Item__c();
                    newRemItem.Delivery_Note_Invoice__c = wrapDeliveryNoteObj.dn.Id;
                    newRemItem.Remittance_Advice__c = ApexPages.currentPage().getParameters().get('id');

//REPLACE THIS
                    newRemItem.Remittance_Amount__c = wrapDeliveryNoteObj.pickedValue;

//WITH THIS
                    //  newRemItem.Remittance_Amount__c = IF(wrapDeliveryNoteObj.pickedCheck = TRUE,
                    //  wrapDeliveryNoteObj.dn.zRemittancePositiveBalance__c,
                    //  wrapDeliveryNoteObj.pickedValue);

                    newRemItem.Reconciles__c = wrapDeliveryNoteObj.pickedCheck;
                    newRemItem.Line_Item_Type__c = wrapDeliveryNoteObj.dn.zRemittanceType__c;

                    remAdLineItemsTobeInserted.add(newRemItem);
                }
            }
            if(remAdLineItemsTobeInserted.size() > 0){
                insert remAdLineItemsTobeInserted;
            }
        update selectedDeliveryNotes;
    }

    public class wrapDeliveryNote {
        public Delivery_Note__c dn {get;set;}
        public Boolean selected {get;set;}
        public decimal pickedValue {get;set;}
        public Boolean pickedCheck {get;set;}

        public wrapDeliveryNote(Delivery_Note__c d) {
            dn = d;
            selected = false;
            pickedValue = 0;
            pickedCheck = false;
        }
    }
}
3

You can use a ternary statement, which looks like condition? value_when_true : value_when_false.


newRemItem.Remittance_Amount__c = wrapDeliveryNoteObj.pickedCheck?
    wrapDeliveryNoteObj.dn.zRemittancePositiveBalance__c:
    wrapDeliveryNoteObj.pickedValue);

1
  • @TheMikeyBoosh you're welcome!
    – sfdcfox
    Oct 2 '18 at 3:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.