You need to sign in to do that
Don't have an account?
Need help reading value from a list and validating result.
I have a couple of lists in my apex class that I'm trying to check against certain potential query results in order to trigger a conditional set of actions, however they don't seem to be executing as intended and I'm a little perplexed as they contain the trigger values in the tests I'm running, but the conditional don't trigger.
My code is below:
public with sharing class claimSubmitController { private ApexPages.StandardController controller {get; set;} public List<MG_Contract_Holder__c> searchResults {get;set;} public string vin6 {get;set;} public string Name {get;set;} public string contractNum {get;set;} public string descr {get;set;} public string causeLoss {get;set;} public string lDate {get;set;} public string cPhone {get;set;} public string cEmail {get;set;} public static String SEARCH {get{return 'SEARCH';}set;} public static String SHOW {get{return 'SHOW';}set;} public static String HIDE {get{return 'HIDE';}set;} public static String CLAIM_QUESTIONS {get{return 'CLAIM_QUESTIONS';}set;} public static String CLAIM_DONE {get{return 'CLAIM_DONE';}set;} public String currentPage {get;set;} public String buttonStatus {get;set;} public String listChoice {get;set;} public MG_MAG_Claim__c claim {get;set;} // Standard controller public claimSubmitController(ApexPages.StandardController controller) { currentPage = SEARCH; buttonStatus = HIDE; listChoice = HIDE; } // Search button clicked public PageReference search() { String qry = 'SELECT Vin_Number__c, Name, Product_Group__c, Insurer__c, Contract_Number__c FROM MG_Contract_Holder__c WHERE (Vin_Last_6__c =:vin6) AND (Contract_Number__c =:contractNum) AND (Name LIKE \''+String.escapeSingleQuotes(Name)+'%\')'; searchResults = Database.query(qry); List<MG_Contract_Holder__c> c = [SELECT Insurer__c FROM MG_Contract_Holder__c WHERE Vin_Last_6__c =:vin6 AND Contract_Number__c =:contractNum LIMIT 1]; if (c.isEmpty()){ ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'No records found')); hideButton(); return null; } String cD = String.valueOf(c[0]); if(cD == 'NSD' || cD == 'Markel' || cD == 'CarCo' || cD == 'Test Insurer'){ ApexPages.Message err = new ApexPages.Message(ApexPages.Severity.ERROR,'Your policy requires direct interaction with one of our associates, please call the phone number on your policy specified under claims.'); ApexPages.addMessage(err); hideButton(); return null; } else{ showButton(); } return null; } String[] coverage = new String[]{}; public List<SelectOption> getItems() { List<SelectOption> options = new List<SelectOption>(); options.add(new SelectOption('T&W','T&W')); options.add(new SelectOption('WINDSHIELD','Windshield')); options.add(new SelectOption('KEY','Key')); options.add(new SelectOption('PDR','Dent')); return options; } public String[] getCoverage() { return coverage; } public void setCoverage(String[] coverage) { this.coverage = coverage; } public PageReference showButton(){ PageReference pageReference = null; buttonStatus = SHOW; return(pageReference); } public PageReference hideButton(){ PageReference pageReference = null; buttonStatus = HIDE; return(pageReference); } public PageReference hideList(){ PageReference pageReference = null; listChoice = HIDE; return(pageReference); } public PageReference showList(){ PageReference pageReference = null; listChoice = SHOW; return(pageReference); } public PageReference startClaim(){ PageReference pageReference = null; currentPage = CLAIM_QUESTIONS; List<MG_Contract_Holder__c> cvg = [SELECT Product_Group__c FROM MG_Contract_Holder__c WHERE (Vin_Last_6__c =:vin6) AND (Contract_Number__c =:contractNum)]; if (cvg.isEmpty()) { listChoice = HIDE; hideList(); return null; } String cV = String.valueOf(cvg[0]); if(cV == 'MPP' || cV == 'Key Plus' || cV == 'UPP Plus' || cV == 'UPP' || cV == 'MPP TX' || cV == 'MPP Plus' || cV == 'PG01'){ listChoice = SHOW; showList(); } return(pageReference); } public PageReference submitClaim(){ PageReference pageReference = null; currentPage = CLAIM_DONE; return(pageReference); } }
The specific parts I'm having trouble with are:
List<MG_Contract_Holder__c> c = [SELECT Insurer__c FROM MG_Contract_Holder__c WHERE Vin_Last_6__c =:vin6 AND Contract_Number__c =:contractNum LIMIT 1]; if (c.isEmpty()){ ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'No records found')); hideButton(); return null; } String cD = String.valueOf(c[0]); if(cD == 'NSD' || cD == 'Markel' || cD == 'CarCo' || cD == 'Test Insurer'){ ApexPages.Message err = new ApexPages.Message(ApexPages.Severity.ERROR,'Your policy requires direct interaction with one of our associates, please call the phone number on your policy specified under claims.'); ApexPages.addMessage(err); hideButton(); return null; }
And :
List<MG_Contract_Holder__c> cvg = [SELECT Product_Group__c FROM MG_Contract_Holder__c WHERE (Vin_Last_6__c =:vin6) AND (Contract_Number__c =:contractNum)]; if (cvg.isEmpty()) { listChoice = HIDE; hideList(); return null; } String cV = String.valueOf(cvg[0]); if(cV == 'MPP' || cV == 'Key Plus' || cV == 'UPP Plus' || cV == 'UPP' || cV == 'MPP TX' || cV == 'MPP Plus' || cV == 'PG01'){ listChoice = SHOW; showList(); }
I figure that I'm failing to parse the list array properly, but what I have is the only syntax the system would let me use to pull out the item I'm trying to check against without throwing a compile error so any suggestions on improvement would be appreciated.
You are trying to parse a MG_Contract_Holder__c record to a String.
All Answers
You are trying to parse a MG_Contract_Holder__c record to a String.
That helped, much appreciated.