Apex - Test Batch class Execute method not covered code coverage - testing

Batch apex class not covering execute method
Batch Apex Class : Trying to cover execute method but not covered in image above.
This batch class is on aggregate result. Please suggest me how to cover this batch class
It is working on search result of order if the status is based on filter then in execute method it will aggregate the value of fulfilment id of all orders related to it. based on their order status it executes.
global class UpdateOrderIntegrationStatus_Batch implements
Database.Batchable<AggregateResult>, Database.Stateful{
String status_filter = 'Waiting On Prior Order';
String query = 'select count(Id) cnt, Fulfillment__c from Apttus_Config2__Order__c'
+' where Fulfillment__c <> null and Order_Integration_Status__c = \''+status_filter + '\''
+' group by Fulfillment__c '
+' limit 50000';
public UpdateOrderIntegrationStatus_Batch(){}
public UpdateOrderIntegrationStatus_Batch(string q){
query = q;
}
global Iterable<AggregateResult> start(Database.BatchableContext BC){
//system.debug('>>>> query : ' + query)
return new AggregateResultIterable(query);
}
global void execute(Database.BatchableContext BC, List<sobject> results){
set<Id> fufillmentIds = new set<Id>();
for(Sobject sObj:results){
AggregateResult ar = (AggregateResult)sObj;
fufillmentIds.add((Id) ar.get('Fulfillment__c'));
}
List<Contract> fulfillments = [select id,(select Id, Order_Integration_Status__c from Orders__r order by Name asc) from Contract where id IN:fufillmentIds];
List<Apttus_Config2__Order__c> orderToUpdate = new List<Apttus_Config2__Order__c>();
String priorOrderIntegrationStatus = '';
for(Contract fulfillmentObj: fulfillments){
priorOrderIntegrationStatus = '';
for(Apttus_Config2__Order__c order: fulfillmentObj.Orders__r){
if(order.Order_Integration_Status__c == 'Processed'){
priorOrderIntegrationStatus = order.Order_Integration_Status__c;
}
else if(order.Order_Integration_Status__c == 'Error'){
break;
}
else if(order.Order_Integration_Status__c == status_filter && priorOrderIntegrationStatus == 'Processed' ){
order.Order_Integration_Status__c = 'Ready';
orderToUpdate.add(order);
priorOrderIntegrationStatus = order.Order_Integration_Status__c;
break;
}
else{
priorOrderIntegrationStatus = order.Order_Integration_Status__c; //For other statuses like Ready, Not Ready, Pending etc.
continue;
}
}
}
if(orderToUpdate <> null && orderToUpdate.size() > 0){
Database.update(orderToUpdate, false);
}
}
global void finish(Database.BatchableContext BC){
System.debug('UpdateOrderIntegrationStatus_Batch Finished');
}
}
Test Batch class:
#isTest
public class UpdateOrderIntegrationStatus_Batch_Test {
public static testMethod void testBatch() {
Test.StartTest();
Account acc =APTS_BvdUtility.createAccount();
Contact con = APTS_BvdUtility.createContact(acc.Id);
Apttus_Config2__AccountLocation__c acclocation = APTS_BvdUtility.createAccountLocation('Test Loc', acc.Id, con.Id);
Opportunity opp = APTS_BvdUtility.createOpportunity('Test Opp ', acc.Id, con.Id);
Apttus_Config2__PriceList__c priceList = APTS_BvdUtility.createPriceList('Test PriceBook') ;
Apttus_Proposal__Proposal__c quote = APTS_BvdUtility.createQuote(acc, opp, priceList.Id, 'quoteName');
Apttus_Config2__Order__c newOrder = new Apttus_Config2__Order__c();
newOrder.Apttus_QPConfig__ProposalId__c = quote.Id;
newOrder.Apttus_Config2__Status__c = 'Pending';
newOrder.AC_Billing_Street_1__c = '234';
newOrder.AC_Shipping_Street_1__c = '234';
newOrder.Ultimate_Parent_Account_ID__c = quote.Apttus_Proposal__Account__c;
newOrder.Apttus_Config2__BillToAccountId__c = quote.Apttus_Proposal__Account__c;
newOrder.Apttus_Config2__ShipToAccountId__c = quote.Apttus_Proposal__Account__c;
newOrder.Apttus_Config2__RelatedOpportunityId__c = quote.Apttus_Proposal__Opportunity__c;
newOrder.Apttus_Config2__OrderStartDate__c = quote.Apttus_Proposal__ExpectedStartDate__c;
newOrder.Apttus_Config2__OrderEndDate__c = quote.Apttus_Proposal__ExpectedEndDate__c;
newOrder.Apttus_Config2__SoldToAccountId__c = quote.Apttus_Proposal__Account__c;
newOrder.Apttus_Config2__PriceListId__c = quote.Apttus_QPConfig__PriceListId__c;
newOrder.Apttus_Config2__Type__c = quote.Apttus_QPConfig__ABOType__c;
newOrder.Language__c = 'English';
newOrder.Billing_Cycle__c = 'Annual';
newOrder.Detailed_Invoice__c = true;
newOrder.Bill_To_Contracting_Party__c = 'Test123';
newOrder.Ship_To_Contracting_Party__c = 'Test123';
newOrder.Bill_To_Location__c = acclocation.Id;
newOrder.Ship_To_Location__c = acclocation.id;
newOrder.Bill_To_Ultimate_Parent_Account_ID__c = quote.Apttus_Proposal__Account__c;
newOrder.Ship_To_Ultimate_Parent_Account_ID__c = quote.Apttus_Proposal__Account__c;
newOrder.Apttus_Config2__ActivatedDate__c = System.today();
newOrder.Apttus_Config2__OrderDate__c = System.today();
newOrder.CurrencyIsoCode = quote.CurrencyIsoCode;
newOrder.Apttus_Config2__ActivatedDate__c = System.Date.today();
newOrder.Order_Integration_Status__c='Waiting On Prior Order';
insert newOrder;
String testseqname = 'CONTRACT_NUMBER';
double testseqnumber = 1234;
Sequence_Number__c sn = new Sequence_Number__c(Name = testseqname, Next_Sequence_Number__c = testseqnumber);
insert sn;
List<SObject> contracts = new List<Contract>();
Contract fulfillment = new Contract();
fulfillment.Fulfillment_Total__c = 6000;
fulfillment.AccountId = acc.Id;
fulfillment.Opportunity__c = opp.Id;
fulfillment.Renewal_Opportunity__c = opp.Id;
fulfillment.CurrencyIsoCode = newOrder.CurrencyIsoCode;
fulfillment.CustomerSignedDate = system.today();
fulfillment.Status = 'Client Signed';
fulfillment.End_Date__c = newOrder.Apttus_Config2__OrderEndDate__c;
fulfillment.StartDate = newOrder.Apttus_Config2__OrderStartDate__c;
fulfillment.Latest_Order__c = newOrder.Id;
fulfillment.Billing_Integration_Status__c = 'Ready';
fulfillment.RecordTypeId = System.Label.Sales_Contract_RecordTypeID;
fulfillment.Original_Order_Submit_Date__c = newOrder.Apttus_Config2__ActivatedDate__c.date();
fulfillment.BusinessUnit__c = 'Bureau van Dijk Electronic Publishing Inc.';
fulfillment.Contract_Sequence_Number__c = 993360;
// insert fulfillment;
contracts.add(fulfillment);
insert contracts;
List<Contract> contrList = [select id,(select Id, Order_Integration_Status__c from Orders__r order by Name asc) from Contract where id =:contracts[0].Id];
newOrder.Order_Integration_Status__c='Processed';
update newOrder;
String status_filter = 'Waiting On Prior Order';
String query = 'select count(Id) cnt, Fulfillment__c from Apttus_Config2__Order__c'
+' where Fulfillment__c <> null and Order_Integration_Status__c = \''+status_filter + '\''
+' group by Fulfillment__c '
+' limit 50000';
/* String query = 'select id,(select Id, Order_Integration_Status__c from Orders__r order
by Name asc) from Contract';
String query = 'select count(Id) cnt, Fulfillment__c from Apttus_Config2__Order__c'
+' where Fulfillment__c =\''+contrList[0].Id +'\' and Order_Integration_Status__c =
\''+status_filter + '\''
+' group by Fulfillment__c '
+' limit 50000';
*/
UpdateOrderIntegrationStatus_Batch obj = new UpdateOrderIntegrationStatus_Batch();
UpdateOrderIntegrationStatus_Batch obj1 = new UpdateOrderIntegrationStatus_Batch(query);
// obj1.execute(BC, contracts);
ID batchprocessid = Database.executeBatch(obj);
ID batchprocessid1 = Database.executeBatch(obj1,10);
List<Apttus_Config2__Order__c> orders =[select Id,
Order_Integration_Status__c,Fulfillment__c from Apttus_Config2__Order__c where
Fulfillment__c=:contracts[0].Id];
for(Apttus_Config2__Order__c ord : orders){
system.assertEquals('Processed', ord.Order_Integration_Status__c);
}
Test.StopTest();
}
}

