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
SUJAY GANGULY 5SUJAY GANGULY 5 

How Can i get a single value from List<String>?

I want to get a value from List<String>. Mean I am storing 3 records at List<String> after that I want to make a checking using that records at Rest  Api Update Time. Please check the code:

List<String>  RecordValueStore= new  List<String>();
List<Account> Acc= new  List<Account>();

Acc=[Select id, Name, Company__c from Account];
For(Account a:Acc){
if(RecordValueStore.get(0).id==Acc.get(0).id){
System.Debug('HI');
}
If Else(RecordValueStore.get(0).Name==Acc.get(0).Name){
System.Debug('Hello');
}

If Else(RecordValueStore.get(0).Comapny__c==Acc.get(0).Comapny__c){
System.Debug('OHH');
}
Update a;
}
Update Acc;

All are working cool, but the problem is happening at normal lits string means from the "RecordValueStore" I can't take the values at checking. It shows that "Variable does not exist: Comapny__c"
Raj VakatiRaj Vakati
Try like this
 
List<String>  RecordValueStore= new  List<String>();
List<Account> Ac=[Select id, Name, Company__c from Account];
For(Account a:Acc){
	If(RecordValueStore.get(0).id!=null && RecordValueStore.get(0)!=null && Acc.get(0).id!=null){
		if(RecordValueStore.get(0).id==Acc.get(0).id){
				System.Debug('HI');
		}
	}
	If(RecordValueStore.get(0).Name!=null && RecordValueStore.get(0)!=null && Acc.get(0).Name!=null){
	
	 if(RecordValueStore.get(0).Name==Acc.get(0).Name){
       System.Debug('Hello');
    }
	}
If(RecordValueStore.get(0).Comapny__c!=null && RecordValueStore.get(0)!=null && Acc.get(0).Comapny__c!=null){
	
	 If(RecordValueStore.get(0).Comapny__c==Acc.get(0).Comapny__c){
		System.Debug('OHH');
	}
}
 }
 Update Acc;

 
SUJAY GANGULY 5SUJAY GANGULY 5
Not Working. the Same error will show.  that "Variable does not exist: Id", mean I can't understand how can I get the individual record values from String List!
Raj VakatiRaj Vakati
My bad 

Change your code like below
 
Map<String,String>  RecordValueStore= new  Map<String,String>();
List<Account> Ac=[Select id, Name, Comapny__c from Account];
For(Account a:Ac){
    If(RecordValueStore.get(a.Id)!=null  && Ac.get(0).id!=null){
        if(RecordValueStore.get(a.Id)==Ac.get(0).id){
            System.Debug('HI');
        }
    }
    If(RecordValueStore.get(a.Name)!=null && Ac.get(0).Name!=null){
        
        if(RecordValueStore.get(a.Name)==Ac.get(0).Name){
            System.Debug('Hello');
        }
    }
    If(RecordValueStore.get(a.Comapny__c)!=null && Ac.get(0).Comapny__c!=null){
        
        If(RecordValueStore.get(a.Comapny__c)==Ac.get(0).Comapny__c){
            System.Debug('OHH');
        }
    }
}
Update Ac;

 
SUJAY GANGULY 5SUJAY GANGULY 5
Challenge not yet complete in My Trailhead Playground 1
Ensure sharing rules from the calling class are enforced for the the 'UtilityClass' Apex class. can you help?