function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Forrest MulduneForrest Muldune 

Apex Trigger - Need help with Error Message

All,

I need help with Line 28, view below

User-added image

Am I writing my expression incorrectly?
sailaja majji 5sailaja majji 5
Hi forrest ,

Assignment should not be combined with logical operators .separate in to 2 different statements  .
o.Cinsumer_LOan__c = TRUE ;
o.Consumer_Loan__Hidden__c= FALSE;
Forrest MulduneForrest Muldune
thank you very much
Forrest MulduneForrest Muldune
Sailaja,

Perhaps you could help me with something else. In my Trigger below, I am trying to come up with a solution when one or more loan records contains "Consumer" in the Consumer__c picklist field in Loans, it will always have Consumer_Loan__c = TRUE and Consumer_Loan_Hidden__c = FALSE  in the associated Opportunity. However if the Loan record(s) does not contain "Consumer" in the Consumer__c picklist field, but it contains "Ambiguous", NULL, "'Insufficient information" and "Not Reviewed" in the Consumer__c picklist field then Consumer_Loan__c = FALSE and Consumer_Loan_Hidden__c = TRUE  in the associated Opportunity.

The relationship is One Opportunity for many Loans.

Trigger updateDealWithLoanInfo2 on Loan__c (after insert, after update) {
    if(Trigger.isAfter && ( Trigger.isInsert || Trigger.isUpdate )) {
        map<id,id> dealMap = new map<id,id>();
        set<id> consumerDeals = new set<id>();
        set<id> consumerDealsYellow = new set<id>();
        set<id> participatedDeals = new set<id>();
        list<Loan__c> loans = new List<Loan__c>(); 
        list<Opportunity> deals = new List<Opportunity>(); 
        list<Opportunity> updatedDeals = new List<Opportunity>(); 

        for(Loan__c l : Trigger.new) {
            if(l.Deal__c <> NULL) {
                dealMap.put(l.Deal__c, l.Id);
            }
        }
        if(dealMap.size()>0){
            loans = [Select Deal__c, Consumer__c, Participated__c from Loan__c where Deal__c in :dealMap.keySet()];
            for (Loan__c l2 : loans){
                if(l2.Consumer__c == 'Consumer'){
                    consumerDeals.add(l2.Deal__c);
                }
                if(l2.Consumer__c == 'Ambiguous' || l2.Consumer__c == NULL || l2.Consumer__c == 'Insufficient information'|| l2.Consumer__c == 'Not reviewed'){
                    consumerDealsYellow.add(l2.Deal__c);
                }
                if(l2.Participated__c == TRUE){
                    participatedDeals.add(l2.Deal__c);
                }
            }
            deals = [Select Id, Consumer_Loan__c,Consumer_Loan_Hidden__c, Participated_Loan__c from Opportunity where Id in :dealMap.keySet()];
            for (Opportunity o : deals){
                if(consumerDeals.contains(o.Id)){
                    o.Consumer_Loan__c = TRUE;
                    o.Consumer_Loan_Hidden__c = FALSE;
                }else{
                    o.Consumer_Loan__c = FALSE;
                }
                if(consumerDealsYellow.contains(o.Id)){
                    o.Consumer_Loan_Hidden__c = TRUE;
                }else{
                    o.Consumer_Loan_Hidden__c = FALSE;
                }
                if(participatedDeals.contains(o.Id)){
                    o.Participated_Loan__c = TRUE;
                }else{
                    o.Participated_Loan__c = FALSE;
                }
                updatedDeals.add(o);
            }
            if(updatedDeals.size()>0){
                update updatedDeals;
            }
        }
    }
}

 
sailaja majji 5sailaja majji 5
HI Forrest ,

Just want to checkout if it issolved .Else let me know i have the solution.

Thanks,
Forrest MulduneForrest Muldune
Sailaja,

Sorry for not contacting you sooner. I modified my coding, view below. The only requirement I am trying to resolve is when record(s) from the custom Loan__c object is deleted, I want the trigger to fire as well. I tried creating coding for this requirement but I was unsuccessful. I am requesting if you could assist me on this.

Trigger updateDealWithLoanInfo2 on Loan__c (after insert, after update, before delete) {
    if(Trigger.isAfter && ( Trigger.isInsert || Trigger.isUpdate )) {
        map<id,id> dealMap = new map<id,id>();
        set<id> consumerDeals = new set<id>();
        set<id> consumerDealsYellow = new set<id>();
        set<id> participatedDeals = new set<id>();
        list<Loan__c> loans = new List<Loan__c>();  
        list<Opportunity> deals = new List<Opportunity>();  
        list<Opportunity> updatedDeals = new List<Opportunity>();  

        for(Loan__c l : Trigger.new) {
            if(l.Deal__c <> NULL) {
                dealMap.put(l.Deal__c, l.Id);
            }
        }
        if(dealMap.size()>0){
            loans = [Select Deal__c, Consumer__c, Participated__c from Loan__c where Deal__c in :dealMap.keySet()];
            for (Loan__c l2 : loans){
                if(l2.Consumer__c == 'Consumer'){
                    consumerDeals.add(l2.Deal__c);
                }
                if(l2.Consumer__c == 'Ambiguous' || l2.Consumer__c == NULL || l2.Consumer__c == 'Insufficient information'|| l2.Consumer__c == 'Not reviewed'){
                    consumerDealsYellow.add(l2.Deal__c);
                }
                if(l2.Participated__c == TRUE){
                    participatedDeals.add(l2.Deal__c);
                }
            }
            deals = [Select Id, Consumer_Loan__c,Consumer_Loan_Hidden__c, Participated_Loan__c from Opportunity where Id in :dealMap.keySet()]; 
            for (Opportunity o : deals){
                if(consumerDeals.contains(o.Id)){
                    o.Consumer_Loan__c = TRUE;
                    o.Consumer_Loan_Hidden__c = FALSE;
                }else{
                    o.Consumer_Loan__c = FALSE;
                }
                if(consumerDealsYellow.contains(o.Id)){
                    o.Consumer_Loan_Hidden__c = TRUE;
                }else{
                    o.Consumer_Loan_Hidden__c = FALSE;
                }
                if(participatedDeals.contains(o.Id)){
                    o.Participated_Loan__c = TRUE;
                }else{
                    o.Participated_Loan__c = FALSE;
                }
                updatedDeals.add(o);
            }
            if(updatedDeals.size()>0){
                update updatedDeals;
            }
        }
    }
}