• David H 18
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
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.
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.