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
venkateshyadav1243venkateshyadav1243 

comparing small letters and capital letters

Hi

I have a scenario

i have to a field on opportunity ,i want populate that value in my account record.

for one account so many opportunitys or there ,so i need to populate distinct values into account object field.

 

ex: i have 1 account ,4 opportunitys

opportunity filed values :

1 a

2 A

3 b

4 B

 

so in the account filed i need to show only  A,B

 

 

How can i do this below is the ,my trigger am populating the values into account filed,but am not able to compare the small and capital letters or the same.

 

trigger Populating_CCY_Pair  on Opportunity (after insert,after update) {
List<opportunity> op=new List<opportunity>();
List<opportunity> opp=new List<opportunity>();
Set<id> accIds = new Set<Id>();
string ccy_pair;
set<string> uniuqvalues=new set<String>();
op=[select id,name,Bought_CCY__c,CCY_Pair__c,Sold_CCY__c,accountid from opportunity where id=:trigger.new];

for(opportunity o:op)
{
if(o.accountid != null)
        {
            accIds.add(o.accountid);
        }
}
Account ac=[select id,name,CCY_Pairs_Traded__c from account where id=:accIds];
opp=[select id,name,Bought_CCY__c,CCY_Pair__c,Sold_CCY__c,accountid  from opportunity where accountid=:accIds];
ccy_pair='';

for(Opportunity o1:opp)
{
if(!uniuqvalues.contains(o1.CCY_Pair__c))
{
uniuqvalues.add(o1.CCY_Pair__c);
ccy_pair=ccy_pair+o1.CCY_Pair__c+';';
system.debug('uniuqvalues of valuews'+ccy_pair);
}
}

ac.CCY_Pairs_Traded__c=ccy_pair.touppercase().trim();

system.debug('account updated fields'+ac.CCY_Pairs_Traded__c);
update ac;
system.debug('account updated records'+ac);

}

 

 

regrads

venkatesh.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Hengky IlawanHengky Ilawan

Hi,

 

You should convert the value into either lower case or upper case before putting it into uniuqvalues.The key for Set is case sensitive.

 

-Hengky-