function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
David H 18David H 18 

Data Integration Specialist: Challenge 5 - Not Completing

Hi,

I'm currently working through the Data Integration Specialist superbadge and my attempt throws the following error when I check the challenge:

Challenge Not yet complete... here's what's wrong:
The 'ProjectRESTService' Apex REST service does not appear to be using a SavePoint to rollback change when an exception occurs.

I don't really understand this error as I appear to have implemented a SavePoint for rolling back changes, so any suggestions would be much appreciated.
 
@RestResource(urlMapping='/project/*')
global with sharing class ProjectRESTService {  
	@HttpPost
	global static String postProjectData(String projectRef, String projectName, String opportunityId, Date startDate, Date endDate, Double amount, String status) {                  	                                         
		List<Project__c> projects = [
			SELECT ProjectRef__c, Name, Opportunity__c, Start_Date__c, End_Date__c, Billable_Amount__c, Status__c
			FROM Project__c
			WHERE ProjectRef__c=:ProjectRef
		];
		
		Project__c project = new Project__c();                                 
		if (!projects.isEmpty()) {
			project = projects[0];
		}
                                                 
		project.ProjectRef__c = projectRef;
		project.Name = projectName;
		project.Opportunity__c = opportunityId;
		project.Start_Date__c = startDate;
		project.End_Date__c = endDate;
		project.Billable_Amount__c = amount;
		project.Status__c = status;
		       
		Opportunity opp = [SELECT Id, DeliveryInstallationStatus__c FROM Opportunity WHERE Id=:opportunityId];         
		opp.DeliveryInstallationStatus__c = 'In Progress';
             
		Savepoint sp = Database.setSavepoint();
		try {           
			upsert project;
			update opp;
			return 'OK';  
		} catch(Exception e) {
			Database.rollback(sp);
			return e.getMessage();
		}        	
	}
}

Thanks.
Leonardo Ariel SalatinoLeonardo Ariel Salatino
Hi man, have you been able to solve this? I'm facing the same error, it's making me nuts =)
John MutumaJohn Mutuma
There could be a wide variety of issues, code could be right logically and different people get the error for different reasons. This may even include some fields on objects being referenced in your code not being assigned to the user profile for the user in context.
You may want to try some debugging even using a tool like Workbench to try and hit your endpoint with proper data and check whether the data is being updated in your objects correctly; you can do that by issuing database queries or using the Reports feature in Salesforce UI.