1

This code is supposed to insert 50 work orders with randomized geolocations. It's meant to create enough records of sample data to set the stage for demonstrating the power of bulk-scheduling/optimization policies on the dispatcher.

The Code is successful in inserting the records with the ServiceTerritory and the WorkType fields correctly, but the Latitude and Longitude fields are not saving to the record.

I've also tried inserting 20 work orders with ServiceTerritory, WorkType, Latitude, and Longitude using a csv and workbench. The same thing is happening here, the records get created with ServiceTerritory and WorkType, but the Latitude and Longitude don't save to the record.

Do you have any idea as to why this is happening or do you know any salesforce secrets around this?

 /** central Santa Barbara **/
double latitude = 34.4208;
double longitude = -119.6982;
double radius = 0.1;

Integer numOfServices=50;

Id territorySB = [SELECT id FROM ServiceTerritory where Name='Santa Barbara'].Id;

List<WorkType> lstWorkTypes = [Select Id from WorkType where Name ='Assessment'];

List<WorkOrder> workOrders = new List<WorkOrder>();

    for (Integer i=0; i<numOfServices; i++){
        Integer randomWorkType = Math.round(Math.random() * (lstWorkTypes.size()-1));
        WorkOrder wo = new WorkOrder();
        wo.ServiceTerritoryId = territorySB;
        wo.WorkTypeId = lstWorkTypes[randomWorkType].Id;
        wo.Latitude = latitude + Math.random() * radius * 2 - 
radius;
        wo.Longitude = longitude + Math.random() * radius * 2 - 
radius;
        workOrders.add(wo);
    }

    insert workOrders;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.