• GRStevenBrookes
  • NEWBIE
  • 50 Points
  • Member since 2010

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

Help, I'm struggling to create a workflow that'll allow me to automatically email a group of users when a certain formula is shown to be TRUE. What I want to achieve is to alert a management group when a user moves an opportunity close date from THIS MONTH to any month after the current month (plus potentially quarter for a separate workflow). 

 

I have been trying to use a combination of ISCHANGED with ISPICKVAL & PRIORVALUE(Field name) but can't get it to work - I just get an error message. The latest version I tried which clearly is wrong was as follows:

 

AND(ISCHANGED(Close_Date), IsWon = FALSE, MONTH(PRIORVALUE(Close_Date))<MONTH(Close_Date))

 

Any help will be appreciated. We track the changing of key fields such as close date and other values.

 

Thanks

 

Mark

 

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,

 

Hope you are all well!

 

Correct me if am wrong, this should be quite simple but cant seem to get my head around it!!

 

2 Objects concerned are Service_Implementation__c and the Standard 'Task' object.

 

What I would like is for when a user creates a task where (Task) RecordType=01220000000JPYY that the 'Description' field on the Task is copied to a field on the 'related to' (which will always be of type 'Service_Implementation__c') called Last_Implementation_Note__c

 

Thats it!

 

Any help appreciated.

 

Steve

 

Hi,

 

have an issue here which i am hoping will be an easy fix.

 

I have an timebased workflow/email alert that sends an email once per hour every 6 hours if a Case is not closed.

 

The criteria are as follows:

 

Evaluation Criteria: When a record is created, or when a record is edited and did not previously meet the rule criteria

Rule Criteria :(Client Management Cases: Case ReasonEQUALSNew Script UAT,New Script QAT) AND (Client Management Cases: Case ClosedEQUALSFalse)

 

Effectivly what happens is when this case if created, the email alerts are loaded into the TBWF queue, as one would expect, howver, when the CaseClosed field, changes to TRUE (via workflow with Re-evaluate Checked) the alerts continue to fire.

 

Any ideas?

 

 

Hi,

 

Cant get my head around this!

 

I am trying to write what I perceive to be quite a simple trigger.

 

I have two objects, the standard Account object and a custom object (Master-Detail (Child)) Service_Agreement__c.

 

When the Owner is changed on the Accoutn object, I need the field Account_Manager_Senior_PA__c on all of the child Service_Agreement__c records (which is connected to the User Object) to be updated with the same 'Owner'.

 

I have started by using:

 

trigger UpdateServiceAgreement_WhenAccMgrAllocated on Account (after update) {

	List<Service_Agreement__c> si = [select Id, Account_Manager_Senior_PA__c from Service_Agreement__c
	 where Account in: Trigger.new ];


for(Service_Agreement__c sic : si){
     sic.Account_Manager_Senior_PA__c = ?????;
}
update si;

}

 ...but @ ?????? get stuck!! not even sure if this would work anyhow.

 

Any help MUCH apprecaited.

 

Steve

I have created the following page:

 

<apex:page standardController="Lead" recordSetVar="Lead" tabStyle="Lead" sidebar="false" showHeader="false">
    <br/>
    <apex:image url="http://www.goresponse.co.uk/wp-content/themes/goresponse/images/go-response-logo-landing.png" />
    <br/>
    <br/>
      <apex:pageBlock title="GoResponse - Inbound Leads (Current Month)">
            <apex:pageBlockTable value="{!Lead}" var="l">
            <apex:column value="{!l.Id}" headerValue="Lead Id" rendered="{!IF(l.VFPage__c <>'No',true,false)}"/>
            <apex:column value="{!l.Name}" headerValue="Contact Name" rendered="{!IF(l.VFPage__c <>'No',true,false)}"/>
            <apex:column value="{!l.Company}" headerValue="Company Name" rendered="{!IF(l.VFPage__c <>'No',true,false)}"/>
            <apex:column value="{!l.LeadSource}" headerValue="Source" rendered="{!IF(l.VFPage__c <>'No',true,false)}"/>
            <apex:column value="{!l.Status}" headerValue="Status" rendered="{!IF(l.VFPage__c <>'No',true,false)}"/>
            <apex:column value="{!l.Disqual_Reason__c}" headerValue="Reason Declined" rendered="{!IF(l.VFPage__c <>'No',true,false)}"/>
            <apex:column value="{!l.Time_Created__c}" headerValue="Date/Time Created" rendered="{!IF(l.VFPage__c <>'No',true,false)}"/>
            <apex:column value="{!l.OwnerId}" headerValue="Lead Owner" rendered="{!IF(l.VFPage__c <>'No',true,false)}"/>
         </apex:pageBlockTable>
              </apex:pageBlock>
