• GRStevenBrookes
  • NEWBIE
  • 50 Points
  • Member since 2010

  • Chatter
    Feed
  • 2
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 66
    Questions
  • 131
    Replies

Hi,

 

I am trying to create a record on Lead from an inbound email however am receiving error:

 

The attached message was sent to the Email Service address <inbound_email_to_lead@p-5mwzfrm0nxt6p749ki530zlzk.2ntneeac.2.apex.salesforce.com> but could not be processed because the following error occurred:

554 System.StringException: Starting position out of bounds: 10

Class.CreateLeadfromEmail.handleInboundEmail: line 40, column 1

 Has anyone any ideas - here is the class:

 

/**
 * Email services are automated processes that use Apex classes
 * to process the contents, headers, and attachments of inbound
 * emails.
 */ 
    
global class CreateLeadfromEmail implements 
        Messaging.InboundEmailHandler {

  // Creates new candidate and job application objects  
    
 
Lead[] newLead = new Lead[0];

 global Messaging.InboundEmailResult handleInboundEmail(
  Messaging.InboundEmail email, 
  Messaging.InboundEnvelope envelope) {
Messaging.InboundEmailResult result = 
        new Messaging.InboundEmailresult();
 
  // Captures the sender's email address  
    
String emailAddress = envelope.fromAddress;
 
  // Retrieves the sender's first and last names  
    
String fName = email.fromname.substring(
        0,email.fromname.indexOf(' '));
String lName = email.fromname.substring(
        email.fromname.indexOf(' '));
 
  // Retrieves content from the email.  
    
  // Splits each line by the terminating newline character  
    
  // and looks for the position of the phone number and city  
    

String[] emailBody = email.plainTextBody.split('\n', 0);
String phoneNumber = emailBody[0].substring(10);
String mobileNumber = emailBody[0].substring(11);
String messagenotes = emailBody[0].substring(13);

 
  // Creates a new candidate from the information  
    
  // retrieved from the inbound email  
    
   try
    {
      newLead.add(new Lead(Email = emailAddress,
      FirstName = fName,
      LastName = lName,
      Phone = phoneNumber,
      MobilePhone = mobileNumber,
      Description = messagenotes
      ));
 
      insert newLead;
   }
    
   catch (System.DmlException e)
   {
System.debug('ERROR: Not able to create lead: ' + e);
   }
 
 
return result;
    }   
}

 any help most apprecaited,

 

Steve

Hi All,

 

I know this is likely to be a two tier question, but looking first of all for some guidence on how i can find out what is causing the problem here.

 

Many thanks in advance:

 

Screenshot

Hi All,

 

We have a a number of 'Account Owners' that need to have an equal number of accounts allocated to them, is there a way (either through apex or another method) to lookup how many accounts each owner has and then allocated any new accounts to the owner with the least number of accounts or in the event that 2 or more owners have the same number, to the owner who hasnt had an account allocated to them for the longest amount of time.

 

I hope this makes sense!

 

Thanks in advance for any assistance

 

Steve

Hi,

New to Visualforce but am looking to do something quite simple! Display a list of records where Status__c is not 'Resolved'

 

This is what I have so far:

 

<apex:page standardController="Issues__c" recordSetVar="All Active Issues" tabStyle="Issues__c" sidebar="false" showHeader="false">
<apex:pageBlock title="Current Active Issues"></apex:pageBlock>
<apex:pageBlock >
      <apex:repeat value="{!Issues__c}" var="i"> 
         <apex:outputPanel rendered="true">
        {!i.Name},
        {!i.Status__c},
        </apex:outputPanel>
       </apex:repeat>
       </apex:pageBlock>
</apex:page>

 

 I would effectivly like the typical Salesforce GUI List View to be displayed (using criteria above)---- i have read through the manual but cant seem to grasp it - i am sure its looking me in the face!!

 

Any help much appreciated

 

Steve

 

 

Ok so my knowledge of Apex Triggers has improved over the years (mainly thanks to help from people on here) however I cant get this one:

 

