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
rv90rv90 

Using IF statement with Contains

for (Task t: triggerNew) {
             If(t.callDisposition.contains('Disconnected')){
           t.type = 'Invalid Contact Information';
        } 
         if(t.callDisposition.contains('Busy')){
            t.type = 'No Answer';
         }
        }
Above is my code where i am trying to developer code where field callDisposition contains 'Disconnected' strings it should update the  type as 'Invalid Contact Information' But what's happening is it is only seeing if the field has exact value (case sensitive) . I want if that field contains  set of any string then IF statement should be true.
Please help me on this.
 
Best Answer chosen by rv90
Leo10Leo10
Check this
string myString;
for (Task t: triggerNew) {
    myString=t.callDisposition.toUpperCase();
    if(myString.contains('DISCONNECTED')){
        t.type = 'Invalid Contact Information';
    } 
    else if(myString.contains('BUSY')){
        t.type = 'No Answer';
    }
}

 

All Answers

Leo10Leo10
Hi 
Try this code
for (Task t: triggerNew) {
	if(t.callDisposition.contains('Disconnected')){
		t.type = 'Invalid Contact Information';
	} 
	else if(t.callDisposition.contains('Busy')){
		t.type = 'No Answer';
	}
}

 
rv90rv90
Hi Nabbel , Thanks for the reply, The code is working fine but only thing is with CONTAINS function. it is checking that the field has exact string or not. My requirement is that if the field contains any string combination of the value entered and should be case Insensitive then it should retirn true.
 
RD@SFRD@SF
Hi Ravitej, 

Do you mean that you callDisposition value might contain "disconnected" value or like any combinations like "disconneCted" ....."discOnnected"
If "disconnected" is the only other combination then,
 
for (Task t: triggerNew) 
{
    if((t.callDisposition.contains('Disconnected')) ||( t.callDisposition.contains('disconnected')))
    {
        t.type = 'Invalid Contact Information';
    }
    else if((t.callDisposition.contains('Busy'))||(t.callDisposition.contains('busy'))
    {
      t.type = 'No Answer';
    }
}

Should do the trick

Hope it helps
RD
Leo10Leo10
Check this
string myString;
for (Task t: triggerNew) {
    myString=t.callDisposition.toUpperCase();
    if(myString.contains('DISCONNECTED')){
        t.type = 'Invalid Contact Information';
    } 
    else if(myString.contains('BUSY')){
        t.type = 'No Answer';
    }
}

 
This was selected as the best answer
rv90rv90
Thanks Nabeel. it worked.