Combined ++++
+++++++++
Global class epayworkitemupdates2{
global class workitemdata
{//Input from portal to create/update workitem information in sfdc
webservice String LegalEntityid;
webservice String oppstage;
webservice String accstatus;
webservice String wrkitmstatus;
webservice String wrkitmtype;
webservice String Reasoncode;
webservice String wrkitemid;
}
global class returnWorkitemresponse
{ // response from SFDC to portal with created/updated record details.
webservice String legalEntityId;
webservice String Wrkitmid;
webservice String Status;
}
webservice Static returnWorkitemresponse createupdateworkitems(workitemdata leadlst)
{
returnWorkitemresponse response = new returnWorkitemresponse();
//if((id.length() == 15 || id.length() == 18) && Pattern.matches('^[a-zA-Z0-9]*$', id))
QC_Checklist__c wrkitm = new QC_Checklist__c();
Account Accdetails=new Account();
if((leadlst.wrkitemid != Null && leadlst.wrkitemid !='') &&(leadlst.LegalEntityid == Null && leadlst.LegalEntityid == ''))
{
wrkitm =[Select id,Opportunity_Merchant_Name__c,Opportunity_Merchant_Name__r.StageName,Type__c,Contract_Status__c,
Reject_Reason__c,Boarding_Source__c from QC_Checklist__c WHERE id = :leadlst.wrkitemid];
system.debug('workitem not null');
//
if(wrkitm != Null && leadlst.LegalEntityid == Null ) {
//query the account details
Opportunity Oppdetails2=[Select id,Name,Probability,StageName,AccountId from Opportunity where id=:wrkitm.Opportunity_Merchant_Name__c ];
Account Accdetails2=[select id,name,AccountNumber,Account_Status__c from Account where id=:Oppdetails2.AccountId];
if(wrkitm.Contract_Status__c == 'Complete - 16')
{
wrkitm.Opportunity_Merchant_Name__c=Accdetails2.AccountNumber;
//wrkitm.Type__c=leadlst.wrkitmtype;
wrkitm.Contract_Status__c=leadlst.wrkitmstatus;
// wrkitm.Reject_Reason__c=;
update wrkitm;
Oppdetails2.StageName='Closed Won';
update Oppdetails2;
Accdetails2.Account_Status__c='Active';
update Accdetails2;
response.status = 'updated workitem';
response.Wrkitmid = wrkitm.id;
}else if(wrkitm.Contract_Status__c == 'Resubmit') //instead of referal we use resubmit
{
wrkitm.Contract_Status__c='Resubmit';
update wrkitm;
//noified to CR ops team
response.status = 'workitem status is refereal';
}
else
{
response.status = 'workitem status not active or referal';
}
}
//
} else
if(leadlst.LegalEntityid != Null && leadlst.LegalEntityid != ''){
//Accdetails=[select id,name,AccountNumber,Account_Status__c from Account where AccountNumber=:leadlst.LegalEntityid];
Accdetails=[select id,name,AccountNumber,Account_Status__c from Account where AccountNumber= :leadlst.LegalEntityid];
system.debug('legalEntityId not null');
//
if((Accdetails.AccountNumber !=null && Accdetails.AccountNumber!='') && (leadlst.wrkitemid ==''&& leadlst.wrkitemid == null) )
{
system.debug('account query results'+Accdetails);
system.debug('leadlst wrktmd results'+leadlst.wrkitemid);
//string wokitmid=leadlst.wrkitemid;
system.debug('leadlst wrktmd results'+leadlst.wrkitemid);
system.debug('Accdetails results'+Accdetails);
Opportunity Oppdetails=[Select id,Name,Probability,StageName,AccountId from Opportunity where Account.AccountNumber=:leadlst.LegalEntityid];
RecordType rType = [Select id,Name from RecordType
where Name ='QcChecklist_ePayablePortal'
AND SobjectType= 'QC_Checklist__c'];
system.debug('opp query results'+Oppdetails);
if(Accdetails.Account_Status__c == 'Active')
{
QC_Checklist__c workitem1 = new QC_Checklist__c();
// workitem1.Opportunity_Merchant_Name__c = leadlst.LegalEntityid;
workitem1.Opportunity_Merchant_Name__c = '0061b000002OuXg';
workitem1.RecordTypeId= rType.Id;
workitem1.QC_Rep__c=UserInfo.getUserId();
//workitem1.Type__c=leadlst.wrkitmtype;
workitem1.Contract_Status__c=leadlst.wrkitmstatus;
//workitem1.Reject_Reason__c=;
//workitem1.Boarding_Source__c=leadlst.Reasoncode;
insert workitem1;
// response.legalEntityId =leadlst.LegalEntityid;
response.Wrkitmid =workitem1.id;
System.debug('new workitem opp name'+workitem1.Opportunity_Merchant_Name__c);
System.debug('new workitemid'+workitem1.id);
System.debug('new workitem assigned user'+workitem1.QC_Rep__c);
}else if(Accdetails.Account_Status__c == 'Sold'){ //instead of service i given sold because value is not in dev
RecordType rType2 = [Select id,Name from RecordType where Name ='Case_ePayablePortal' AND SobjectType= 'Case'];
case casedetails=[select id,AccountId,Status,Type,Recordtype.name from case where Account.AccountNumber=:leadlst.LegalEntityid and Recordtype.name='Case_ePayablePortal' limit 1 ];
System.debug('casedetails query'+casedetails);
if(casedetails != Null){
casedetails.Status='In Progress';
//casedetails.Type=leadlst.wrkitmtype;
update casedetails;
response.Status ='Case Updated';
}
else {
case c1=new case();
c1.AccountId=Accdetails.id;
c1.RecordTypeId= rType2.Id;
c1.Status='New';
//c1.Type=leadlst.wrkitmtype;
insert c1;
response.Status ='Case created';
//response.Wrkitmid =c1.id;
return response;
}
}
else{
response.Status ='Account status is not active or sevice';
}
}
//
} else
if((leadlst.wrkitemid == Null && leadlst.wrkitemid == '') && (leadlst.LegalEntityid == Null && leadlst.LegalEntityid == ''))
{
response.status = 'please Provide legalEntityId or Workitem id to update the workitem';
//return response;
}
else
//
{
if(Accdetails == Null && wrkitm == Null){
response.status = 'please Provide valid legalEntityId or Workitem id to update the workitem';
}
}
return response;
}
}
+++++++++
Global class epayworkitemupdates2{
global class workitemdata
{//Input from portal to create/update workitem information in sfdc
webservice String LegalEntityid;
webservice String oppstage;
webservice String accstatus;
webservice String wrkitmstatus;
webservice String wrkitmtype;
webservice String Reasoncode;
webservice String wrkitemid;
}
global class returnWorkitemresponse
{ // response from SFDC to portal with created/updated record details.
webservice String legalEntityId;
webservice String Wrkitmid;
webservice String Status;
}
webservice Static returnWorkitemresponse createupdateworkitems(workitemdata leadlst)
{
returnWorkitemresponse response = new returnWorkitemresponse();
//if((id.length() == 15 || id.length() == 18) && Pattern.matches('^[a-zA-Z0-9]*$', id))
QC_Checklist__c wrkitm = new QC_Checklist__c();
Account Accdetails=new Account();
if((leadlst.wrkitemid != Null && leadlst.wrkitemid !='') &&(leadlst.LegalEntityid == Null && leadlst.LegalEntityid == ''))
{
wrkitm =[Select id,Opportunity_Merchant_Name__c,Opportunity_Merchant_Name__r.StageName,Type__c,Contract_Status__c,
Reject_Reason__c,Boarding_Source__c from QC_Checklist__c WHERE id = :leadlst.wrkitemid];
system.debug('workitem not null');
//
if(wrkitm != Null && leadlst.LegalEntityid == Null ) {
//query the account details
Opportunity Oppdetails2=[Select id,Name,Probability,StageName,AccountId from Opportunity where id=:wrkitm.Opportunity_Merchant_Name__c ];
Account Accdetails2=[select id,name,AccountNumber,Account_Status__c from Account where id=:Oppdetails2.AccountId];
if(wrkitm.Contract_Status__c == 'Complete - 16')
{
wrkitm.Opportunity_Merchant_Name__c=Accdetails2.AccountNumber;
//wrkitm.Type__c=leadlst.wrkitmtype;
wrkitm.Contract_Status__c=leadlst.wrkitmstatus;
// wrkitm.Reject_Reason__c=;
update wrkitm;
Oppdetails2.StageName='Closed Won';
update Oppdetails2;
Accdetails2.Account_Status__c='Active';
update Accdetails2;
response.status = 'updated workitem';
response.Wrkitmid = wrkitm.id;
}else if(wrkitm.Contract_Status__c == 'Resubmit') //instead of referal we use resubmit
{
wrkitm.Contract_Status__c='Resubmit';
update wrkitm;
//noified to CR ops team
response.status = 'workitem status is refereal';
}
else
{
response.status = 'workitem status not active or referal';
}
}
//
} else
if(leadlst.LegalEntityid != Null && leadlst.LegalEntityid != ''){
//Accdetails=[select id,name,AccountNumber,Account_Status__c from Account where AccountNumber=:leadlst.LegalEntityid];
Accdetails=[select id,name,AccountNumber,Account_Status__c from Account where AccountNumber= :leadlst.LegalEntityid];
system.debug('legalEntityId not null');
//
if((Accdetails.AccountNumber !=null && Accdetails.AccountNumber!='') && (leadlst.wrkitemid ==''&& leadlst.wrkitemid == null) )
{
system.debug('account query results'+Accdetails);
system.debug('leadlst wrktmd results'+leadlst.wrkitemid);
//string wokitmid=leadlst.wrkitemid;
system.debug('leadlst wrktmd results'+leadlst.wrkitemid);
system.debug('Accdetails results'+Accdetails);
Opportunity Oppdetails=[Select id,Name,Probability,StageName,AccountId from Opportunity where Account.AccountNumber=:leadlst.LegalEntityid];
RecordType rType = [Select id,Name from RecordType
where Name ='QcChecklist_ePayablePortal'
AND SobjectType= 'QC_Checklist__c'];
system.debug('opp query results'+Oppdetails);
if(Accdetails.Account_Status__c == 'Active')
{
QC_Checklist__c workitem1 = new QC_Checklist__c();
// workitem1.Opportunity_Merchant_Name__c = leadlst.LegalEntityid;
workitem1.Opportunity_Merchant_Name__c = '0061b000002OuXg';
workitem1.RecordTypeId= rType.Id;
workitem1.QC_Rep__c=UserInfo.getUserId();
//workitem1.Type__c=leadlst.wrkitmtype;
workitem1.Contract_Status__c=leadlst.wrkitmstatus;
//workitem1.Reject_Reason__c=;
//workitem1.Boarding_Source__c=leadlst.Reasoncode;
insert workitem1;
// response.legalEntityId =leadlst.LegalEntityid;
response.Wrkitmid =workitem1.id;
System.debug('new workitem opp name'+workitem1.Opportunity_Merchant_Name__c);
System.debug('new workitemid'+workitem1.id);
System.debug('new workitem assigned user'+workitem1.QC_Rep__c);
}else if(Accdetails.Account_Status__c == 'Sold'){ //instead of service i given sold because value is not in dev
RecordType rType2 = [Select id,Name from RecordType where Name ='Case_ePayablePortal' AND SobjectType= 'Case'];
case casedetails=[select id,AccountId,Status,Type,Recordtype.name from case where Account.AccountNumber=:leadlst.LegalEntityid and Recordtype.name='Case_ePayablePortal' limit 1 ];
System.debug('casedetails query'+casedetails);
if(casedetails != Null){
casedetails.Status='In Progress';
//casedetails.Type=leadlst.wrkitmtype;
update casedetails;
response.Status ='Case Updated';
}
else {
case c1=new case();
c1.AccountId=Accdetails.id;
c1.RecordTypeId= rType2.Id;
c1.Status='New';
//c1.Type=leadlst.wrkitmtype;
insert c1;
response.Status ='Case created';
//response.Wrkitmid =c1.id;
return response;
}
}
else{
response.Status ='Account status is not active or sevice';
}
}
//
} else
if((leadlst.wrkitemid == Null && leadlst.wrkitemid == '') && (leadlst.LegalEntityid == Null && leadlst.LegalEntityid == ''))
{
response.status = 'please Provide legalEntityId or Workitem id to update the workitem';
//return response;
}
else
//
{
if(Accdetails == Null && wrkitm == Null){
response.status = 'please Provide valid legalEntityId or Workitem id to update the workitem';
}
}
return response;
}
}
++++++++++++++
For Using
+++++
Global class epayworkitemupdates2{
global class workitemdata
{//Input from portal to create/update workitem information in sfdc
webservice String LegalEntityid;
webservice String oppstage;
webservice String accstatus;
webservice String wrkitmstatus;
webservice String wrkitmtype;
webservice String Reasoncode;
webservice String wrkitemid;
}
global class returnWorkitemresponse
{ // response from SFDC to portal with created/updated record details.
webservice String legalEntityId;
webservice String Wrkitmid;
webservice String Status;
}
webservice Static List<returnWorkitemresponse> createupdateworkitems(List<workitemdata> leadlst)
{
returnWorkitemresponse response = new returnWorkitemresponse();
List<returnWorkitemresponse> respLst = new List<returnWorkitemresponse>();
//if((id.length() == 15 || id.length() == 18) && Pattern.matches('^[a-zA-Z0-9]*$', id))
QC_Checklist__c wrkitm = new QC_Checklist__c();
Account Accdetails=new Account();
List<workitemdata> wrkitemids = new List<workitemdata>();
List<Account> AccdetailsLst = new List<Account>();
List<workitemdata> LegalEntityids = new List<workitemdata>();
List<QC_Checklist__c> wrkitms = new List<QC_Checklist__c>();
for(workitemdata workData:leadlst){
wrkitemids.add(workData.wrkitemid);
}
for(workitemdata workData:leadlst){
LegalEntityids.add(workData.LegalEntityid);
}
if((!wrkitemids.isEmpty()) && (LegalEntityids.isEmpty())){
wrkitms = [Select id,Opportunity_Merchant_Name__c,Opportunity_Merchant_Name__r.StageName,Type__c,Contract_Status__c,
Reject_Reason__c,Boarding_Source__c from QC_Checklist__c WHERE id IN:wrkitemids];
}
else if(!LegalEntityids.isEMpty()){
AccdetailsLst = [select id,name,AccountNumber,Account_Status__c from Account where AccountNumber IN:LegalEntityids];
}
else if((wrkitemids.isEmpty()) && (LegalEntityids.isEmpty())){
response.status = 'please Provide legalEntityId or Workitem id to update the workitem';
returnWorkitemresponse.add(response);
return returnWorkitemresponse;
}
if((!wrkitms.isEmpty()) && (LegalEntityids.isEmpty())){
List<Opportunity> Oppdetails2Lst = new List<Opportunity>();
LIst<string> oppMetrcNamesLst = new LIst<string>();
List<Account> Accdetails2Lst = new List<Account>();
List<QC_Checklist__c> wrkitmscontStatLst = new List<QC_Checklist__c>();
set<Id> accIDs = new set<Id>();
for(QC_Checklist__c qcCheck:wrkitms){
oppMetrcNamesLst.add(qcCheck.Opportunity_Merchant_Name__c);
if(qcCheck.Contract_Status__c == 'Complete - 16'){
wrkitmscontStatLst.add(qcCheck);
}
if(qcCheck.Contract_Status__c == 'Resubmit'){
wrkitmscontStatLst.add(qcCheck);
}
}
if(!oppMetrcNamesLst.isEmpty()){
Oppdetails2Lst = [Select id,Name,Probability,StageName,AccountId,Opportunity_Merchant_Name__c from Opportunity where id IN:oppMetrcNamesLst];
}
if(!Oppdetails2Lst.isEmpty()){
for(Opportunity opp:Oppdetails2Lst){
accIDs.add(opp.AccountId);
}
}
if(!accIDs.isEmpty()){
Accdetails2Lst = [select id,name,AccountNumber,Account_Status__c from Account where id IN:accIDs];
}
if(!wrkitmscontStatLst.isEmpty()){
List<Opportunity> newOppLst = new List<Opportunity>();
List<Opportunity> newOppLstToUpdate = new List<Opportunity>();
List<Account> newAccListToUpdate = new List<Account>();
for(Account acc:Accdetails2Lst)
{
for(Opportunity opp:oppMetrcNamesLst){
for(workitemdata work:leadlst){
for(Opportunity opp1:Oppdetails2Lst){
opp.Opportunity_Merchant_Name__c=acc.AccountNumber;
//wrkitm.Type__c=leadlst.wrkitmtype;
opp.Contract_Status__c=work.wrkitmstatus;
// wrkitm.Reject_Reason__c=;
newOppLst.add(opp);
//update wrkitm;
opp1.StageName='Closed Won';
newOppLstToUpdate.add(opp1);
//update Oppdetails2;
acc.Account_Status__c='Active';
newAccListToUpdate.add(acc);
//update Accdetails2;
if(opp.Contract_Status__c == 'Complete - 16')
response.status = 'updated workitem';
else
response.status = 'workitem status is refereal';
response.Wrkitmid = opp.id;
returnWorkitemresponse.add(response);
}
}
}
}
if(!newOppLst.isEmpty())
update newOppLst;
if(!newOppLstToUpdate.isEmpty())
update newOppLstToUpdate;
if(!newAccListToUpdate.isEmpty())
update newAccListToUpdate;
}
}
/*if((leadlst.wrkitemid != Null && leadlst.wrkitemid !='') &&(leadlst.LegalEntityid == Null && leadlst.LegalEntityid == ''))
} */
List<QC_Checklist__c> qcToUpdateLSt = new List<QC_Checklist__c>();
List<case> casedetailsLst = new List<case>();
List<case> newLstToCreate = new List<case>();
List<case> newLstToCreate1 = new List<case>();
casedetailsLst=[select id,AccountId,Status,Type from case where Account.AccountNumber IN:LegalEntityids];
for(Account acc:AccdetailsLst){
for(workitemdata work:leadlst){
if(acc.Account_Status__c == 'Active'){
QC_Checklist__c workitem1 = new QC_Checklist__c();
// workitem1.Opportunity_Merchant_Name__c = leadlst.LegalEntityid;
workitem1.Opportunity_Merchant_Name__c = '0061b000002OuXg';
workitem1.QC_Rep__c=UserInfo.getUserId();
//workitem1.Type__c=leadlst.wrkitmtype;
workitem1.Contract_Status__c=leadlst.wrkitmstatus;
//workitem1.Reject_Reason__c=;
//workitem1.Boarding_Source__c=leadlst.Reasoncode;
qcToUpdateLSt.add(workitem1);
//insert workitem1;
// response.legalEntityId =leadlst.LegalEntityid;
response.Wrkitmid =workitem1.id;
}
else if(acc.Account_Status__c == 'Sold'){
//case casedetails=[select id,AccountId,Status,Type from case where Account.AccountNumber IN:LegalEntityids];
if(casedetailsLst.isEmpty()){
case c1=new case();
c1.AccountId=acc.id;
c1.Status='New';
//c1.Type=leadlst.wrkitmtype;
newLstToCreate.add(c1);
//insert c1;
response.Status ='Case created';
returnWorkitemresponse.add(response);
//response.Wrkitmid =c1.id;
//return response;
return returnWorkitemresponse;
}else if(!casedetailsLst.isEmpty()){
for(case cas:casedetailsLst){
cas.Status='In Progress';
newLstToCreate1.add(cas);
}
//casedetails.Status='In Progress';
//casedetails.Type=leadlst.wrkitmtype;
//update casedetails;
response.Status ='Case Updated';
}
}
}
}
if(!qcToUpdateLSt.isEmpty())
insert qcToUpdateLSt;
for(QC_Checklist__c workItem:qcToUpdateLSt){
response.Wrkitmid = workItem.id;
returnWorkitemresponse.add(response);
}
if(!newLstToCreate.isEmpty())
insert newLstToCreate;
if(!newLstToCreate1.isEmpty())
update newLstToCreate1;
if((wrkitms.isEmpty()) && (AccdetailsLst.isEmpty())){
response.status = 'please Provide valid legalEntityId or Workitem id to update the workitem';
returnWorkitemresponse.add(response);
}
return returnWorkitemresponse;
/*if(Accdetails!= Null && leadlst.wrkitemid == Null){
return response; */
}
}
++++++++++++++++++++++++++++++++++++