public static string CheckOut(){
String userID;
userID = UserInfo.getUserId();
list<user> u=[select id,Name from user where id=:userID];
string nam= u[0].Name +'-Automated';
list<Opportunity> Oppid=[select id from opportunity where name=:nam];
system.debug('Oppid'+Oppid[0].id);
string OID;
OID=Oppid[0].id;
list<OpportunityLineItem> OppListItems=[select OpportunityId,Quantity,UnitPrice,PriceBookEntryId,Product2Id,InMyCart__c,Wishlisted__c
from OpportunityLineItem where InMyCart__c=:true AND OpportunityId=:OID];
if(OppListItems.size()>0){
Order NewOrder = new Order(
AccountId='0012800000ZKzhH',
Status='Draft',
EffectiveDate=System.today(),
Pricebook2Id ='01s28000006q8A8',
OpportunityId=Oppid[0].id
);
insert NewOrder;
list <OrderItem> OrderitemList=new list<OrderItem>();
For(integer i=0;i<OppListItems.size();i++){
if(OppListItems[i].InMyCart__c==true){
OppListItems[i].InMyCart__c=false;
OrderItem OI=new OrderItem(
OrderId=NewOrder.Id,
Quantity=OppListItems[i].Quantity,
PriceBookEntryId=OppListItems[i].PriceBookEntryId,
UnitPrice=OppListItems[i].UnitPrice
// Product2Id=OppLI[i].Product2Id
);
OrderitemList.add(OI);
}
}
system.debug('OrderitemList'+OrderitemList);
insert OrderitemList;
system.debug('OppLI'+OppListItems);
update OppListItems;
list<OpportunityLineItem> OppLIToDelete=[select id,name from OpportunityLineItem where InMyCart__c=:false AND WishListed__c=:false];
delete OppLIToDelete;
}
return OID;
}OppLIToDelete is getting deleted . But order and order products are not getting created. Any help would be appreciated.Thankyou
4 answers
Eldon-Currently it looks like Orders is not a supported object in the Napili template. http://resources.docs.salesforce.com/202/18/en-us/sfdc/pdf/community_templates.pdf and see page 5 for supported objects for Napili.