</apex:page>

 the problem i have is that the page never shows any data in public view as VFPage__c is a formula field which ofcourse is read only.....i guess that becuase of this its not rendering (although dosnt totally make sense!) is there a workaround?

 

Effectivly the forumla works out if the record should be displayed, the formula is:

 

IF( 
AND( 
MONTH(DATEVALUE( CreatedDate)) = MONTH(TODAY()), 
BEGINS(TEXT( LeadSource), "IB")), 
"Yes", 
"No")

 

Hi All,

 

I have 'manipulated' a previous trigfger used on the Task/Leads object which effectivly marks a checkbox on the Lead object if an associated task is Not Started and in the future. I want to utilise this same functionality for Accounts and related Tasks as well. I think I changed the correct parts of the trigger, however it dosnt trigger! Any ideas would be most appreciated.

 

trigger FlagFutureTasks on Task (after insert, after update) {

Set<Id> leadsToUpdate = new Set<Id>{};
String leadPrefix = Account.SObjectType.getDescribe().getKeyPrefix();

for(Task t : trigger.new)
if(t.WhoId != null && ((String)t.WhoId).startsWith(leadPrefix))  //if not null and whoId belongs to a Lead
leadsToUpdate.add(t.WhoId);
List<Account> updateLeads = new List<Account>{};

for (Account currLead : [Select Id,Has_Future_Scheduled_Activity__c, (Select Id, Status, ActivityDate, Outcome__c from Tasks ORDER BY CreatedDate DESC) from Account where Id IN :leadsToUpdate ])
{
updateLeads.add(currLead);
currLead.Has_Future_Scheduled_Activity__c = false;

for(Task t : currLead.Tasks )
{

if(t.ActivityDate > Date.Today() && t.Status == 'Not Started')
currLead.Has_Future_Scheduled_Activity__c = true;

}//end inner for
}//end outer for

if (updateLeads != null && !updateLeads.isEmpty())
Database.update(updateLeads);

}

 

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

 

 

Hi, 

 

Please could someone help me my telling me why I am gettin the Too Many SOQL Queries Error on the following trigger:

 

trigger CountAccountType_Customer on Account (after delete, after insert, after undelete, 
after update) {

     Set<Id> esIds=new Set<Id>();
     for (Account es : trigger.new)
     {
        esIds.add(es.OwnerId);
     }

     List<User> sis=[select id, of_Accounts_with_Type_Customer__c, (select id from Accounts__r) 
     from User where id in :esIds];
    
     for(User si : sis) {
      
      si.of_Accounts_with_Type_Customer__c  = si.Accounts__r.size();
  }
  update sis;
}

 

Hi All,

 

This seems quite simply in my head - i am sure it is, i just dont seem to be able to get it down on paper!

 

So I have a lookup field on my Account called  Account_Ownership_Tracking__c which there is only 1 record 'Master' All accoounts point to this one record.

 

On the Account_Ownership_Tracking__c object I have a number of fields for example:

 

AccMgr1_LiveClients__c

AccMgr2_LiveClients__c

 

what i need whenever the 'Type' field or the account owner on the Account object is changed, (where type is Customer) and the owner is 'ACcMgr1' for this to update (COUNT) the number of Accounts with Type of Customer and Owned by themselves (AccMgr1) to be added to the field on the Account_Ownership_Tracking__c > AccMgr1_LiveClients__c field.

 

This would also need to decrease when the Type is moved from Customer to anything else.

 

Hope this makes sense and many thanks in advance for any assistance.

 

Steve

Can any one help with this - where am i going wrong?

 

