• ajnixx
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies

Hi guys,

 

I need your help. I have this error and i can't find any solution. im stuck for a few days now...thanks (heres the code)

 

Error Message:    System.QueryException: List has no rows for assignment to SObject  ---- Class.POController.<init>: line 31, column 1

 

 

Code:

 

public class POController {
public String orderLineItems { get; set; }

public String getPO_Line_Item() {
return null;
}


public class MissingAccountException extends Exception {}
public class NoLineItemsException extends Exception {}


public Account account {get; private set;}
public Opportunity opportunity {get; private set;}
public Purchase_Order__c order {get; private set;}
public OpportunityLineItem oppLineItem {get; private set;}
public PO_Line_Item__c[] poLineItems {get; private set;}
public PO_Line_Item__c poLineItem {get; private set;}
public List<PO_Line_Item__c> lineItems= new List<PO_Line_Item__c>();
private integer itemCount=0;

private PriceBookEntry pbEntry;

public POController() {

Boolean ShowPartner=false;
Id id = ApexPages.currentPage().getParameters().get('id');
//Id accountId=ApexPages.currentPage().getParameters().get('aId');
Id opportunityId = ApexPages.currentPage().getParameters().get('oId');

opportunity = (opportunityId == null) ? new Opportunity() :[SELECT name, accountID, CloseDate, Description, StageName, Pricebook2Id FROM Opportunity WHERE id = :smileysurprised:pportunityId];

if (opportunity.AccountId != null){
account =new Account();
account= [SELECT name, accountnumber, billingstreet, BillingCity, BillingState, BillingPostalCode, BillingCountry,ShippingStreet, ShippingCity, ShippingState, ShippingPostalCode, ShippingCountry, phone, fax FROM account WHERE id = :smileysurprised:pportunity.AccountId] ;
}else {
throw new MissingAccountException('Cannot create an order from this opportunity: Please assign an account to the opportunity.');
}

order = (id == null) ? new Purchase_Order__c() :
[SELECT Purchase_Order__c.Name FROM Purchase_Order__c WHERE id = :id];

//Pre-populate Opportunity and account information
order.Status_Code__c='New';


//Create a new PO_Line_Item__c and populate a row for each POLineItem that exists

integer i = 0;
poLineItems = new PO_Line_Item__c[0];
for(OpportunityLineItem opp: [SELECT Id, SortOrder, PricebookEntryId, Description, Quantity, ListPrice, UnitPrice, TotalPrice, ServiceDate FROM OpportunityLineItem WHERE Opportunityid = :smileysurprised:pportunityId])
{

string pbeID = opp.PricebookEntryId;
pbEntry = (pbeId == null) ? new PriceBookEntry() :
[Select Id, Name, Pricebook2Id, Product2Id, ProductCode from PricebookEntry where Id=:smileytongue:beID];


poLineItem = new PO_Line_Item__c();
poLineItem.Purchase_Order__c=order.Id;
poLineItem.Product__c = pbEntry.Product2Id;
poLineItem.Name = pbEntry.Name;
poLineItem.Unit_Price__c = opp.ListPrice;
poLineItems.add(poLineItem);
i++;
}
itemCount=i;
if (itemCount == 0) {
throw new NoLineItemsException('Unable to create PO: Products must be added to Sales Order before creating a PO.');
}
System.Debug('Finished Page Load');

}

//Returns the user back to the Sales Order page this was launched from
public PageReference cancel(){
return (new ApexPages.StandardController(Opportunity)).view();
}
//saves PO and child PO
public PageReference save() {
System.Debug('Running Save Method');

try
{
insert order;
System.Debug(order.id);
for(PO_Line_Item__c li: poLineItems)
{
li.Purchase_Order__c=order.id;
}
insert poLineItems;
//If the Opportunity Stage is not 'Closed Won' then update it
if (Opportunity.StageName != 'Closed Won'){
Opportunity.StageName='Closed Won';
update Opportunity;
}
}catch(System.DMLException e)
{
ApexPages.addMessages(e);
return null;
}

// After Save, navigate to the default view page:
return (new ApexPages.StandardController(order)).view();
}

public PageReference loadHelpPage(){
PageReference pg = new PageReference('/apex/CreatePOHelp');
return pg;
}


}

  • February 20, 2013
  • Like
  • 0