I need a trigger to change the owner on an account when the Type is changed to 'Customer'. The way I need to trigger to decide who to change the owner to by counting the number of  accounts where type is 'Customer' for each Owner 1, Owner 2 and Owner 3 and then assigning the ownership to the Owner with the least Accounts. Where each owner has the same number of accounts, then it should assign ownership to the person who had an account assigned the longest time ago.

 

is this possible?

Hi All,

 

Ive been racking my brains for a solution to my problem, but everyone I come up with is overly complex! So I thought id put it out there!

 

I need to allocate the owner of an Account based on round robin assignment taking into account the number of accounts each 'Owner' has for example

 

Owner 1 has 10 Accounts

Owner 2 has 11 Accounts

Owner 3 has 9 Accounts

 

When a new account is created Owner 3 would be the owner has they ave the least, then 1, then 2.

 

Any ideas?

 

Hi All,

 

Im using this trigger:

trigger UpdateAccountSADependent on Service_Agreement__c (before update) {
Set<Id> esIds=new Set<Id>();
     for (Service_Agreement__c es : trigger.new)
     {
        esIds.add(es.Related_Account__c);
     }

     List<Account> sis=[select id, (select id from Service_Agreements__r where Master_Service_Status__c = 'Live') from Account where id in :esIds];
    
     for(Account si : sis) {
      if(si.service_agreements__r.size()>0) {	  
		  si.HasLiveSA__c = TRUE;
	  if(si.service_agreements__r.size()==0)  {
	  	si.HasLiveSA__c = FALSE;
	  }  
      }
	 }	
   update sis;
}

 however, it has a  flaw, which I am hoping can easily be solved, I just cant get my head around it!

 

It (quite rightly, as coded) only selects Service Agreements where the Master Service Status = Live - so therefore, it sets the HasLiveSA to TRUE, but never FALSE, as for it to be FALSE, the Master Service Status would not be Live! (Hope that makes sense) so is there anyway I can get the trigger to look at all Service Agreement records and where MSS = Live - make HasLiveSA = TRUE and where MSS  = *Any This Else* make HasLiveSA = FALSE.

 

Hope this makes sense.

 

Thanks in advance.

 

Steve

Evening World,

 

I am using the following Apex Trigger and Test Class:

 

trigger AutoAllocateDelegatesToTrainingActions on Training__c (before insert) {
{
	List<Employee_Training_Action__c> listETA = new List<Employee_Training_Action__c> ();
	
	for (Training__C T : trigger.new)
	if(Trigger.isInsert)
	{
	
		
			Employees__c Emp = [SELECT Id FROM Employees__c WHERE Works_Nights_Weekdays__c = TRUE];
			
			listETA.add(new Employee_Training_Action__c(
			Training_Action__c = T.id,
			Employee__c = Emp.id));
		
		if(listETA.size() >0)
		{
			insert listETA;	
		}
	}
}
}

 

@isTest
private class Test_TA_DelegateAllocation {
static testMethod void myUnitTest9()
{
	Service_Agreement__c SA = new Service_Agreement__c ();
	SA.Name = 'Test SA';
	insert SA;
	Training__c TR = new Training__c ();
	TR.Service_Agreement__c=SA.Id;
	insert TR;
	Employee_Training_Action__c ETA = new Employee_Training_Action__c ();
	ETA.Training_Action__c=TR.Id;
	ETA.Employee__c = 'a0l20000001IYYN';
try{	
	insert ETA;}
 catch(System.DmlException e){            
 System.debug('we caught a dml exception: ' + e.getDmlMessage(0));
	}
}
}

 However, when deploying to production I am getting the following error:

 

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AutoAllocateDelegatesToTrainingActions: execution of BeforeInsert

caused by: System.QueryException: List has more than 1 row for assignment to SObject

Trigger.AutoAllocateDelegatesToTrainingActions: line 10, column 23: []

 

I understand what the error is saying, and it is correct, there will be more than one record to create, however, how do i tell the system that this is 'ok'!

 

Help much apprecaited.

 

Steve