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
Samantha ChuaSamantha Chua 

Boolean if Statement stops codes from executing

Hi,

I have a snippet of conditional statements which are not executing ): Anyone knows what I am doing wrong?

These codes work:
//Retrieving email from email template name
            EmailTemplate ABC = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'ABC'];
            EmailTemplate domainX = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'BCS'];
            EmailTemplate efg = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'EFG'];
            EmailTemplate evpl = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'HIJ'];

            
                if (c.Product__c.contains('ABC')) {
                    templateId = ABC.Id;
                } else if (c.Product__c.equals('fib') || c.Product__c.equals('efg')){
                    templateId = efg.Id;
                } else if (c.Product__c.contains('Hosted') || c.Product__c.contains('Domain Name')){
                    templateId = domainX.Id;
                } else if (c.Product__c.contains('EVPL')){
                    templateId = evpl.Id;
                }
            }

However, when i add in one more condition to check, it stopped working ):
Here is a snippet:
 
//Retrieving email from email template name
            EmailTemplate ABC = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'ABC'];
            EmailTemplate domainX = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'BCS'];
            EmailTemplate efg = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'EFG'];
            EmailTemplate evpl = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'HIJ'];
           
            EmailTemplate DDosWS = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'abc'];
            EmailTemplate fiberWS = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'csd'];
            EmailTemplate evplWS = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'sds'];
            
            if (c.Sales_Type__c.equals('Wholesale')) {
                isWholesale = true;
            } else {
                isWholesale = false;
            }
            
            if (isWholesale == false) {
                if (c.Product__c.contains('abc')) {
                    templateId = abc.Id;
                } else if (c.Product__c.equals('Fibernet') || c.Product__c.equals('Lite')){
                    templateId = efg.Id;
                } else if (c.Product__c.contains('Hosted') || c.Product__c.contains('Domain')){
                    templateId = domainX.Id;
                } else if (c.Product__c.contains('EVPL')){
                    templateId = evpl.Id;
                }
            } else {
                if (c.Product__c.contains('abc')) {
                    templateId = DDosWS.Id;
                } else if (c.Product__c.equals('Fibernet') || c.Product__c.equals('Lite')){
                    templateId = fiberWS.Id;
                } else if (c.Product__c.contains('EVPL')){
                    templateId = evplWS.Id;
                }
            }

What am I doing wrong in the boolean check?

Regards,
Samantha
 
Best Answer chosen by Samantha Chua
Samantha ChuaSamantha Chua
Thanks guys, I found out my mistake. I forgot to query for Sales Type, hence I cannot simply just use the field yah. (: awesome. Thanks guys! Best regards, Samantha

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Please try to debug your code and check value

//Retrieving email from email template name
            EmailTemplate ABC = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'ABC'];
            EmailTemplate domainX = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'BCS'];
            EmailTemplate efg = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'EFG'];
            EmailTemplate evpl = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'HIJ'];
           
            EmailTemplate DDosWS = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'abc'];
            EmailTemplate fiberWS = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'csd'];
            EmailTemplate evplWS = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'sds'];
            
            if (c.Sales_Type__c.equals('Wholesale')) {
                isWholesale = true;
            } else {
                isWholesale = false;
            }
            
            if (isWholesale == false)
            {
                System.debug('-----inside-isWholesale-false------------->'+c.Product__c);
                if (c.Product__c.contains('abc')) {
                    templateId = abc.Id;
                } else if (c.Product__c.equals('Fibernet') || c.Product__c.equals('Lite')){
                    templateId = efg.Id;
                } else if (c.Product__c.contains('Hosted') || c.Product__c.contains('Domain')){
                    templateId = domainX.Id;
                } else if (c.Product__c.contains('EVPL')){
                    templateId = evpl.Id;
                }
            }
            else
            {
                System.debug('-----inside-isWholesale-true------------->'+c.Product__c);
                if (c.Product__c.contains('abc')) {
                    templateId = DDosWS.Id;
                } else if (c.Product__c.equals('Fibernet') || c.Product__c.equals('Lite')){
                    templateId = fiberWS.Id;
                } else if (c.Product__c.contains('EVPL')){
                    templateId = evplWS.Id;
                }
            }
Mahesh DMahesh D
Hi Samantha,

What is the error you are getting, 

Also execute the below code and print the deug log here:

 
//Retrieving email from email template name
            EmailTemplate ABC = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'ABC'];
            EmailTemplate domainX = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'BCS'];
            EmailTemplate efg = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'EFG'];
            EmailTemplate evpl = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'HIJ'];
           
            EmailTemplate DDosWS = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'abc'];
            EmailTemplate fiberWS = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'csd'];
            EmailTemplate evplWS = [SELECT ID FROM EmailTemplate WHERE DeveloperName = 'sds'];
            System.debug('=================c.Sales_Type__c:'+c.Sales_Type__c);
            if (c.Sales_Type__c.equals('Wholesale')) {
                isWholesale = true;
            } else {
                isWholesale = false;
            }
            System.debug('=================isWholesale:'+isWholesale);
            if (isWholesale == false) {
				System.debug('==========Line 18=======c.Product__c:'+c.Product__c);
                if (c.Product__c.contains('abc')) {
                    templateId = abc.Id;
                } else if (c.Product__c.equals('Fibernet') || c.Product__c.equals('Lite')){
                    templateId = efg.Id;
                } else if (c.Product__c.contains('Hosted') || c.Product__c.contains('Domain')){
                    templateId = domainX.Id;
                } else if (c.Product__c.contains('EVPL')){
                    templateId = evpl.Id;
                }
            } else {
				System.debug('==========Line 29=======c.Product__c:'+c.Product__c);
                if (c.Product__c.contains('abc')) {
                    templateId = DDosWS.Id;
                } else if (c.Product__c.equals('Fibernet') || c.Product__c.equals('Lite')){
                    templateId = fiberWS.Id;
                } else if (c.Product__c.contains('EVPL')){
                    templateId = evplWS.Id;
                }
            }

Regards,
Mahesh
Samantha ChuaSamantha Chua
Thanks guys, I found out my mistake. I forgot to query for Sales Type, hence I cannot simply just use the field yah. (: awesome. Thanks guys! Best regards, Samantha
This was selected as the best answer