trigger AutoCreateSA on Opportunity (after insert , before update,after update)
{
List<Service_Agreement__c> listSA = new List<Service_Agreement__c>();
List<Commission_Tracking__c> listCOM = new List<Commission_Tracking__c>();
        
        for(Opportunity o : trigger.new)
        {
            if(Trigger.isUpdate)
            {
                if(o.StageName == 'Closed Won' && o.SA_Generated__c == FALSE)
                {
                  listSA.add(new Service_Agreement__c(
                  name = o.Name + ' - ' + o.Service_Type2__c,
                  Related_Account__c = o.accountid,
                  Related_Opportunity__c = o.id,
                  BD_Owner__c=o.OwnerId,
                  DEBUG_BDApprovalREQ__c=o.Sales_Script_Approval_Req__c,
                  Primary_Contact__c = o.Primary_Opportunity_Contact__c));
                  listCOM.add(new Commission_Tracking__c(
                  Opportunity__c = o.Id));
                  
                                 }
            }
            if(Trigger.isInsert)
            {
                if(o.StageName == 'Closed Won' && o.SA_Generated__c == FALSE)
                {
                 listSA.add(new Service_Agreement__c(
                  name = o.Name + ' - ' + o.Service_Type2__c,
                  Related_Account__c = o.accountid,
                  Related_Opportunity__c = o.id,
                  BD_Owner__c=o.OwnerId,
                  DEBUG_BDApprovalREQ__c=o.Sales_Script_Approval_Req__c,
                  Primary_Contact__c = o.Primary_Opportunity_Contact__c));
                  listCOM.add(new Commission_Tracking__c(
                  Opportunity__c = o.Id));
                  
                }
            }
        
        if(listSA.size() > 0)
        {
            o.SA_Generated__c = TRUE;
        }
            
        if(listSA.size() > 0)
        {
            insert listSA;
        }
        if(listCOM.size() > 0)
        {
            insert listCOM;
        }
        }
}

 

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

Morning All,

 

I have limited experience of creating Javabuttons - mainly conditional but am getting stuck on this one and would be most grateful of any assistance.

 

I have 2 objects,

Service_Agreement__c

Service_Implementation__c (Master Detail (Child) to above)

 

The SA will only ever have 1 SI, what i would like is for a button which sets the field on the child object (Service Implementation__c)named Stage__c to 'Set Live' but only when the check box named 'Condition__c' is TRUE. When it is FALSE, then a message should be displayed to the User saying 'Denied'.

 

Many thanks in advance.

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

Evening All,

 

Having a few problems....I effectivly have 2 objects, one called CallScripter_Data__c and another Service_Data__c - the latter being a child of the first via a MDR.

 

Effectivly, records are added to the Service Data object and I want some simple calculations to then appear on the related CallScripter object.

 

Here is my code - which works, but only posts the values for the last record that is ended, rather than summing up all of the records that fit the criteria - like a Roll-Up-Summary - can anyone help with this?

 

trigger CS_Data_Jan12 on Service_Data__c (before insert) {

     Set<Id> esIds=new Set<Id>();
     for (Service_Data__c es : trigger.new)
     {
        esIds.add(es.CallScripter_Data__c);
     }

     List<CallScripter_Data__c> sis=[select id, January12_Total_Calls__c,January12_Total_Minutes__c, (select id, Calls__c,Minutes__c from Service_Data__r) from CallScripter_Data__c where id in :esIds];
    
     for(CallScripter_Data__c si : sis) {
      if(si.Service_Data__r.size()>0) {	  
		  si.January12_Total_Calls__c = si.Service_Data__r[0].Calls__c;
		  si.January12_Total_Minutes__c = si.Service_Data__r[0].Minutes__c;
		  	 }	
  }
  update sis;
}

 

Morning All,

 

Ok, so for the past 3 hours I have been at this. But cant seem to get it working so that both myself and Salesforce UI is happy!

Essentially, I am running a Workflow Field Update to insert the Date and Time, something is 'due', the value of when this is is dependent on the day and the time of the day. For example Between 9am and 3pm Monday-Thursday, the due date is in an hours time, another example, on a Saturday, the due date is 9am on Monday (same for sunday). So, I first looked into how to get add and subtract time from a Now() value and thanks to some well documented support, I realised it was a simple calculation, i.e to add 1 hour you would use something like this Now() + (1/24), so I went and laid out my fomula - without realising it wouldnt fit in the field on the UI so this wouldnt work:

 

/////OLD FULL DETAIL FORMULA - TOO LONG FOR SALESFORCE//////

