• tech update
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Public Class JSONParseDisplay{


Public Static void ParseJSON() {

  
  String Jsonstrn = '{"userDevices":[{"asserts":[" 2015-8-06 22:48:00"," 2015-8-06 22:48:00"],"battery":{"percentage":20,"voltage":3745},"deviceId":29308103,"deviceSerialNumber":"12EB5676534B","deviceType":"Charge HR","deviceWireId":"eb5672212b12","fwVersionRaw":"APP18.84 BSL18.84","hardwareVersion":"9","lastSyncClient":"api/sync-CLIENT-VISIBLE/mobile-ios/401","lastSyncedAt":"2015-08-10T13:27:56.000Z","pairedAt":"2015-04-10T19:51:15.000Z","pairedToEmail":"afit@somewhere.com"}]}';

//String Jsonstrn = '{"userDevices":[' +'{"asserts":[" 2015-8-06 22:48:00"," 2015-8-06 22:48:00"],"battery":[' +'{"percentage":20,"voltage":3745}],"deviceId":29308103,"deviceSerialNumber":"12EB5676534B","deviceType":"Charge HR","deviceWireId":"eb5672212b12","fwVersionRaw":"APP18.84 BSL18.84","hardwareVersion":"9","lastSyncClient":"api/sync-CLIENT-VISIBLE/mobile-ios/401","lastSyncedAt":"2015-08-10T13:27:56.000Z","pairedAt":"2015-04-10T19:51:15.000Z","pairedToEmail":"afitbitter@somewhere.com"}' +']}';

   JSONParser parser = JSON.createParser(Jsonstrn);
   System.debug('parser' +parser);
   while (parser.nextToken() != null) {
   
     if (parser.getCurrentToken() == JSONToken.START_ARRAY) {
     
         while (parser.nextToken() != null) {
         
          if (parser.getCurrentToken() == JSONToken.START_OBJECT) {
          
          
          UserDevice usd = (UserDevice)parser.readValueAs(UserDevice.class);
          System.debug('usd++ : ' +usd);
          System.debug('pairedAt: ' +usd.pairedAt);
          
         // System.debug('Size of batteries: ' +usd.batteries.size());
          System.debug('batteries: ' +usd.batteries);
          
          String s = JSON.serialize(usd);
          System.debug('Serialized invoice: ' + s);
          
          parser.skipChildren();
              
           }
              
        }

     } 
    
   }

 }
 
 public class UserDevice {
        
        List<string> asserts;
       List<battery> batteries;
      // List<string> batteries;
        public Double deviceId;
        public string deviceSerialNumber;
        public string deviceType;
        public string deviceWireId;
        public string fwVersionRaw;
        public Double hardwareVersion;
        public string lastSyncClient;
        public string lastSyncedAt;
        public string pairedAt;
        public string pairedToEmail;
        
        public UserDevice(List<string> asser,List<battery> batt,Double devId,string deviceSerNumber,string devType,string devWireId,string fwVersRaw,Double hardVersion,string lastSyClient,string lastSyedAt,string paredAt,string paredToEmail){
        
        asserts = asser;
       batteries = batt.clone();
       // batteries = Double.parseDouble(batt);
      // batteries = batt;
      //  System.debug('batt.clone(): ' +batt.clone());
        deviceId = devId;
        deviceSerialNumber = deviceSerNumber;
        deviceType = devType;
        deviceWireId = devWireId;
        fwVersionRaw = fwVersRaw;
        hardwareVersion = hardVersion;
        lastSyncClient = lastSyClient;
        lastSyncedAt = lastSyedAt;
        pairedAt = paredAt;
        pairedToEmail = paredToEmail;
        
        System.debug('pairedToEmail: ' +pairedToEmail);
   }     
 
 }
 
 public class battery {
        public Double percentage;
        public Double voltage;
        //System.debug('voltage::' +voltage);     
 
 
 } 


}

I am trying to execute the following code for recalling an approval process an ends up getting the following error

 

 

execution of AfterUpdate caused by: System.DmlException: Process failed. First exception on row 0; first error: INVALID_OPERATION, Illegal transition type:

 

 Approval.ProcessWorkItemRequest pwr = new Approval.ProcessWorkItemRequest();
       
List<ProcessInstance> procins = new List<ProcessInstance>([select Id from ProcessInstance where Status = 'Pending' and TargetObjectId = :objectId]);
// Retrieve the process work instance id associated to the process instance
            List<ProcessInstanceWorkitem>  workitem = new List<ProcessInstanceWorkitem>([select Id from ProcessInstanceWorkitem where ProcessInstanceId = :procins[0].id]);

            if ((workitem != null) && (workitem.size() > 0))
            {
                pwr.SetComments(statusToUpdate);

                pwr.setWorkItemId(workitem[0].id);
                pwr.setAction('Remove');
            
               
                // Execute process request
                Approval.ProcessResult pr = Approval.process(pwr);

}