Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- Approving the Submited Approval through Apex code
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Approving the Submited Approval through Apex code
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
11-15-2012 08:16 AM
I am Facing the problem when i am Approving the Submited Approval through Apex code
and i am countered with this error pl help me out .
System.DmlException: Process failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id
public void Reject (){
update perform;
Approval.ProcessWorkitemRequest req2 = new Approval.ProcessWorkitemRequest();
req2.setComments('Rating are not up to the mark');
req2.setAction('Reject'); //This is the action that is approve in your case, you can set it to Reject also
req2.setNextApproverIds(new Id[] {UserInfo.getUserId()});
// Use the ID from the newly created item to specify the item to be worked
req2.setWorkitemId(perform.id);
// Submit the request for approval
Approval.ProcessResult result2 = Approval.process(req2);
System.assert(result2.isSuccess(), 'Result Status:'+result2.isSuccess());
System.assertEquals(
'Approved', result2.getInstanceStatus(),
'Instance Status'+result2.getInstanceStatus());
}
Solved! Go to Solution.
Re: Approving the Submited Approval through Apex code
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
12-11-2012 07:30 AM
Approval.ProcessWorkitemRequest[] prWkItems = New Approval.ProcessWorkItemRequest[]{};
//Reject the record
ProcessInstance[] pi = [Select ID, Status, TargetObject.Name,
(SELECT Id, ActorId, ProcessInstanceId FROM Workitems),
(SELECT Id, StepStatus, Comments FROM Steps) From ProcessInstance
Where TargetObjectID IN :tbuApprovals AND Status = 'Pending'];
for(ProcessInstance instance : pi){
for(ProcessInstanceWorkItem workItem : instance.WorkItems){
Approval.ProcessWorkitemRequest prWkItem = new Approval.ProcessWorkitemRequest();
prWkItem.setWorkItemID(workItem.id);
prWkItem.setComments('Request Canceled by User: ' + userInfo.getName());
prWkItem.setAction('Reject');
prWkItems.add(prWkItem);
}
}
if(!prWkItems.isEmpty()){
shouldTriggerRun.stopFAR();
Approval.ProcessResult[] appResult = Approval.process(prWkItems);
shouldTriggerRun.allowFAR();
}

