Thanks.@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();
}
}
}
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.