+ Start a Discussion
tsalbtsalb 

IF AND Syntax for tests before executing code

Newbie here... I've gotten this far but need some help tweaking the syntax - could anyone offer some advice?

 

I'm not sure how to format the IF with an AND condition?

 

public PageReference completeOrder() {       
	Set<String> RErequiredFiles = new Set<String>{'Valuation'};
	Set<String> BOVrequiredFiles = new Set<String>{'Valuation', 'Invoice'};
	List<File__c> existingFiles = new List<File__c>();
	Set<String> uniqueTypes = new Set<String>();
	Service_Request__c ord = [select Status__c, Type__c from Service_Request__c where Id = :orderId];
      
	existingFiles = [select Type__c from File__c where Service_Request__c = :orderId];
      
      for(File__c f: existingFiles) {
        uniqueTypes.add(f.Type__c);
      }
      
      Boolean resultRE = uniqueTypes.containsAll(RErequiredFiles);
      Boolean resultBOV = uniqueTypes.containsAll(BOVrequiredFiles);
      
      PageReference completed = ApexPages.currentPage();    
      
      if(ord.Type__c == 'Unified')
      AND(resultRE == false) {
	ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,
        'Missing required documents');
		ApexPages.addMessage(myMsg);
      }
      else if(ord.Type__c != 'Unified') 
      AND(resultBOV == false) {
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,
        'Missing required documents');
		ApexPages.addMessage(myMsg);

      } else if (ord.Status__c != 'Appraisal Contracted') {
		ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,
		'Order has already been completed, for additional files please utilize the Upload File button');
		ApexPages.addMessage(myMsg);

      } else {     

		ord.Status__c = 'Valuation Received';
		update ord;
		completed = new PageReference('/success');
      }
      
    return completed;
    
}

 

Best Answer chosen by Admin (Salesforce Developers) 
CaptainObviousCaptainObvious

use && instead of AND:

 

    if ( ord.Type__c=='Unified' && resultRE==false )  {
    ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,
        'Missing required documents');
        ApexPages.addMessage(myMsg);
    }

 

All Answers

CaptainObviousCaptainObvious

use && instead of AND:

 

    if ( ord.Type__c=='Unified' && resultRE==false )  {
    ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,
        'Missing required documents');
        ApexPages.addMessage(myMsg);
    }

 

This was selected as the best answer
tsalbtsalb

Your username, this question. Fail on my part.

 

Thank you sir!