Please help.. i'm stuck on this. Can't figure out which is wrong with my coding. I received an error '

Error: Compile Error: expecting a semi-colon, found '(' at line 83 column 29 

Any help will be appreciated. Thanks

 

This is my code:

 

public class InvoiceController {

public class MissingAccountException extends Exception {}
public class NoLineItemsException extends Exception {}


public Account account {get; private set;}
public Opportunity opportunity {get; private set;}
public Invoice__c order {get; private set;}
public OpportunityLineItem oppLineItem {get; private set;}
public Invoice_Line_Item__c[] invoiceLineItems {get; private set;}
public Invoice_Line_Item__c invoiceLineItem {get; private set;}
public List<Invoice_Line_Item__c> lineItems= new List<Invoice_Line_Item__c>();
private integer itemCount=0;

private PriceBookEntry pbEntry;

public InvoiceController() {

Boolean ShowPartner=false;
Id id = ApexPages.currentPage().getParameters().get('id');
//Id accountId=ApexPages.currentPage().getParameters().get('aId');
Id opportunityId = ApexPages.currentPage().getParameters().get('oId');

opportunity = (opportunityId == null) ? new Opportunity() :
[SELECT name, accountID, CloseDate, Description, StageName, Pricebook2Id FROM Opportunity WHERE id = :opportunityId];

if (opportunity.AccountId != null){
account =new Account();
account= [SELECT name, accountnumber, billingstreet, BillingCity, BillingState, BillingPostalCode, BillingCountry,ShippingStreet, ShippingCity, ShippingState, ShippingPostalCode, ShippingCountry, phone, fax FROM account WHERE id = :opportunity.AccountId] ;
}else {
throw new MissingAccountException('Cannot create an invoice from this opportunity: Please assign an account to the opportunity.');
}

invoice = (id == null) ? new Invoice__c() :
[SELECT Invoice__c.Name FROM Invoice__c WHERE id = :id];

{

//Pre-populate Opportunity and account information
invoice.Name=Opportunity.Name;
invoice.AccountId__c=opportunity.AccountId;
invoice.OpportunityId__c = opportunity.id;
invoice.Status__c='New';

//Retrieve the PriceBook name for Prepopulation in order
string pbID = opportunity.Pricebook2Id;
PriceBook2 pb = (opportunity.Pricebook2Id == null) ? new PriceBook2() :
[Select Id, Name from Pricebook2 where Id=:pbID];
invoice.Pricebook__c=pb.Name;

//Create a new Invoice_Line_Item__c and populate a row for each oppLineItem that exists

integer i = 0;
Invoice_Line_Item = new Invoice_Line_Item__c[0];
for(OpportunityLineItem opp: [SELECT Id, SortOrder, PricebookEntryId, Description, Quantity, ListPrice, UnitPrice, TotalPrice, ServiceDate FROM OpportunityLineItem WHERE Opportunityid = :opportunityId])
{

string pbeID = opp.PricebookEntryId;
pbEntry = (pbeId == null) ? new PriceBookEntry() :
[Select Id, Name, Pricebook2Id, Product2Id, ProductCode from PricebookEntry where Id=:pbeID];


invoiceLineItem = new Invoice_Line_Item__c();
invoiceLineItem.Invoice__c=invoice.Id;
invoiceLineItem.Invoice__c = i+1;
invoiceLineItem.ProductId__c = pbEntry.Product2Id;
invoiceLineItem.Name = pbEntry.Name;
invoiceLineItem.Quantity__c = opp.Quantity;
invoiceLineItem.List_Price__c= opp.ListPrice;
invoiceLineItem.Sales_Price__c=opp.UnitPrice;
invoiceLineItem.Total_Price__c=opp.TotalPrice;
invoiceLineItem.add(Invoice_Line_Item);
i++;
}
itemCount=i;
if (itemCount == 0) {
throw new NoLineItemsException('Unable to create Invoice: Products must be added to the Opportunity before creating an Invoice.');
}
System.Debug('Finished Page Load');

}
public PageReference cancel() {
return (new ApexPages.StandardController(opportunity)).view();
}
//saves invoice and child invoices
public PageReference save() {
System.Debug('Running Save Method');

try
{
insert invoice;
System.Debug(invoice.id);
for(Invoice_Line_Item__c li: invoiceLineItems)
{
li.Invoice__c=invoice.id;
}
insert invoiceLineItems;
//If the Opportunity Stage is not 'Closed Won' then update it
if (Opportunity.StageName != 'Closed Won'){
Opportunity.StageName='Closed Won';
update Opportunity;
}
}catch(System.DMLException e)
{
ApexPages.addMessages(e);
return null;
}

// After Save, navigate to the default view page:
return (new ApexPages.StandardController(invoice)).view();
}

public PageReference loadHelpPage(){
PageReference pg = new PageReference('/apex/CreateInvoiceHelp');
return pg;
}


}

 

 