Related

I'm using 3 filters in my lightning component to want to show data all together,i.e. record should be displayed after filtering through all filters

I have created a lightning component with 3 filters- one for searching listview, one from dropdown (picklist) and third by searching the name. I'm able to make it work by individual search but for combining have been asked to use dynamic SQL in apex by passing the string in apex class. So here's code is attached of class .But I don't know how to move forward.
public with sharing class ApexSearchForm {
#AuraEnabled
public static List<Asset__c> fetchAccounts(String status, String v) {
String a= 'Recently Viewed Assets';
String b='All Assets';
String c='Choose One';
List<Asset__c> accList = new List<Asset__c>();
if(String.isNotBlank(status)){
accList = [SELECT Name, Status__c, Description__c, Executive_Sponsor__c, Documentation_Link__c,Video_Link__c,Source_Code_Link__c
FROM Asset__c
WHERE Status__c = :status];
}if(String.isBlank(status)){
accList = [SELECT Name, Status__c, Description__c, Executive_Sponsor__c, Documentation_Link__c, Video_Link__c,Source_Code_Link__c
FROM Asset__c LIMIT 100];
}if(v == a){
accList = [SELECT Id, Name, Description__c, Submitted_Date__c, Documentation_Link__c, Source_Code_Link__c,Video_Link__c,Status__c
FROM Asset__c
WHERE LastViewedDate != NULL
ORDER BY LastViewedDate DESC LIMIT 5];
}else if(v==b){
accList = [SELECT Id, Name, Description__c, Submitted_Date__c, Documentation_Link__c, Source_Code_Link__c,Video_Link__c,Status__c
FROM Asset__c
ORDER BY Name ASC ];
}else if(v==c){
accList = [SELECT Id, Name, Description__c, Submitted_Date__c, Documentation_Link__c, Source_Code_Link__c,Video_Link__c,Status__c
FROM Asset__c ];
}else if(String.isNotBlank(status) && v==a){
accList=[SELECT Id, Name, Description__c, Submitted_Date__c, Documentation_Link__c, Source_Code_Link__c,Video_Link__c,Status__c
FROM Asset__c
WHERE Status__c = :status
ORDER BY LastViewedDate DESC];
}
return accList;
}
#AuraEnabled
public static Map<String, String> getStatusFieldValue(){
Map<String, String> options = new Map<String, String>();
Schema.DescribeFieldResult fieldResult = Asset__c.Status__c.getDescribe();
List<Schema.PicklistEntry> pValues = fieldResult.getPicklistValues();
for (Schema.PicklistEntry p: pValues) {
options.put(p.getValue(), p.getLabel());
}
return options;
}
}
Assuming that you pass correctly the parameters from frontend to the controller, you can do something like:
public static List<Asset__c> fetchAccounts(String status, String v) {
String a= 'Recently Viewed Assets';
String b='All Assets';
String query = 'SELECT Name, Status__c, Description__c, Executive_Sponsor__c, Documentation_Link__c,Video_Link__c,Source_Code_Link__c FROM Asset__c';
if(String.isNotBlank(status) || v != null){
query += ' WHERE';
if(String.isNotBlank(status)){
query += ' Status__c = :status';
}
if(v != null){
query += ' ORDER BY';
if(v == a){
query += ' LastViewedDate DESC';
if(String.isNotBlank(status)){
query += ' LIMIT 5';
}
} else if(v == b){
query += ' Name ASC';
}
}
} else {
query += ' LIMIT 100';
}
List<Asset__c> accList = Database.query(query);
return accList;
}

