• jjackson1.391016164401765E12
  • NEWBIE
  • 5 Points
  • Member since 2014
  • Application Programmer
  • Sonifi Solutions

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 6
    Replies
Hi
I'm doing a trigger that is triggered from the Assigned Resource.  The trigger works in the UI, however, I'm having an issue with the Test Code.

I receive an error:
FIELD_CUSTOM_VALIDATION_EXCEPTION, Cannot change status from New to Scheduled: []

Now, if i do the same from the UI, there is no error regarding the status change.  The status change is allowed in the FSL administration.  I can assign using the dispatcher console - all good.  And I can mimic the process i'm using in the test code in the UI (editing the SA directly) with out error.  
Wondering if any one has seen this error before?
Code is included below:
@isTest static void test_AssignedResource_Insert() {
		List<AssignedResource> toInsert = new List<AssignedResource>();

		//retrieve a service resource
		List<ServiceResource> listSR = new List<ServiceResource>([SELECT Id, Name FROM ServiceResource WHERE Name = 'Technician One']);
		ServiceResource sr1 = listSR[0];

		// retrieve the Service Appointment created by test data
		List<WorkOrder> workOrders = new List<WorkOrder>([SELECT Id FROM WorkOrder WHERE Subject ='Test Subject1']);
		List<Id> woIds = new List<Id>();
		for (WorkOrder wo : workOrders ) {
			woIds.add(wo.Id);
		}
		if (woIds.size() > 0 ) {
			List<ServiceAppointment> appts = new List<ServiceAppointment> ();
			appts = [SELECT Id FROM ServiceAppointment WHERE Work_Order__c IN :woIds];
			//for all the appts - should be one - create an assigned resource
			if(appts.size()>0) {
				for( ServiceAppointment sa : appts ) {
					sa.SchedStartTime = datetime.newInstance(2019, 4, 19, 11, 00, 0);
					sa.SchedEndTime = datetime.newInstance(2019, 4, 19, 11, 30, 0);

					AssignedResource ar = new AssignedResource(ServiceAppointmentId=sa.Id,ServiceResourceId=sr1.Id);
					toInsert.add(ar);
				}
				update appts;

				insert toInsert;

				List<ServiceAppointment> assignedSA = new List<ServiceAppointment>([SELECT Id,Technician_Name__c FROM ServiceAppointment WHERE Work_Order__c IN :woIds]);
				System.assertEquals(assignedSA.size(), 1);
				System.assertEquals(assignedSA[0].Technician_Name__c,sr1.Name);

			} else {

			}


		} else {
			//exception
			System.assertNotEquals(woIds.size(), 0);
		}


	}
the error occurs on the insert of the assigned resources
insert toInsert;
IF i change the code such that I manually do the status change in the code example:
sa.SchedStartTime = datetime.newInstance(2019, 4, 19, 11, 00, 0);
sa.SchedEndTime = datetime.newInstance(2019, 4, 19, 11, 30, 0);
sa.Status = 'Scheduled';
the error is returned for the update of the service appointments.
update appts;

Feed back greatly appreciated.

Andrew




 
I have followed the instructions for creating a sfdx project locally and converted all of my metadata to the sfdx format. Now I want to push my local meta data to my scratch org but I receive a huge list of errors. Most of them are that the objects are different and items don't exist, which I know because it's the first time I want to push my local version to the scratch org so my scratch org matches my production/sandbox metadata.Has anyone had this problem and have any advice to how to deploy my local set of metadata to a scratch org? I tried to use the --forceoverwrite parameter on sfdx push, but I still receive a LOT of errors such as invalid type, field does not exist, etc. I would think this command would overwrite what is on the scratch org with what I am pushing to it. Thanks for any advice
All,

I created an Apex Trigger below, but I assume it is firing after a user selects the "Submit" button. I would like for this trigger to fire after someone selects either the " Approve " button or " Reject " button.

I would appreciate your help 




trigger TriggerApprover on Matter__c (before update) {
   
       if(trigger.isUpdate){
             List<Matter__c> MatterList =  [Select id,
                                                   (Select Id,
                                                         IsPending,
                                                         ProcessInstanceId,
                                                         TargetObjectId,
                                                         StepStatus,
                                                         OriginalActorId,
                                                         ActorId,
                                                         RemindersSent,
                                                         Comments,
                                                         IsDeleted,
                                                         CreatedDate,
                                                         CreatedById,
                                                         SystemModstamp
                                                    FROM ProcessSteps
                                                ORDER BY CreatedDate DESC)
                                                    From Matter__c
                                                WHERE Id IN : Trigger.new];
 
             if(MatterList.size() > 0){
 
               for(Matter__c mat : MatterList){
             
                for(Matter__c mat1 : Trigger.new) {
                 
                         //check copy comment is true
                         if(mat.id == mat1.id && mat1.Copy_Comment__c) {
 
                           if (mat.ProcessSteps.size() > 0) {
                           
                         mat1.Approver_Comment__c = mat.ProcessSteps[0].Comments;
                         mat1.copy_comment__c = false;
               
                           }
 
                        }
                
                    }
               }
             }  
        } 
    }
 
Hi all,I am new to salesforce. I want to display user's list of groups in which he is member in a community via homepage component.Does anyone know how to do that in visaulforce page.I am not sure about how to take current logged in user's Id and search the chatter groups for that user as member.Any help will be appreciated. 

I'm at a loss to figure this one out.  When trying to save various files (it applies to all of them), Eclipse isn't even attempting to Save up to the Server.  It use to try to Save and only if it encountered an error would it Save Locally and report the error. 

Now, its only saves locally with no errors and only warnings with a description of "File only saved locally, not to server".  The only way I can save a file to the server is manually right-click on the file and choose Force.com \ Save to Server.  And this works fine but its maddening to now have to do this for every file.

 

Something is not right and I'd be grateful if some knows the solution!

 

Thanks in advance

Hi all,I am new to salesforce. I want to display user's list of groups in which he is member in a community via homepage component.Does anyone know how to do that in visaulforce page.I am not sure about how to take current logged in user's Id and search the chatter groups for that user as member.Any help will be appreciated.