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
Joe HayesJoe Hayes 

List to string nearly works but not quite...

Hi Everyone,

I have a controller that gathers a list of names and then creates a string of names and puts them in an email.

The code works but the first name is displayed twice on the list. Can anyone correct it so that it only shows the names once?
 
//Loads of stuff before this...
	
List<Delegate__c> dels = [SELECT id, Name, FROM Delegate__c WHERE accountid__c =: AccountID]
    String listofDels;
      for(Delegate__c del: dels){
        if(listofDels == NULL) listOfDels = del.Name;
        listOfDels = listOfDels+ '<br/>'+del.Name;                   //This is displaying the same del.name twice
    }
	
	//sort all the email stuff out here...
	
	htmlBody = htmlBody.replace('[ListOfDelegates]', listofDels);   //replace text in the email with the new string of names.



Thanks
Joe
Best Answer chosen by Joe Hayes
Krishna SambarajuKrishna Sambaraju
Change the code as follows.
List<Delegate__c> dels = [SELECT id, Name, FROM Delegate__c WHERE accountid__c =: AccountID]
    String listofDels;
      for(Delegate__c del: dels){
        if(listofDels == NULL) listOfDels = del.Name;
        else{listOfDels = listOfDels+ '<br/>'+del.Name;}                   //This is displaying the same del.name twice
    }

All Answers

Krishna SambarajuKrishna Sambaraju
Change the code as follows.
List<Delegate__c> dels = [SELECT id, Name, FROM Delegate__c WHERE accountid__c =: AccountID]
    String listofDels;
      for(Delegate__c del: dels){
        if(listofDels == NULL) listOfDels = del.Name;
        else{listOfDels = listOfDels+ '<br/>'+del.Name;}                   //This is displaying the same del.name twice
    }
This was selected as the best answer
Joe HayesJoe Hayes
Amazing! Thank you works a treat!

Ta
Joe