Optaplanner ScoreDirector continuous planning DayOff Request

I am trying to enable continuous planning and requests. I have tried to follow the computer example provided within the doco. Code below. I can see the values updated during debug. Code below. What am I doing wrong
public void addEmployeeDayOff(final Employee employee,final DayOffRequest dayOffRequest) {
logger.info("Scheduling employee dayoff ({}).", dayOffRequest);
doProblemFactChange(scoreDirector -> {
NurseRoster nurseRoster = scoreDirector.getWorkingSolution();
Employee workingEmployee = scoreDirector.lookUpWorkingObject(employee);
DayOffRequest dayoffRequest = scoreDirector.lookUpWorkingObject(dayOffRequest);
scoreDirector.beforeProblemPropertyChanged(workingEmployee);
if (workingEmployee == null) {
return;
}
ArrayList<DayOffRequest> requestoffList = new ArrayList<>(nurseRoster.getDayOffRequestList());
nurseRoster.setDayOffRequestList(requestoffList);
scoreDirector.beforeProblemFactAdded(dayoffRequest);
workingEmployee.getDayOffRequestMap().put(dayoffRequest.getShiftDate(), dayoffRequest);
scoreDirector.afterProblemPropertyChanged(workingEmployee);
nurseRoster.getDayOffRequestList().add(dayoffRequest);
scoreDirector.afterProblemPropertyChanged(dayoffRequest);
scoreDirector.triggerVariableListeners();
});
The above is called from here:
List<DayOffRequest> dayOffRequestList;
//updating from database .. not sure if this is the issue
List<DayOffData> dayOffElementList = (List<DayOffData>) rosterService.listDayOffData();
dayOffRequestList = new ArrayList<>(dayOffElementList.size());
long nextdayoffId =0L;
for (DayOffData element : dayOffElementList) {
if (nextdayoffId <= element.getId()) {
nextdayoffId = element.getId() + 1L;
}
DayOffRequest dayOffRequest = new DayOffRequest();
String empID = element.getEmployee().getName();
int weight = element.getWeight();
LocalDate shiftDate = element.getShiftDate();
ShiftDate date1 = shiftDateMap.get(shiftDate);
Employee employee = employeeMap.get(empID);
dayOffRequest.setId(nextdayoffId);
dayOffRequest.setWeight(weight);
dayOffRequest.setEmployee(employee);
dayOffRequest.setShiftDate(date1);
dayOffRequestList.add(dayOffRequest);
//If this is not enabled the values don't pass to the addEmployeeDayOff method is this correct??
scoreDirector.afterProblemFactAdded(dayOffRequest);
scoreDirector.afterProblemFactAdded(employee);
addEmployeeDayOff(employee,dayOffRequest);
}
I found this worked but not sure if this is the correct way to approach the problem.
public void addEmployeeDayOff(final Employee employee, final DayOffRequest dayOffRequest) {
logger.info("Scheduling employee dayoff ({}).", dayOffRequest);
doProblemFactChange(scoreDirector -> {
NurseRoster nurseRoster = (NurseRoster) scoreDirector.getWorkingSolution();
Employee workingEmployee = scoreDirector.lookUpWorkingObject(employee);
DayOffRequest dayoffRequest = (DayOffRequest) scoreDirector.lookUpWorkingObject(dayOffRequest);
scoreDirector.beforeProblemPropertyChanged(workingEmployee);
if (workingEmployee == null) {
return;
}
ArrayList<DayOffRequest> requestoffList = new ArrayList<>(nurseRoster.getDayOffRequestList());
nurseRoster.setDayOffRequestList(requestoffList);
scoreDirector.afterProblemFactAdded(requestoffList);
scoreDirector.afterProblemPropertyChanged(requestoffList);
ArrayList<Employee> beforeempList = new ArrayList<>(nurseRoster.getEmployeeList());
nurseRoster.setEmployeeList(beforeempList);
nurseRoster.getEmployeeList().remove(workingEmployee);
scoreDirector.beforeProblemFactRemoved(workingEmployee);
scoreDirector.afterProblemFactRemoved(workingEmployee);
ArrayList<Employee> empList = new ArrayList<>(nurseRoster.getEmployeeList());
nurseRoster.setEmployeeList(empList);
workingEmployee.getDayOffRequestMap().put(dayOffRequest.getShiftDate(), dayOffRequest);
nurseRoster.getEmployeeList().add(workingEmployee);
scoreDirector.beforeProblemFactAdded(workingEmployee);
scoreDirector.afterProblemFactAdded(workingEmployee);
scoreDirector.triggerVariableListeners();
});
I have uploaded the xml and Java file here https://github.com/rod182211/Optaplanner in to hope someone can advise why when I advance 14 days not all rule continue to apply. I assumed scoredirector only needed to be made aware of changes.
14 Day advance taking into account Requests via the below.
doProblemFactChange(scoreDirector -> {
NurseRoster nurseRoster = scoreDirector.getWorkingSolution();
NurseRosterParametrization nurseRosterParametrization = nurseRoster
.getNurseRosterParametrization();
List<ShiftDate> shiftDateList = nurseRoster.getShiftDateList();
Shift oldLastShift = nurseRoster.getShiftList()
.get(nurseRoster.getShiftList().size() - 1);
long shiftId = oldLastShift.getId() + 1L;
int shiftIndex = oldLastShift.getIndex() + 1;
ShiftDate oldLastShiftDate = shiftDateList
.get(shiftDateList.size() - 1);
long shiftDateId = (oldLastShiftDate.getId() + 1L);
int shiftDayIndex = (oldLastShiftDate.getDayIndex() + 1);
// long parmId = nurseRoster.getNurseRosterParametrization().getId()
// + 1L;
scoreDirector
.beforeProblemPropertyChanged(nurseRosterParametrization);
// Update to get the first day along with adding 14 days to the run
LocalDate startDate = (oldLastShiftDate.getDate().plusDays(1));
LocalDate endDate = (oldLastShiftDate.getDate().plusDays(14));
int maxDayIndex = Math.toIntExact(DAYS.between(startDate, endDate));
int shiftDateSize = maxDayIndex + 1;
List<ShiftDate> shiftDateList1 = new ArrayList<>(shiftDateSize);
shiftDateMap = new HashMap<>(shiftDateSize);
LocalDate date = startDate;
for (int i = 0; i < shiftDateSize; i++) {
ShiftDate shiftDate = new ShiftDate();
shiftDate.setId(shiftDateId);
shiftDate.setDayIndex(shiftDayIndex);
shiftDate.setDate(date);
shiftDate.setShiftList(new ArrayList<>());
shiftDateMap.put(date, shiftDate);
shiftDateId++;
shiftDayIndex++;
date = date.plusDays(1);
nurseRoster.getShiftDateList().add(shiftDate);
shiftDateList1.add(shiftDate);
scoreDirector.afterProblemFactAdded(shiftDate);
}
List<Skill> skillList;
List<Skill> skillElementList = (List<Skill>) nurseRoster
.getSkillList();
skillList = new ArrayList<>(skillElementList.size());
skillMap = new HashMap<>(skillElementList.size());
long id = 0L;
for (Skill element : skillElementList) {
Skill skill = new Skill();
skill.setId(id);
skill.setCode(element.getCode());
skillList.add(skill);
if (skillMap.containsKey(skill.getCode())) {
throw new IllegalArgumentException(
"There are 2 skills with the same code ("
+ skill.getCode() + ").");
}
skillMap.put(skill.getCode(), skill);
id++;
}
List<Contract> contractElementList = (List<Contract>) nurseRoster
.getContractList();
List<Contract> contractList = new ArrayList<>(
contractElementList.size());
contractMap = new HashMap<>(contractElementList.size());
for (Contract element : contractElementList) {
Contract contract = new Contract();
long Id = element.getId();
contract.setId(Id);
contract.setCode(element.getCode());
contract.setDescription(element.getDescription());
WeekendDefinition weekend = element.getWeekendDefinition();
contract.setWeekendDefinition(weekend);
contract.setContractLineList(new ArrayList<ContractLine>());
contractMap.put(contract.getCode(), contract);
contractList.add(contract);
}
List<ShiftTypeSkillRequirement> coverRequirementElementList = (List<ShiftTypeSkillRequirement>) nurseRoster
.getShiftTypeSkillRequirementList();
List<ShiftType> shiftTypeElementList = (List<ShiftType>) rosterService
.listShiftType();
List<ShiftType> shiftTypeList = new ArrayList<>(
shiftTypeElementList.size());
shiftTypeMap = new HashMap<>(shiftTypeElementList.size());
long Id = 0L;
int index = 0;
long shiftTypeSkillRequirementId = 0L;
List<ShiftTypeSkillRequirement> shiftTypeSkillRequirementList = new ArrayList<>(
shiftTypeElementList.size() * 2);
for (ShiftType element : shiftTypeElementList) {
ShiftType shiftType = new ShiftType();
shiftType.setId(Id);
shiftType.setCode(element.getCode());
shiftType.setIndex(index);
String startTimeString = element.getStartTimeString();
shiftType.setStartTimeString(startTimeString);
String endTimeString = element.getEndTimeString();
shiftType.setEndTimeString(endTimeString);
shiftType
.setNight(startTimeString.compareTo(endTimeString) > 0);
shiftType.setDescription(element.getDescription());
for (ShiftTypeSkillRequirement skillElement : coverRequirementElementList) {
ShiftTypeSkillRequirement shiftTypeSkillRequirement = new ShiftTypeSkillRequirement();
shiftTypeSkillRequirement
.setId(shiftTypeSkillRequirementId);
shiftTypeSkillRequirement.setShiftType(shiftType);
Skill skill = skillMap
.get(skillElement.getSkill().getCode());
if (skill == null) {
throw new IllegalArgumentException("The skill ("
+ skillElement.getSkill().getCode()
+ ") of shiftType (" + shiftType.getCode()
+ ") does not exist.");
}
shiftTypeSkillRequirement.setSkill(skill);
shiftTypeSkillRequirementList
.add(shiftTypeSkillRequirement);
shiftTypeSkillRequirementId++;
}
shiftTypeList.add(shiftType);
if (shiftTypeMap.containsKey(shiftType.getCode())) {
throw new IllegalArgumentException(
"There are 2 shiftTypes with the same code ("
+ shiftType.getCode() + ").");
}
shiftTypeMap.put(shiftType.getCode(), shiftType);
Id++;
index++;
}
nurseRoster.setShiftTypeList(shiftTypeList);
nurseRoster.setShiftTypeSkillRequirementList(
shiftTypeSkillRequirementList);
int shiftListSize = shiftDateMap.size() * shiftTypeList.size();
List<Shift> shiftList1 = new ArrayList<>(shiftListSize);
dateAndShiftTypeToShiftMap = new HashMap<>(shiftListSize);
dayOfWeekAndShiftTypeToShiftListMap = new HashMap<>(
7 * shiftTypeList.size());
for (ShiftDate shiftDate : shiftDateList1) {
for (ShiftType shiftType : shiftTypeList) {
Shift shift = new Shift();
shift.setId(shiftId);
shift.setShiftDate(shiftDate);
shiftDate.getShiftList().add(shift);
shift.setShiftType(shiftType);
shift.setIndex(shiftIndex);
shift.setRequiredEmployeeSize(0); // Filled in later
shiftList1.add(shift);
dateAndShiftTypeToShiftMap.put(
Pair.of(shiftDate.getDate(), shiftType.getCode()),
shift);
addShiftToDayOfWeekAndShiftTypeToShiftListMap(shiftDate,
shiftType, shift);
shiftId++;
shiftIndex++;
nurseRoster.getShiftList().add(shift);
scoreDirector.afterProblemFactAdded(shift);
}
}
List<DayOffRequest> dayOffRequestList;
List<DayOffRequest> requestList = (List<DayOffRequest>) nurseRoster.getDayOffRequestList();
DayOffRequest oldLastDayOff = requestList.get(requestList.size() - 1);
long DayOffId = (oldLastDayOff.getId() + 1l);
List<DayOffDate> dayOffElementList = rosterService.listDayOffDate();
dayOffRequestList = new ArrayList<>(dayOffElementList.size());
for (DayOffDate element : dayOffElementList) {
DayOffRequest dayOffRequest = new DayOffRequest();
int weight = element.getWeight();
LocalDate shiftDate = element.getDate();
ShiftDate date1 = shiftDateMap.get(shiftDate);
Employee employee = element.getEmployee();
Employee workingEmployee = scoreDirector.lookUpWorkingObject(employee);
dayOffRequest.setId(DayOffId);
DayOffId++;
dayOffRequest.setWeight(weight);
dayOffRequest.setEmployee(workingEmployee);
dayOffRequest.setShiftDate(date1);
workingEmployee.getDayOffRequestMap().put(date1, dayOffRequest);
nurseRoster.getDayOffRequestList().add(dayOffRequest);
}
List<DayOnRequest> dayOnRequestList;
List<DayOnDate> dayOnElementList1 = rosterService.listDayOnDate();
dayOnRequestList = new ArrayList<>(dayOnElementList1.size());
for (DayOnDate element : dayOnElementList1) {
DayOnRequest dayOnRequest = new DayOnRequest();
long DayOnId = element.getId();
int weight = element.getWeight();
LocalDate localshiftDate = element.getDate();
ShiftDate dateon = shiftDateMap.get(localshiftDate);
Employee employee = element.getEmployee();
Employee workingEmployee = scoreDirector.lookUpWorkingObject(employee);
dayOnRequest.setId(DayOnId);
dayOnRequest.setWeight(weight);
dayOnRequest.setEmployee(workingEmployee);
dayOnRequest.setShiftDate(dateon);
dayOnRequestList.add(dayOnRequest);
workingEmployee.getDayOnRequestMap().put(dateon, dayOnRequest);
nurseRoster.getDayOnRequestList().add(dayOnRequest);
}
List<ShiftOffRequest> shiftOffRequestList;
List<ShiftOffDate> shiftOffElementList = (List<ShiftOffDate>) rosterService.listShiftOffDate();
shiftOffRequestList = new ArrayList<>(shiftOffElementList.size());
for (ShiftOffDate element : shiftOffElementList) {
ShiftOffRequest shiftOffRequest = new ShiftOffRequest();
long ShiftonId = element.getId();
int weight = element.getWeight();
Employee employee = element.getEmployee();
Employee workingEmployee = scoreDirector.lookUpWorkingObject(employee);
LocalDate date1 = element.getDate();
String shiftcode = element.getShiftType().getCode();
Shift shift = dateAndShiftTypeToShiftMap.get(Pair.of(date1, shiftcode));
shiftOffRequest.setId(ShiftonId);
shiftOffRequest.setEmployee(workingEmployee);
shiftOffRequest.setShift(shift);
shiftOffRequest.setWeight(weight);
shiftOffRequestList.add(shiftOffRequest);
workingEmployee.getShiftOffRequestMap().put(shift, shiftOffRequest);
nurseRoster.setShiftOffRequestList(shiftOffRequestList);
}
List<ShiftOnRequest> shiftOnRequestList;
List<ShiftOnDate> shiftOnElementList = (List<ShiftOnDate>) rosterService.listShiftOnDate();
shiftOnRequestList = new ArrayList<>(shiftOnElementList.size());
for (ShiftOnDate element : shiftOnElementList) {
ShiftOnRequest shiftOnRequest = new ShiftOnRequest();
long ShiftonId = element.getId();
int weight = element.getWeight();
Employee employee = element.getEmployee();
Employee workingEmployee = scoreDirector.lookUpWorkingObject(employee);
LocalDate date1 = element.getDate();
String shiftcode = element.getShiftType().getCode();
Shift shift = dateAndShiftTypeToShiftMap.get(Pair.of(date1, shiftcode));
shiftOnRequest.setId(ShiftonId);
shiftOnRequest.setEmployee(workingEmployee);
shiftOnRequest.setShift(shift);
shiftOnRequest.setWeight(weight);
shiftOnRequestList.add(shiftOnRequest);
workingEmployee.getShiftOnRequestMap().put(shift, shiftOnRequest);
nurseRoster.setShiftOnRequestList(shiftOnRequestList);
}
List<CoverRequirements> coverRequirementElementList1 = (List<CoverRequirements>) rosterService
.listCoverRequirements();
for (CoverRequirements element : coverRequirementElementList1) {
String type = element.getShiftType().getCode();
DayOfWeek day = element.getDayOfWeek();
int req = element.getRequiredEmployeesize();
ShiftType shiftType = shiftTypeMap.get(type);
Pair<DayOfWeek, ShiftType> key = Pair.of(day, shiftType);
List<Shift> shiftList = dayOfWeekAndShiftTypeToShiftListMap
.get(key);
for (Shift shift : shiftList) {
shift.setRequiredEmployeeSize(
shift.getRequiredEmployeeSize() + req);
}
}
List<ShiftAssignment> shiftAssignmentList = new ArrayList<>(
shiftList1.size());
long shiftAssignmentId = nurseRoster.getShiftAssignmentList()
.get(nurseRoster.getShiftAssignmentList().size() - 1)
.getId() + 1L;
for (Shift shift : shiftList1) {
for (int i = 0; i < shift.getRequiredEmployeeSize(); i++) {
ShiftAssignment newShiftAssignment = new ShiftAssignment();
newShiftAssignment.setId(shiftAssignmentId);
shiftAssignmentId++;
newShiftAssignment.setShift(shift);
newShiftAssignment.setIndexInShift(i);
shiftAssignmentList.add(newShiftAssignment);
nurseRoster.getShiftAssignmentList()
.add(newShiftAssignment);
scoreDirector.afterEntityAdded(newShiftAssignment);
}
}
//This should move the planning window
nurseRosterParametrization.setFirstShiftDate(shiftDateList1.get(0));
nurseRosterParametrization.setLastShiftDate(shiftDateList1.get(shiftDateList1.size() - 1));
nurseRosterParametrization.setPlanningWindowStart(shiftDateList1.get(0));
nurseRoster.setNurseRosterParametrization(nurseRosterParametrization);
scoreDirector.afterProblemPropertyChanged(nurseRosterParametrization);
scoreDirector.triggerVariableListeners();
}, true);
}

ODBC-2028 Error SAP B1

I am trying to add a purchase order by DI API for SAP B1. My code is working on my client but I tried it as an addon on another company that has different data. And it gives the error: "No matching records found(ODBC-2028)". Here is a part of my code:
public void createPOrderFor(int id,
string itemCode,
string itemName,
int qty,
int satisSip,
string cardCode,
string cardName,
string releaseDate)
{
SAPbobsCOM.Documents BO_item;
BO_item = (SAPbobsCOM.Documents)getCompany().GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseOrders);
base.doConnectionInfo();
server = base.server;
database = base.database;
user = base.user;
pass = base.pass;
string year = releaseDate.Substring(0, 4);
string month = releaseDate.Substring(4, 2);
string day = releaseDate.Substring(6, 2);
releaseDate = year + "-" + month + "-" + day;
BO_item.Lines.ItemCode = itemCode;
BO_item.Lines.ItemDescription = itemName;
BO_item.Lines.Quantity = qty;
BO_item.Lines.ShipDate = DateTime.Parse(releaseDate);
BO_item.Lines.UserFields.Fields.Item("U_SatisSip").Value = satisSip;
BO_item.Lines.Add();
BO_item.Comments = satisSip + " numaralı satış siparişine istinaden";
BO_item.CardCode = cardCode;
BO_item.CardName = cardName;
BO_item.NumAtCard = "";
BO_item.Series = 13;//birincil
//BO_item.Segment -- it is read only.
BO_item.TaxDate = DateTime.Now;
BO_item.DocDate = DateTime.Now;
BO_item.DocDueDate = DateTime.Parse(releaseDate);
BO_item.SalesPersonCode = 4;//default Hakan Yılmaz
BO_item.DocumentsOwner = 4;
BO_item.DiscountPercent = 0.0;
BO_item.Address2 = "TURKEY";
BO_item.Address = "";
BO_item.TransportationCode = 1;
BO_item.AgentCode = null;
BO_item.JournalMemo = "Satınalma siparişleri - " + cardCode;
BO_item.GroupNumber = 1;//net30
BO_item.PaymentMethod = null;
BO_item.Project = null;
BO_item.UserFields.Fields.Item("U_SatSip").Value = satisSip;
var retVal = BO_item.Add();
int errorCode = 0;
string errMsg = "";
if (retVal != 0)
{
getCompany().GetLastError(out errorCode, out errMsg);
SAPbouiCOM.Framework.Application.SBO_Application.StatusBar.SetText("Error: " + errMsg , SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
}
First of all remove all null fields. If there are DI Object fields that you cannot provide a value for, you should not set them equal to null.
BO_item.AgentCode = null;
BO_item.PaymentMethod = null;
BO_item.Project = null;
Just remove them completely. Also instead of Date.Time.Now try setting a date in this format: 20180531 for all date fields as a test.
BO_item.DocDate = "20180531"
If it returns the same error, attempt to test this in an SAP Business One Demo Database (can be obtained from sap partneredge).
Also, Ensure the User Defined Fields you are trying to set values for exist in your new customer's database
let me know how it works for you so we can continue.

DocuSign does not pass values to Salesforce

DocuSign doesn't pass values back into Salesforce. And Even doesn't give me any errors in the logs.
I used a Custom Field like source ID and MergeFieldXml tab option with the write-back = true. But it doesn't work.
Please advise what is wrong?
Merge fields are enabled for the DocuSign account.
My code example:
global class AnnualContract
{
webService static string AM_SendToDocuSign(String id, string strObjType)
{
Docusign_API_Setting__c APISetting = Docusign_API_Setting__c.getInstance('API Settings');
String envelopeId = '';
string DealerName = '';
string DealerId = '';
String accountId = APISetting.AccountId__c;
String userId = APISetting.UserId__c;
String password = APISetting.Password__c;
String integratorsKey = APISetting.IntegratorsKey__c;
String webServiceUrl = APISetting.WebServiceUrl__c;
list<Lead> lstLead = new list<Lead>();
list<Contact> lstContact = new list<Contact>();
if(strObjType == 'Lead')
{
lstLead = [SELECT Name,Status,Email,FirstName,LastName,Owner.Name,Title,FROM Lead where id = : Id limit 1];
}
StaticResource objSR = [SELECT Id,name, SystemModStamp FROM StaticResource WHERE Name = 'AnnualContractPDF' LIMIT 1];
String url_file_ref = '/resource/' + String.valueOf(((DateTime)objSR.get('SystemModStamp')).getTime())+ '/' + objSR.get('Name');
if(strObjType == 'Lead')
{
DealerName = lstLead[0].Name;
}
DocuSignAPI.APIServiceSoap dsApiSend = new DocuSignAPI.APIServiceSoap();
dsApiSend.endpoint_x = webServiceUrl;
//Set Authentication
String auth = '<DocuSignCredentials><Username>'+ userId
+'</Username><Password>' + password
+ '</Password><IntegratorKey>' + integratorsKey
+ '</IntegratorKey></DocuSignCredentials>';
System.debug('Setting authentication to: ' + auth);
dsApiSend.inputHttpHeaders_x = new Map<String, String>();
dsApiSend.inputHttpHeaders_x.put('X-DocuSign-Authentication',
auth);
DocuSignAPI.Envelope envelope = new DocuSignAPI.Envelope();
envelope.Subject = 'Please Sign this Contract' + lstLead[0].Name;
envelope.EmailBlurb = 'This is my new eSignature service, it allows me to get your signoff without having to fax, scan, retype, refile and wait forever';
envelope.AccountId = accountId;
// Render the contract
System.debug('Rendering the contract');
PageReference pageRef = new PageReference(url_file_ref);
Blob pdfBlob = pageRef.getContent();
DocuSignAPI.CustomField field = new DocuSignAPI.CustomField ();
field.Name = '##SFLead';
field.Value = lstLead[0].Id; //value of the external source Id
field.Show = 'false';
field.CustomFieldType = 'Text';
envelope.CustomFields = new DocuSignAPI.ArrayOfCustomField();
envelope.CustomFields.CustomField = new DocuSignAPI.CustomField[1];
envelope.CustomFields.CustomField[0] = field;
// Document
DocuSignAPI.Document document = new DocuSignAPI.Document();
document.ID = 1;
document.pdfBytes = EncodingUtil.base64Encode(pdfBlob);
document.Name = 'Annual Contract';
document.FileExtension = 'pdf';
envelope.Documents = new DocuSignAPI.ArrayOfDocument();
envelope.Documents.Document = new DocuSignAPI.Document[1];
envelope.Documents.Document[0] = document;
// Recipient
System.debug('Building up the recipient');
DocuSignAPI.Recipient recipient = new DocuSignAPI.Recipient();
recipient.ID = 1;
recipient.Type_x = 'Signer';
recipient.RoutingOrder = 1;
recipient.Email = lstLead[0].Email;
recipient.UserName = lstLead[0].FirstName + ' ' + lstLead[0].LastName;
recipient.RequireIDLookup = false;
envelope.Recipients = new DocuSignAPI.ArrayOfRecipient();
envelope.Recipients.Recipient = new DocuSignAPI.Recipient[1];
envelope.Recipients.Recipient[0] = recipient;
// Tab
DocuSignAPI.Tab tab1 = new DocuSignAPI.Tab();
tab1.Type_x = 'SignHere';
tab1.RecipientID = 1;
tab1.DocumentID = 1;
tab1.AnchorTabItem = new DocuSignAPI.AnchorTab();
tab1.AnchorTabItem.AnchorTabString = '/t1/';
tab1.AnchorTabItem.XOffset = 100;
DocuSignAPI.Tab tab2 = new DocuSignAPI.Tab();
tab2.Type_x = 'DateSigned';
tab2.RecipientID = 1;
tab2.DocumentID = 1;
tab2.AnchorTabItem = new DocuSignAPI.AnchorTab();
tab2.AnchorTabItem.AnchorTabString = '/d1/';
DocuSignAPI.Tab tab3 = new DocuSignAPI.Tab();
tab3.CustomTabType = 'Text';
tab3.Name = 'Title';
tab3.Type_x = 'Custom';
tab3.RecipientID = 1;
tab3.DocumentID = 1;
tab3.TabLabel = 'Title';
if(strObjType == 'Lead')
{
if(lstLead[0].Title != null)
{
tab3.Value = ''+lstLead[0].Title+'';
}
}
else
{
if(lstContact[0].Title != null)
{
tab3.Value = ''+lstContact[0].Title+'';
}
}
tab3.CustomTabWidth=100;
tab3.CustomTabRequired=false;
tab3.CustomTabLocked=false;
tab3.CustomTabDisableAutoSize=false;
tab3.TemplateLocked=false;
tab3.TemplateRequired=false;
tab3.ConditionalParentLabel='';
tab3.ConditionalParentValue='';
tab3.SharedTab=true;
tab3.RequireInitialOnSharedTabChange=false;
tab3.ConcealValueOnDocument=false;
tab3.AnchorTabItem = new DocuSignAPI.AnchorTab();
tab3.AnchorTabItem.AnchorTabString = '/t2/';
tab3.AnchorTabItem.XOffset = 42;
tab3.AnchorTabItem.YOffset = -5;
tab3.MergeFieldXml = '<mergeField><allowSenderToEdit>true</allowSenderToEdit><configurationType>salesforce</configurationType><path>Lead.Title</path><row>1</row><writeBack>true</writeBack></mergeField>';
envelope.Tabs = new DocuSignAPI.ArrayOfTab();
envelope.Tabs.Tab = new DocuSignAPI.Tab[3];
envelope.Tabs.Tab[0] = tab1;
envelope.Tabs.Tab[1] = tab2;
envelope.Tabs.Tab[2] = tab3;
System.debug('Calling the API');
try {
DocuSignAPI.EnvelopeStatus es = dsApiSend.CreateAndSendEnvelope(envelope);
envelopeId = es.EnvelopeID;
System.debug('Returned successfully, envelope id = ' + envelopeId );
return '';
} catch ( CalloutException e) {
System.debug('Exception - ' + e );
envelopeId = 'Exception - ' + e;
return '';
}
return '';
}
}
I resolved the issue with the DocuSign support.
MergeFieldXml for SOAP should be like this:
tab3.MergeFieldXml ='<mergefieldconfig configversion="1.0" service="salesforce"><mergefield><writeenabled>true</writeenabled><sendercanedit>true</sendercanedit><queryfrom><obj><type>Lead</type><name>Lead</name><field><fieldtype>string</fieldtype><name>Title</name></field></obj></queryfrom></mergefield></mergefieldconfig>';

dataadapter update method not working

I have a DataSet which I'm trying to use to update an sql db.
When I call the update method of the dataset's data adapter method. The backend db does not get updated.
To further test the problem I created a variable called rowsAffected which is:
int rowsAffected = private_EnrolleeTableAdapter1.Update(enrollee);
The variable returns 1 when I run the code but the databse is not updated.
Any ideas as to what I might be doing wrong?
Code is included below:
//Create new employee record(row) on Private_Enrollee table in database
HMODataSet.Private_EnrolleeRow enrollee = HMODataSet.Private_Enrollee.NewPrivate_EnrolleeRow();
enrollee.Title = title;
enrollee.Firstname = firstname;
enrollee.Othername = middlename;
enrollee.Surname = surname;
enrollee.Sex = sex;
enrollee.Date_of_Birth = dateofbirth;
enrollee.Office_Tel = officetel;
enrollee.Residential_Tel = restel;
enrollee.Mobile_Tel = mobtel;
enrollee.Email_Address = email;
enrollee.Marital_Status = maritalstatus;
enrollee.Occupation = occupation;
enrollee.NextOfKin_Name = nextofkin;
enrollee.Relationship = relationship;
enrollee.Next_of_Kin_Address = address;
enrollee.Next_of_Kin_Telephone_No = nextofkintelno;
enrollee.Address = address;
enrollee.Town = town;
enrollee.City = city;
enrollee.State = state;
enrollee.Country = country;
enrollee.Hospital = healthcareprovider;
enrollee.Proposed_Plan_Type = proposedinsuranceplan;
enrollee.Blood_Group = bloodgroup;
enrollee.Genotype = genotype;
enrollee.Pre_Informed_Illness = preinformedillness;
enrollee.Existing_Chronic_Illness = chronicdisease;
enrollee.Enrollee_Type = enrolleetypeid;
enrollee.Enrollee_Type_ID = enrolleetypeid;
enrollee.Occupation = occupation;
enrollee.Designation = designation;
enrollee.Employer = employer;
HMODataSet.Private_Enrollee.AddPrivate_EnrolleeRow(enrollee);
int rowsAffected = private_EnrolleeTableAdapter1.Update(enrollee);
HMODataSet.AcceptChanges();