  • February 10, 2013
  • Like
  • 0

Hi guys,

 

I need your help. I have this error and i can't find any solution. im stuck for a few days now...thanks (heres the code)

 

Error Message:    System.QueryException: List has no rows for assignment to SObject  ---- Class.POController.<init>: line 31, column 1

 

 

Code:

 

public class POController {
public String orderLineItems { get; set; }

public String getPO_Line_Item() {
return null;
}


public class MissingAccountException extends Exception {}
public class NoLineItemsException extends Exception {}


public Account account {get; private set;}
public Opportunity opportunity {get; private set;}
public Purchase_Order__c order {get; private set;}
public OpportunityLineItem oppLineItem {get; private set;}
public PO_Line_Item__c[] poLineItems {get; private set;}
public PO_Line_Item__c poLineItem {get; private set;}
public List<PO_Line_Item__c> lineItems= new List<PO_Line_Item__c>();
private integer itemCount=0;

private PriceBookEntry pbEntry;

public POController() {

Boolean ShowPartner=false;
Id id = ApexPages.currentPage().getParameters().get('id');
//Id accountId=ApexPages.currentPage().getParameters().get('aId');
Id opportunityId = ApexPages.currentPage().getParameters().get('oId');

opportunity = (opportunityId == null) ? new Opportunity() :[SELECT name, accountID, CloseDate, Description, StageName, Pricebook2Id FROM Opportunity WHERE id = :smileysurprised:pportunityId];

if (opportunity.AccountId != null){
account =new Account();
account= [SELECT name, accountnumber, billingstreet, BillingCity, BillingState, BillingPostalCode, BillingCountry,ShippingStreet, ShippingCity, ShippingState, ShippingPostalCode, ShippingCountry, phone, fax FROM account WHERE id = :smileysurprised:pportunity.AccountId] ;
}else {
throw new MissingAccountException('Cannot create an order from this opportunity: Please assign an account to the opportunity.');
}

order = (id == null) ? new Purchase_Order__c() :
[SELECT Purchase_Order__c.Name FROM Purchase_Order__c WHERE id = :id];

//Pre-populate Opportunity and account information
order.Status_Code__c='New';


//Create a new PO_Line_Item__c and populate a row for each POLineItem that exists

integer i = 0;
poLineItems = new PO_Line_Item__c[0];
for(OpportunityLineItem opp: [SELECT Id, SortOrder, PricebookEntryId, Description, Quantity, ListPrice, UnitPrice, TotalPrice, ServiceDate FROM OpportunityLineItem WHERE Opportunityid = :smileysurprised:pportunityId])
{

string pbeID = opp.PricebookEntryId;
pbEntry = (pbeId == null) ? new PriceBookEntry() :
[Select Id, Name, Pricebook2Id, Product2Id, ProductCode from PricebookEntry where Id=:smileytongue:beID];


poLineItem = new PO_Line_Item__c();
poLineItem.Purchase_Order__c=order.Id;
poLineItem.Product__c = pbEntry.Product2Id;
poLineItem.Name = pbEntry.Name;
poLineItem.Unit_Price__c = opp.ListPrice;
poLineItems.add(poLineItem);
i++;
}
itemCount=i;
if (itemCount == 0) {
throw new NoLineItemsException('Unable to create PO: Products must be added to Sales Order before creating a PO.');
}
System.Debug('Finished Page Load');

}

//Returns the user back to the Sales Order page this was launched from
public PageReference cancel(){
return (new ApexPages.StandardController(Opportunity)).view();
}
//saves PO and child PO
public PageReference save() {
System.Debug('Running Save Method');

try
{
insert order;
System.Debug(order.id);
for(PO_Line_Item__c li: poLineItems)
{
li.Purchase_Order__c=order.id;
}
insert poLineItems;
//If the Opportunity Stage is not 'Closed Won' then update it
if (Opportunity.StageName != 'Closed Won'){
Opportunity.StageName='Closed Won';
update Opportunity;
}
}catch(System.DMLException e)
{
ApexPages.addMessages(e);
return null;
}

// After Save, navigate to the default view page:
return (new ApexPages.StandardController(order)).view();
}

public PageReference loadHelpPage(){
PageReference pg = new PageReference('/apex/CreatePOHelp');
return pg;
}


}