IF(
AND(
OR( 
DEBUG_SACreatedDay__c = "Monday",
DEBUG_SACreatedDay__c = "Tuesday",
DEBUG_SACreatedDay__c = "Wednesday",
DEBUG_SACreatedDay__c = "Thursday",
DEBUG_SACreatedDay__c = "Friday"),
OR(
BEGINS(DEBUG_SAHourCreated__c,"09"),
BEGINS(DEBUG_SAHourCreated__c,"10"),
BEGINS(DEBUG_SAHourCreated__c,"11"),
BEGINS(DEBUG_SAHourCreated__c,"12"),
BEGINS(DEBUG_SAHourCreated__c,"13"),
BEGINS(DEBUG_SAHourCreated__c,"14"),
BEGINS(DEBUG_SAHourCreated__c,"15"),
BEGINS(DEBUG_SAHourCreated__c,"16"))),
NOW()+ (1/24),
IF(
AND(
OR( 
DEBUG_SACreatedDay__c = "Monday",
DEBUG_SACreatedDay__c = "Tuesday",
DEBUG_SACreatedDay__c = "Wednesday",
DEBUG_SACreatedDay__c = "Thursday"),
BEGINS(DEBUG_SAHourCreated__c,"17")),
NOW()-(1/3)+1,
IF(
AND(
OR( 
DEBUG_SACreatedDay__c = "Monday",
DEBUG_SACreatedDay__c = "Tuesday",
DEBUG_SACreatedDay__c = "Wednesday",
DEBUG_SACreatedDay__c = "Thursday"),
BEGINS(DEBUG_SAHourCreated__c,"18")),
NOW()-(1/2.66)+1,
IF(
AND(
OR( 
DEBUG_SACreatedDay__c = "Monday",
DEBUG_SACreatedDay__c = "Tuesday",
DEBUG_SACreatedDay__c = "Wednesday",
DEBUG_SACreatedDay__c = "Thursday"),
BEGINS(DEBUG_SAHourCreated__c,"19")),
NOW()-(1/2.4)+1,
IF(
AND(
OR( 
DEBUG_SACreatedDay__c = "Monday",
DEBUG_SACreatedDay__c = "Tuesday",
DEBUG_SACreatedDay__c = "Wednesday",
DEBUG_SACreatedDay__c = "Thursday"),
BEGINS(DEBUG_SAHourCreated__c,"20")),
NOW()-(1/2.18)+1,
IF(
AND(
OR( 
DEBUG_SACreatedDay__c = "Monday",
DEBUG_SACreatedDay__c = "Tuesday",
DEBUG_SACreatedDay__c = "Wednesday",
DEBUG_SACreatedDay__c = "Thursday"),
BEGINS(DEBUG_SAHourCreated__c,"21")),
NOW()-(1/2)+1,
IF(
AND(
OR( 
DEBUG_SACreatedDay__c = "Monday",
DEBUG_SACreatedDay__c = "Tuesday",
DEBUG_SACreatedDay__c = "Wednesday",
DEBUG_SACreatedDay__c = "Thursday"),
BEGINS(DEBUG_SAHourCreated__c,"22")),
NOW()-(1/1.84)+1,
IF(
AND(
OR( 
DEBUG_SACreatedDay__c = "Monday",
DEBUG_SACreatedDay__c = "Tuesday",
DEBUG_SACreatedDay__c = "Wednesday",
DEBUG_SACreatedDay__c = "Thursday"),
BEGINS(DEBUG_SAHourCreated__c,"23")),
NOW()-(1/1.71)+1,
IF(
AND(
OR( 
DEBUG_SACreatedDay__c = "Monday",
DEBUG_SACreatedDay__c = "Tuesday",
DEBUG_SACreatedDay__c = "Wednesday",
DEBUG_SACreatedDay__c = "Thursday"),
BEGINS(DEBUG_SAHourCreated__c,"00")),
NOW()+(1/2.66),
IF(
AND(
OR( 
DEBUG_SACreatedDay__c = "Monday",
DEBUG_SACreatedDay__c = "Tuesday",
DEBUG_SACreatedDay__c = "Wednesday",
DEBUG_SACreatedDay__c = "Thursday"),
BEGINS(DEBUG_SAHourCreated__c,"01")),
NOW()+(1/3),
IF(
AND(
OR( 
DEBUG_SACreatedDay__c = "Monday",
DEBUG_SACreatedDay__c = "Tuesday",
DEBUG_SACreatedDay__c = "Wednesday",
DEBUG_SACreatedDay__c = "Thursday"),
BEGINS(DEBUG_SAHourCreated__c,"02")),
NOW()+(1/3.42),
IF(
AND(
OR( 
DEBUG_SACreatedDay__c = "Monday",
DEBUG_SACreatedDay__c = "Tuesday",
DEBUG_SACreatedDay__c = "Wednesday",
DEBUG_SACreatedDay__c = "Thursday"),
BEGINS(DEBUG_SAHourCreated__c,"03")),
NOW()+(1/4),
IF(
AND(
OR( 
DEBUG_SACreatedDay__c = "Monday",
DEBUG_SACreatedDay__c = "Tuesday",
DEBUG_SACreatedDay__c = "Wednesday",
DEBUG_SACreatedDay__c = "Thursday"),
BEGINS(DEBUG_SAHourCreated__c,"04")),
NOW()+(1/4.8),
IF(
AND(
OR( 
DEBUG_SACreatedDay__c = "Monday",
DEBUG_SACreatedDay__c = "Tuesday",
DEBUG_SACreatedDay__c = "Wednesday",
DEBUG_SACreatedDay__c = "Thursday"),
BEGINS(DEBUG_SAHourCreated__c,"05")),
NOW()+(1/6),
IF(
AND(
OR( 
DEBUG_SACreatedDay__c = "Monday",
DEBUG_SACreatedDay__c = "Tuesday",
DEBUG_SACreatedDay__c = "Wednesday",
DEBUG_SACreatedDay__c = "Thursday"),
BEGINS(DEBUG_SAHourCreated__c,"06")),
NOW()+(1/8),
IF(
AND(
OR( 
DEBUG_SACreatedDay__c = "Monday",
DEBUG_SACreatedDay__c = "Tuesday",
DEBUG_SACreatedDay__c = "Wednesday",
DEBUG_SACreatedDay__c = "Thursday"),
BEGINS(DEBUG_SAHourCreated__c,"07")),
NOW()+(1/12),
IF(
AND(
OR( 
DEBUG_SACreatedDay__c = "Monday",
DEBUG_SACreatedDay__c = "Tuesday",
DEBUG_SACreatedDay__c = "Wednesday",
DEBUG_SACreatedDay__c = "Thursday"),
BEGINS(DEBUG_SAHourCreated__c,"08")),
NOW()+(1/24),
IF(
AND(
DEBUG_SACreatedDay__c = "Friday",
BEGINS(DEBUG_SAHourCreated__c,"17")),
NOW()-(1/3)+3,
IF(
AND(
DEBUG_SACreatedDay__c = "Friday",
BEGINS(DEBUG_SAHourCreated__c,"18")),
NOW()-(1/2.66)+3,
IF(
AND(
DEBUG_SACreatedDay__c = "Friday",
BEGINS(DEBUG_SAHourCreated__c,"19")),
NOW()-(1/2.4)+3,
IF(
AND(
DEBUG_SACreatedDay__c = "Friday",
BEGINS(DEBUG_SAHourCreated__c,"20")),
NOW()-(1/2.18)+3,
IF(
AND(
DEBUG_SACreatedDay__c = "Friday",
BEGINS(DEBUG_SAHourCreated__c,"21")),
NOW()-(1/2)+3,
IF(
AND(
DEBUG_SACreatedDay__c = "Friday",
BEGINS(DEBUG_SAHourCreated__c,"22")),
NOW()-(1/1.84)+3,
IF(
AND(
DEBUG_SACreatedDay__c = "Friday",
BEGINS(DEBUG_SAHourCreated__c,"23")),
NOW()-(1/1.71)+3,
IF(
AND(
DEBUG_SACreatedDay__c = "Monday",
BEGINS(DEBUG_SAHourCreated__c,"00")),
NOW()+ (1/2.6),
IF(
AND(
DEBUG_SACreatedDay__c = "Monday",
BEGINS(DEBUG_SAHourCreated__c,"01")),
NOW()+ (1/3),
IF(
AND(
DEBUG_SACreatedDay__c = "Monday",
BEGINS(DEBUG_SAHourCreated__c,"02")),
NOW()+ (1/3.42),
IF(
AND(
DEBUG_SACreatedDay__c = "Monday",
BEGINS(DEBUG_SAHourCreated__c,"03")),
NOW()+ (1/4),
IF(
AND(
DEBUG_SACreatedDay__c = "Monday",
BEGINS(DEBUG_SAHourCreated__c,"04")),
NOW()+ (1/4.8),
IF(
AND(
DEBUG_SACreatedDay__c = "Monday",
BEGINS(DEBUG_SAHourCreated__c,"05")),
NOW()+ (1/6),
IF(
AND(
DEBUG_SACreatedDay__c = "Monday",
BEGINS(DEBUG_SAHourCreated__c,"06")),
NOW()+ (1/8),
IF(
AND(
DEBUG_SACreatedDay__c = "Monday",
BEGINS(DEBUG_SAHourCreated__c,"07")),
NOW()+ (1/12),
IF(
AND(
DEBUG_SACreatedDay__c = "Monday",
BEGINS(DEBUG_SAHourCreated__c,"08")),
NOW()+ (1/24),
IF(
AND(
DEBUG_SACreatedDay__c = "Monday",
BEGINS(DEBUG_SAHourCreated__c,"09")),
NOW()+ (1/24),
IF(
AND(
DEBUG_SACreatedDay__c = "Saturday",
BEGINS(DEBUG_SAHourCreated__c,"00")),
NOW()+ (1/2.6)+2,
IF(
AND(
DEBUG_SACreatedDay__c = "Saturday",
BEGINS(DEBUG_SAHourCreated__c,"01")),
NOW()+ (1/3)+2,
IF(
AND(
DEBUG_SACreatedDay__c = "Saturday",
BEGINS(DEBUG_SAHourCreated__c,"02")),
NOW()+ (1/3.42)+2,
IF(
AND(
DEBUG_SACreatedDay__c = "Saturday",
BEGINS(DEBUG_SAHourCreated__c,"03")),
NOW()+ (1/4)+2,
IF(
AND(
DEBUG_SACreatedDay__c = "Saturday",
BEGINS(DEBUG_SAHourCreated__c,"04")),
NOW()+ (1/4.8)+2,
IF(
AND(
DEBUG_SACreatedDay__c = "Saturday",
BEGINS(DEBUG_SAHourCreated__c,"05")),
NOW()+ (1/6)+2,
IF(
AND(
DEBUG_SACreatedDay__c = "Saturday",
BEGINS(DEBUG_SAHourCreated__c,"06")),
NOW()+ (1/8)+2,
IF(
AND(
DEBUG_SACreatedDay__c = "Saturday",
BEGINS(DEBUG_SAHourCreated__c,"07")),
NOW()+ (1/12)+2,
IF(
AND(
DEBUG_SACreatedDay__c = "Saturday",
BEGINS(DEBUG_SAHourCreated__c,"08")),
NOW()+ (1/24)+2,
IF(
AND(
DEBUG_SACreatedDay__c = "Saturday",
BEGINS(DEBUG_SAHourCreated__c,"09")),
NOW() +2,
IF(
AND(
DEBUG_SACreatedDay__c = "Saturday",
BEGINS(DEBUG_SAHourCreated__c,"10")),
NOW()- (1/24)+2,
IF(
AND(
DEBUG_SACreatedDay__c = "Saturday",
BEGINS(DEBUG_SAHourCreated__c,"11")),
NOW()-(1/12)+2,
IF(
AND(
DEBUG_SACreatedDay__c = "Saturday",
BEGINS(DEBUG_SAHourCreated__c,"12")),
NOW()-(1/8)+2,
IF(
AND(
DEBUG_SACreatedDay__c = "Saturday",
BEGINS(DEBUG_SAHourCreated__c,"13")),
NOW()- (1/6)+2,
IF(
AND(
DEBUG_SACreatedDay__c = "Saturday",
BEGINS(DEBUG_SAHourCreated__c,"14")),
NOW()-(1/4.8)+2,
IF(
AND(
DEBUG_SACreatedDay__c = "Saturday",
BEGINS(DEBUG_SAHourCreated__c,"15")),
NOW()-(1/4)+2,
IF(
AND(
DEBUG_SACreatedDay__c = "Saturday",
BEGINS(DEBUG_SAHourCreated__c,"16")),
NOW()-(1/3.42)+2,
IF(
AND(
DEBUG_SACreatedDay__c = "Saturday",
BEGINS(DEBUG_SAHourCreated__c,"17")),
NOW()-(1/3)+2,
IF(
AND(
DEBUG_SACreatedDay__c = "Saturday",
BEGINS(DEBUG_SAHourCreated__c,"18")),
NOW()-(1/2.66)+2,
IF(
AND(
DEBUG_SACreatedDay__c = "Saturday",
BEGINS(DEBUG_SAHourCreated__c,"19")),
NOW()-(1/2.4)+2,
IF(
AND(
DEBUG_SACreatedDay__c = "Saturday",
BEGINS(DEBUG_SAHourCreated__c,"20")),
NOW()-(1/2.18)+2,
IF(
AND(
DEBUG_SACreatedDay__c = "Saturday",
BEGINS(DEBUG_SAHourCreated__c,"21")),
NOW()-(1/2)+2,
IF(
AND(
DEBUG_SACreatedDay__c = "Saturday",
BEGINS(DEBUG_SAHourCreated__c,"22")),
NOW()-(1/1.84)+2,
IF(
AND(
DEBUG_SACreatedDay__c = "Saturday",
BEGINS(DEBUG_SAHourCreated__c,"23")),
NOW()-(1/1.71)+2,
IF(
AND(
DEBUG_SACreatedDay__c = "Sunday",
BEGINS(DEBUG_SAHourCreated__c,"00")),
NOW()+ (1/2.6)+1,
IF(
AND(
DEBUG_SACreatedDay__c = "Sunday",
BEGINS(DEBUG_SAHourCreated__c,"01")),
NOW()+ (1/3)+1,
IF(
AND(
DEBUG_SACreatedDay__c = "Sunday",
BEGINS(DEBUG_SAHourCreated__c,"02")),
NOW()+ (1/3.42)+1,
IF(
AND(
DEBUG_SACreatedDay__c = "Sunday",
BEGINS(DEBUG_SAHourCreated__c,"03")),
NOW()+ (1/4)+1,
IF(
AND(
DEBUG_SACreatedDay__c = "Sunday",
BEGINS(DEBUG_SAHourCreated__c,"04")),
NOW()+ (1/4.8)+1,
IF(
AND(
DEBUG_SACreatedDay__c = "Sunday",
BEGINS(DEBUG_SAHourCreated__c,"05")),
NOW()+ (1/6)+1,
IF(
AND(
DEBUG_SACreatedDay__c = "Sunday",
BEGINS(DEBUG_SAHourCreated__c,"06")),
NOW()+ (1/8)+1,
IF(
AND(
DEBUG_SACreatedDay__c = "Sunday",
BEGINS(DEBUG_SAHourCreated__c,"07")),
NOW()+ (1/12)+1,
IF(
AND(
DEBUG_SACreatedDay__c = "Sunday",
BEGINS(DEBUG_SAHourCreated__c,"08")),
NOW()+ (1/24)+1,
IF(
AND(
DEBUG_SACreatedDay__c = "Sunday",
BEGINS(DEBUG_SAHourCreated__c,"09")),
NOW() +1,
IF(
AND(
DEBUG_SACreatedDay__c = "Sunday",
BEGINS(DEBUG_SAHourCreated__c,"10")),
NOW()- (1/24)+1,
IF(
AND(
DEBUG_SACreatedDay__c = "Sunday",
BEGINS(DEBUG_SAHourCreated__c,"11")),
NOW()-(1/12)+1,
IF(
AND(
DEBUG_SACreatedDay__c = "Sunday",
BEGINS(DEBUG_SAHourCreated__c,"12")),
NOW()-(1/8)+1,
IF(
AND(
DEBUG_SACreatedDay__c = "Sunday",
BEGINS(DEBUG_SAHourCreated__c,"13")),
NOW()- (1/6)+1,
IF(
AND(
DEBUG_SACreatedDay__c = "Sunday",
BEGINS(DEBUG_SAHourCreated__c,"14")),
NOW()-(1/4.8)+1,
IF(
AND(
DEBUG_SACreatedDay__c = "Sunday",
BEGINS(DEBUG_SAHourCreated__c,"15")),
NOW()-(1/4)+1,
IF(
AND(
DEBUG_SACreatedDay__c = "Sunday",
BEGINS(DEBUG_SAHourCreated__c,"16")),
NOW()-(1/3.42)+1,
IF(
AND(
DEBUG_SACreatedDay__c = "Sunday",
BEGINS(DEBUG_SAHourCreated__c,"17")),
NOW()-(1/3)+1,
IF(
AND(
DEBUG_SACreatedDay__c = "Sunday",
BEGINS(DEBUG_SAHourCreated__c,"18")),
NOW()-(1/2.66)+1,
IF(
AND(
DEBUG_SACreatedDay__c = "Sunday",
BEGINS(DEBUG_SAHourCreated__c,"19")),
NOW()-(1/2.4)+1,
IF(
AND(
DEBUG_SACreatedDay__c = "Sunday",
BEGINS(DEBUG_SAHourCreated__c,"20")),
NOW()-(1/2.18)+1,
IF(
AND(
DEBUG_SACreatedDay__c = "Sunday",
BEGINS(DEBUG_SAHourCreated__c,"21")),
NOW()-(1/2)+1,
IF(
AND(
DEBUG_SACreatedDay__c = "Sunday",
BEGINS(DEBUG_SAHourCreated__c,"22")),
NOW()-(1/1.84)+1,
IF(
AND(
DEBUG_SACreatedDay__c = "Sunday",
BEGINS(DEBUG_SAHourCreated__c,"23")),
NOW()-(1/1.71)+1),
NOW() + (1/24)
)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))

 So i then thought, how do i shorten this, so decided to put the decimal/fraction part into its own field using a CASE statement like this:

 

CASE"(VALUE"(LEFT"( DEBUG_SAHourCreated__c,2)")",
0,2.66,
1,3.0,
2,3.42,
3,4.0,
4,4.8,
5,6.0,
6,8.0,
7,12,
8,24,
9,0,
10,24,
11,12,
12,8,
13,6,
14,4.8,
15,4,
16,3.42,
17,3,
18,2.66,
19,2.4,
20,2.18,
21,2.0,
22,1.84,
23,1.71,
0)"

 and then re-wrote the orginial formula to reference this (a lot shorter in size!):

 

IF(
AND(
VALUE(LEFT( DEBUG_SAHourCreated__c,2))>=9,
VALUE(LEFT( DEBUG_SAHourCreated__c,2))<=15,
OR( 
DEBUG_SACreatedDay__c = "Monday",
DEBUG_SACreatedDay__c = "Tuesday",
DEBUG_SACreatedDay__c = "Wednesday",
DEBUG_SACreatedDay__c = "Thursday",
DEBUG_SACreatedDay__c = "Friday")),
NOW()+ (1/24),
IF(
AND(
VALUE(LEFT( DEBUG_SAHourCreated__c,2))>15,
VALUE(LEFT( DEBUG_SAHourCreated__c,2))<24,
OR( 
DEBUG_SACreatedDay__c = "Monday",
DEBUG_SACreatedDay__c = "Tuesday",
DEBUG_SACreatedDay__c = "Wednesday",
DEBUG_SACreatedDay__c = "Thursday")),
NOW()-(DEBUG_WC_Time_Decimal__c)+1,
IF(
AND(
VALUE(LEFT( DEBUG_SAHourCreated__c,2))>=0,
VALUE(LEFT( DEBUG_SAHourCreated__c,2))<9,
OR( 
DEBUG_SACreatedDay__c = "Monday",
DEBUG_SACreatedDay__c = "Tuesday",
DEBUG_SACreatedDay__c = "Wednesday",
DEBUG_SACreatedDay__c = "Thursday",
DEBUG_SACreatedDay__c = "Friday")),
NOW()+(DEBUG_WC_Time_Decimal__c),
IF(
AND(
VALUE(LEFT( DEBUG_SAHourCreated__c,2))>15,
VALUE(LEFT( DEBUG_SAHourCreated__c,2))<24,
DEBUG_SACreatedDay__c = "Friday"),
NOW()-(DEBUG_WC_Time_Decimal__c)+3,
IF(
AND(
VALUE(LEFT( DEBUG_SAHourCreated__c,2))>15,
VALUE(LEFT( DEBUG_SAHourCreated__c,2))<24,
DEBUG_SACreatedDay__c = "Saturday"),
NOW()-(DEBUG_WC_Time_Decimal__c)+2,
IF(
AND(
VALUE(LEFT( DEBUG_SAHourCreated__c,2))>=0,
VALUE(LEFT( DEBUG_SAHourCreated__c,2))<9,
DEBUG_SACreatedDay__c = "Saturday"),
NOW()+(DEBUG_WC_Time_Decimal__c)+2,
IF(
AND(
VALUE(LEFT( DEBUG_SAHourCreated__c,2))>15,
VALUE(LEFT( DEBUG_SAHourCreated__c,2))<24,
DEBUG_SACreatedDay__c = "Sunday"),
NOW()-(DEBUG_WC_Time_Decimal__c)+1,
IF(
AND(
VALUE(LEFT( DEBUG_SAHourCreated__c,2))>=0,
VALUE(LEFT( DEBUG_SAHourCreated__c,2))<9,
DEBUG_SACreatedDay__c = "Sunday"),
NOW()+(DEBUG_WC_Time_Decimal__c)+1,
NOW()))))))))

 however!!!!! using this method, SF calculates in a different way - instead of doing Now() + (1/24) + 1 (for example) it does Now() + 0.041 + 1, which gives a totally different answer, in fact SF just adds 1.041 days onto the Now().

 

Can any one offer any help here? Either utilising the hard work I have put in above, or any other way to acheive what I am trying to achieve.

 

Many thanks in advance, sorry for the long post!

 

Steve

 

Hi All,

 

Sure this is a syntax problem, but cant get my head around it:

 

{!REQUIRESCRIPT("/soap/ajax/18.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/18.0/apex.js")} 

var connection =sforce.connection; 
var CA = "{!CMC__c.DEBUG_ofCompletedAssessments__c}";
var User = "{!$User.Full_Name__c}",
var CR = "{!CMC__c.Case_Reason__c}",
var URL = "{!CMC__c.UAT_QAT_Zoomerang_URL__c}",

IF( 
                AND( 
                                CA <1, 
                                OR( 
                                                CR = "New Script QAT", 
                                                CR = "New Script UAT"
                                  )
                                )
                { 
                                window.open('URL');
                }
)
else{
alert("Either an Assessment is not applicable for this case, or you are not authorised to complete assessments");
}

 

 

 I get 'Unexpected Identifier' when clicking?

 

Any help appreciated.

Hi,

 

is there a way of calculating the week in the month (i.e Week 1-5) that an opportunity is marked as closed won.

I gather a formula field is the best way - but cant work out how it would be done?

 

Thanks in advance for your help.

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