You need to sign in to do that
Don't have an account?
syed akram
how to solve this error?
System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []
This is a permission issue , you need to change your sharing rules,profile permissions etc.You will get accurate reason for this ,If you can paste your code here .
Thanks
Ajay
Check filed level security as well object level access(Relationship between two object).
Thanks
public without sharing class UpdateList {
list<order> selectorder;
String quoteId {set; get;}
String selectedOrderId {set; get;}
public List<Order> selectedOrders {set; get;}
public Boolean orderUpdated {set; get;}
public UpdateList(){
quoteId = ApexPages.currentPage().getParameters().get('quoteID');
orderUpdated = false;
}
public PageReference selectOrder(){
selectedOrderId = ApexPages.currentPage().getParameters().get('ordersRadio');
selectedOrders = [select Id, OrderNumber, Status from Order where id=:selectedOrderId];
return null;
}
public list<Order> getorderslist()
{
List<order> allords=[select Id,Ordernumber,Status from Order where quoteId=:quoteId];
return allords;
}
//call this method to update order, and copy all quote line items from quote
public PageReference updateOrder(){
//get selected orderId from the list
selectedOrderId = ApexPages.currentPage().getParameters().get('ordersRadio');
//get quote line items using the quoteId
List<OrderItem> orderLines = new List<OrderItem>();
for(QuoteLineItem qLine : [SELECT Id, QuoteId, PricebookEntryId, Quantity, UnitPrice, Discount, Description, ServiceDate,
Product2Id, SortOrder, ListPrice, Subtotal, TotalPrice FROM QuoteLineItem where QuoteId=:quoteId]){
OrderItem oLine = new OrderItem();
oLine.OrderId = selectedOrderId;
oLine.PricebookEntryId = qLine.PricebookEntryId;
oLine.Quantity = qLine.Quantity;
oLine.UnitPrice = qLine.UnitPrice;
oLine.Description = qLine.Description;
oLine.ServiceDate = qLine.ServiceDate;
orderLines.add(oLine);
}
insert orderLines;
orderUpdated = true;
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Record updated Successfully.Thank you!'));
return null;
}
}
here is test class when i am running the test class i am getting Error.
@istest (seeAllData=true)
private without sharing class TestUpdateList{
Private static Account a;
Private static Contact c;
Private static Opportunity opp;
Private static Quote q;
Private static QuoteLineItem Qli;
private static Order o;
Static {
// Creating the data for Account,Contact,Opportunity,Quote and Order.
a=new Account(Name='test1',Phone='9458383336'); // creating account with only mandatory Fields
insert a;
c = new Contact(LastName='Test',AccountId=a.Id); // creating contact with only mandatory Fields
insert c;
// creating opportunity with only mandatory Fields
opp = new Opportunity(Name='Test Opp',AccountId=a.Id,StageName='closedwon',CloseDate=Date.Today());
insert opp;
Pricebook2 stdPb = [select Id from Pricebook2 where isStandard=true limit 1];
Product2 p = new product2(name='test',family='test',productcode='12345');
insert p;
System.debug('### p:'+p);
PricebookEntry pbe = new PricebookEntry(pricebook2id=stdPb.id, product2id=p.id,
unitprice=1.0, isActive=true,UseStandardPrice=false);
insert pbe;
// Creating Quote with only mandatory Fields
q=new Quote(Name='testquote',opportunityId=opp.Id, pricebook2id=stdPb.id);
insert q;
// Creating Quote Line Items PricebookEntryId, Product2Id
qli=new QuoteLineItem(QuoteId=q.Id,pricebookentryid=pbe.id, Quantity=12,UnitPrice=1500,Discount=0,Description='nothing',ServiceDate=system.today());
insert qli;
// Creating Order with mandatory Fields
o=new Order(AccountId=a.Id,Name='test',status='draft',EffectiveDate=system.today());
insert o;
}
// retreiving the order record and working fine 25% code coverage with this method.
Static TestMethod void Testgetorderslist(){
Test.StartTest();
PageReference pageRef=page.PrevOrder;
pageRef.getParameters().put('quoteID',q.Id);
Test.SetCurrentPageReference(pageRef);
UpdateList ul=new UpdateList();
List<order> orderList = ul.getorderslist();
pageRef.getParameters().put('selectOrder',o.Id);
ul.SelectOrder();
ul.updateOrder();
system.debug('test result ='+ orderList);
system.assertEquals(orderList.size(),1);
Test.StopTest();
}
//after this method i am getting 46% code
Static TestMethod void TestselectOrder(){
Test.StartTest();
PageReference pageRef=page.PrevOrder;
Test.SetCurrentPageReference(pageRef);
ApexPages.currentPage().getParameters().put('ordersRadio',o.Id);
ApexPages.StandardController sc = new ApexPages.standardController(o);
UpdateList controller=new UpdateList();
controller.SelectOrder();
controller.UpdateOrder();
Test.StopTest();
}
}
Add the following statement in your testmethod and execute.
User newuser = new User(alias = 'hasrole', email='userwithrole@roletest1.com', userroleid = r.id, emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US', localesidkey='en_US', profileid = <<system admin profileid>>, timezonesidkey='America/Los_Angeles', username='userwithrole@testorg.com');
insert newuser;
System.RunAs(newuser)
{
//execute the update statements;
}
http://salesforce.stackexchange.com/questions/34863/test-code-for-the-new-standard-order-object