+ Start a Discussion
shephalishephali 

Integration with Twilio to enable SMS

I am following a link : http://www.codespokes.com/2013/09/how-to-send-sms-on-mobile-from.html

I am getting error with apex code 
"expecting a left angle bracket, found 'getPersonList' at line 15 column 16"
Can anyone please help on this?
public with sharing class TwilioCloudCommunicationClass {  
  
// Public Properties  
public String SelectedMobileNumber{get;set;}  
public String OtherMobileNumber{get;set;}  
public String textMessage{get;set;}  
  
// Default construtor  
public TwilioCloudCommunicationClass()  
{  
    SelectedMobileNumber  = '' ;  
    OtherMobileNumber = '' ;  
}  
  
Public List getPersonList()  
{  
    Try{  
        List localList = new List();  
        localList.add(new SelectOption('' , '--Select--'));  
        for(contact cont : [select Name,MobilePhone from contact where TwilioRegisteredUser__c = true ])  
        {  
            localList.add(new SelectOption(cont.MobilePhone , cont.Name));            
        }        
        localList.add(new SelectOption('other' , 'Other'));  
        return localList ;  
    }  
    catch(Exception e)  
    {  
        ApexPages.addMessages(e);        
        return null;  
    }  
}  
  
public void SendSMS()  
{  
    Try{        
        SelectedMobileNumber = (SelectedMobileNumber == '')? OtherMobileNumber:SelectedMobileNumber ;  
        if(SelectedMobileNumber != '')  
        {  
            List AdminInfo = TwilioConfig__c.getall().values();  
            String ACCOUNT_SID = '';  
            String AUTH_TOKEN  = '' ;              
            String SenderMobileNumber = '' ;  
            // Informaton getting from custom setting  
            if(AdminInfo.size()>0)  
            {            
                ACCOUNT_SID             = AdminInfo[0].AccountSid__c;  
                AUTH_TOKEN              = AdminInfo[0].AuthToken__c;                  
                SenderMobileNumber      = AdminInfo[0].Admin_Mobile_Number__c;      
            }              
            TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);  
             
            Map properties = new Map {  
                        'To'   => SelectedMobileNumber ,  
                        'From' => SenderMobileNumber,  
                        'Body' => textMessage  
                };  
            TwilioSMS message = client.getAccount().getSmsMessages().create(properties);  
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO, 'Message has been sent'));  
        }  
        else  
        {  
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.Error, 'Pelase provide valid Mobile Number '));  
        }  
    }catch(Exception e )  
    {  
        ApexPages.addMessages(e);        
        return ;  
    }    
}  
  
}

 
cloudSavvyProgcloudSavvyProg
Hi Shepali,

Your code is missing the return type on method defintion on line 15. So it should be

Line 15:   Public List getPersonList()  instead change it to  Public List<SelectOption> getPersonList()    
I am assuming from your code you are returning list of select option.

Line 18: List localList = new List();  instead change it to List<SelectOption> localList = new List<SelectOption>(); 

Hope this helps.


Regards,
CloudSavvyProg

 
shephalishephali
Hi CloudSavvyProg,

                 Thanks for your quick response.
Now I am getting one by one error on each list and map as in line no 40(list) and line no 53.(un expected token 'map')

Regards
Shephali
cloudSavvyProgcloudSavvyProg
Hi Shephali,

Sorry for the late response. You might have resolved it already. But just in case you haven't, on line 40 you have define the type of data going to the list. So it might be List<String> AdminInfo = TwilioConfig__c.getall().values();  . Change the List<String> to whatever kind of data you think is coming form TwilioConfig__c.getall().values().

On line 53 again its the type of data that Map holds. So I am assuming it might be string.
Map<String, String> properties = new Map<String, String> { 
54                        'To'  => SelectedMobileNumber , 
55                        'From' => SenderMobileNumber, 
56                        'Body' => textMessage 
57                }; 


For more info on using collections see the below link.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_collections.htm

If this post has resolved your issue, please mark it as solved to close the thread.

Regards,

CloudSavvyProg