  • February 20, 2013
  • Like
  • 0

Please help.. i'm stuck on this. Can't figure out which is wrong with my coding. I received an error '

Error: Compile Error: expecting a semi-colon, found '(' at line 83 column 29 

Any help will be appreciated. Thanks

 

This is my code:

 

public class InvoiceController {

public class MissingAccountException extends Exception {}
public class NoLineItemsException extends Exception {}


public Account account {get; private set;}
public Opportunity opportunity {get; private set;}
public Invoice__c order {get; private set;}
public OpportunityLineItem oppLineItem {get; private set;}
public Invoice_Line_Item__c[] invoiceLineItems {get; private set;}
public Invoice_Line_Item__c invoiceLineItem {get; private set;}
public List<Invoice_Line_Item__c> lineItems= new List<Invoice_Line_Item__c>();
private integer itemCount=0;

private PriceBookEntry pbEntry;

public InvoiceController() {

Boolean ShowPartner=false;
Id id = ApexPages.currentPage().getParameters().get('id');
//Id accountId=ApexPages.currentPage().getParameters().get('aId');
Id opportunityId = ApexPages.currentPage().getParameters().get('oId');

opportunity = (opportunityId == null) ? new Opportunity() :
[SELECT name, accountID, CloseDate, Description, StageName, Pricebook2Id FROM Opportunity WHERE id = :opportunityId];

if (opportunity.AccountId != null){
account =new Account();
account= [SELECT name, accountnumber, billingstreet, BillingCity, BillingState, BillingPostalCode, BillingCountry,ShippingStreet, ShippingCity, ShippingState, ShippingPostalCode, ShippingCountry, phone, fax FROM account WHERE id = :opportunity.AccountId] ;
}else {
throw new MissingAccountException('Cannot create an invoice from this opportunity: Please assign an account to the opportunity.');
}

invoice = (id == null) ? new Invoice__c() :
[SELECT Invoice__c.Name FROM Invoice__c WHERE id = :id];

{

//Pre-populate Opportunity and account information
invoice.Name=Opportunity.Name;
invoice.AccountId__c=opportunity.AccountId;
invoice.OpportunityId__c = opportunity.id;
invoice.Status__c='New';

//Retrieve the PriceBook name for Prepopulation in order
string pbID = opportunity.Pricebook2Id;
PriceBook2 pb = (opportunity.Pricebook2Id == null) ? new PriceBook2() :
[Select Id, Name from Pricebook2 where Id=:pbID];
invoice.Pricebook__c=pb.Name;

//Create a new Invoice_Line_Item__c and populate a row for each oppLineItem that exists

integer i = 0;
Invoice_Line_Item = new Invoice_Line_Item__c[0];
for(OpportunityLineItem opp: [SELECT Id, SortOrder, PricebookEntryId, Description, Quantity, ListPrice, UnitPrice, TotalPrice, ServiceDate FROM OpportunityLineItem WHERE Opportunityid = :opportunityId])
{

string pbeID = opp.PricebookEntryId;
pbEntry = (pbeId == null) ? new PriceBookEntry() :
[Select Id, Name, Pricebook2Id, Product2Id, ProductCode from PricebookEntry where Id=:pbeID];


invoiceLineItem = new Invoice_Line_Item__c();
invoiceLineItem.Invoice__c=invoice.Id;
invoiceLineItem.Invoice__c = i+1;
invoiceLineItem.ProductId__c = pbEntry.Product2Id;
invoiceLineItem.Name = pbEntry.Name;
invoiceLineItem.Quantity__c = opp.Quantity;
invoiceLineItem.List_Price__c= opp.ListPrice;
invoiceLineItem.Sales_Price__c=opp.UnitPrice;
invoiceLineItem.Total_Price__c=opp.TotalPrice;
invoiceLineItem.add(Invoice_Line_Item);
i++;
}
itemCount=i;
if (itemCount == 0) {
throw new NoLineItemsException('Unable to create Invoice: Products must be added to the Opportunity before creating an Invoice.');
}
System.Debug('Finished Page Load');

}
public PageReference cancel() {
return (new ApexPages.StandardController(opportunity)).view();
}
//saves invoice and child invoices
public PageReference save() {
System.Debug('Running Save Method');

try
{
insert invoice;
System.Debug(invoice.id);
for(Invoice_Line_Item__c li: invoiceLineItems)
{
li.Invoice__c=invoice.id;
}
insert invoiceLineItems;
//If the Opportunity Stage is not 'Closed Won' then update it
if (Opportunity.StageName != 'Closed Won'){
Opportunity.StageName='Closed Won';
update Opportunity;
}
}catch(System.DMLException e)
{
ApexPages.addMessages(e);
return null;
}

// After Save, navigate to the default view page:
return (new ApexPages.StandardController(invoice)).view();
}

public PageReference loadHelpPage(){
PageReference pg = new PageReference('/apex/CreateInvoiceHelp');
return pg;
}


}

 

 

