You need to sign in to do that
Don't have an account?
Adil_SFDC
List Index out of bounds 0
public void sendMailAndCreateTask(List<Document> dList)
{
List<Task> taskList = new List<Task>();
String endPoint;
HTTPResponse res;
HttpRequest req = new HttpRequest();
Http http = new Http();
String customizedEmailText = '';
String customizedEmailSub = '';
Contact_Email__c[] ce = [select Subject__c,description__c from Contact_Email__c where user__c = :UserInfo.getUserId()];
if(ce.size() >0 && ce[0].description__c != null)
{
customizedEmailText = EncodingUtil.UrlEncode(ce[0].description__c,'UTF-8');
customizedEmailSub = EncodingUtil.UrlEncode(ce[0].Subject__c,'UTF-8');
}
Integer ra=dList.size() - 1;
// docIdString=dList[0].title;
if(dList!=null &&dList.size()>0) {
selecttitle = dList[0].title+' '+'and'+' '+ra+' '+'others';
selecttitle = EncodingUtil.UrlEncode(selecttitle,'UTF-8');
}
if(dList!=null &&dList.size()==1)
selecttitle = EncodingUtil.UrlEncode(dList[0].title,'UTF-8');
String docIdsSelected ;
if(dList!=null &&dList.size()>0)
docIdsSelected = dList[0].id;
if(dList!=null && dList.size()>1)
for(Integer i=1;i<dList.size();i++){
docIdsSelected = docIdsSelected + ','+dList[i].id;
system.debug('Docdocdoc'+ docIdsSelected );
}
if(isDynamic == 'true'&&ce[0].Subject__c==null ) ( ERROR)
else if(isDynamic == 'true'&&ce[0].Subject__c!=null)
else if(isDynamic == 'false'&&ce[0].Subject__c!=null)
else
system.debug('XXXX'+endpoint);
/*if(testVar == '')
{
res = http.send(req);
JSONParser parser = JSON.createParser(res.getBody());
while (parser.nextToken() != null)
{
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'd'))
{
parser.nextToken();
if(parser.getText() == 'true')
{
taskList.add(t);
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Email sent successfully for the selected documents.'));// \''+d.title+'\'.'));
}
else
{
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Email could not be sent.'));
}
}
}
}*/
boolean dListcountertrack=false;
for(Document d: dList)
{
if(d==dList[0])
dListcountertrack=true;
else
dListcountertrack=false;
// docIdsSelected = d.Id;
// if(isDynamic == 'true')
// else
// system.debug('eeeee'+dList);
req.setMethod('GET');
req.setTimeout(60000);
req.setEndpoint(endPoint);
Task t = new Task();
t.WhoId = c.id;
t.Subject = 'iCentera Dynamic Email sent for '+d.title;
t.status = 'Completed';
t.type = 'Email';
String comments = d.title+'\n\n';
comments += 'Please download and save the following linked file:\n';
comments += '\nTitle:'+d.title;
comments += '\nFormat:'+d.filetype;
comments += '\nDescription:'+d.description;
t.description = comments;
taskList.add(t);
if(testVar == '' && dListcountertrack)
{
res = http.send(req);
JSONParser parser = JSON.createParser(res.getBody());
while (parser.nextToken() != null)
{
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'd'))
{
parser.nextToken();
if(parser.getText() == 'true')
{
// taskList.add(t);
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Email sent successfully for the selected documents.'));// \''+d.title+'\'.'));
}
else
{
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Email could not be sent.'));
}
}
}
}
}
insert taskList;
}
Adil_SFDC,
Before refering to the 0th index of list you must perform a check on whether the list is empty or not.
Hi Rahul
i was waiting for the reply . Here there are no records my list is totally empty.
If my list is empty how do i check this.
Whenever you try to access records from list first check if its empty or not like it is done below:
when i try to fill the list i get the error again . I m trying this
List< Contact_Email__c> lstcon = new List<Contact_Email__c>();
lstcon[0].subject__c= ' ';
insert lstcon;
if(lstcon.size()>0){
if(isDynamic == 'true'&&lstcon[0].subject__c==null)
I get error again
In your code just add a condition and check if it helps:
In previous post it was just an example to explain when to add the check.
i Added this and it works
List< Contact_Email__c> lstcon = new List<Contact_Email__c>();
Contact_Email__c cont = new Contact_Email__c();
cont.subject__c= ' ';
lstcon.add(cont);
if(lstcon.size()>0){
if(isDynamic == 'true'&&lstcon[0].subject__c==null)
Yup that would work too..
Hi Rahul that works but my select title fails
I dont get any error message but the select title doesnt pass in the endpoint.
Any suggestion
Add some debug statements for knowing the cause.
for the solution i tried for inserting contactemail
I get error
Arguement 1 cannot be null in test method.
any solution for this