  • February 10, 2013
  • Like
  • 0

Hello - I am trying to add to my current apex trigger that automaticlly adds a line item to a custom object based on the product family.

 

I need to add in here that if the product quantity = 10 then we add 10 line items insted of one...

 

Any help would be appriciated

 

Trigger:

trigger trg_new_ResumeSubscription on Opportunity (after update)
{
   List<Opportunity> closedWonOpps=new List<Opportunity>();

   for (Opportunity opp : trigger.new)
   {
       Opportunity oldOpp=trigger.oldMap.get(opp.id);
       if ( (opp.StageName=='Closed Won') &&
            (oldOpp.StageName!='Closed Won') )
       {
          closedWonOpps.add(opp);
       }
   }
    
   if (!closedWonOpps.isEmpty())
   {
List<OpportunityLineItem> olis = [SELECT ID, OpportunityId, Subscription_Term1__c, UnitPrice, 
        Product_Name__c,Closed_Won_Date__c, Daily_View_Limit1__c, Views_Purchased1__c FROM OpportunityLineItem WHERE Product_Family__c = 'Resume Search' and
              OpportunityId in :closedWonOpps];

      List<Resume_Subscriptions__c> rsToInsert=new List<Resume_Subscriptions__c>();
      for (OpportunityLineItem oli : olis)
      {
 Resume_Subscriptions__c newRS= new Resume_Subscriptions__c();
         newRS.Views_Purchased3__c = oli.Views_Purchased1__c;
         newRS.Subscription_Term3__c = oli.Subscription_Term1__c;
         newRS.Price__c = oli.UnitPrice;
         newRS.Product_Name__c = oli.Product_Name__c ;
         newRS.Opportunity__c = oli.Opportunityid;
         newRS.Purchase_Date2__c = oli.Closed_Won_Date__c;
         newRS.Daily_View_Limit3__c = oli.Daily_View_Limit1__c;
              rsToInsert.add(newRS);
      }

      insert rsToInsert;
   }
}

 

I have to get all the orders printed in pdf format. Each order has some related order line items. i have used <apex:repeat value="{!order}" var="ord"> for the order loop. Now from the loop how can i get the related child Order_line record's values. I cannot use related list as it will give all values of the records, but i want some of its values.

 

Thanks in advance