You need to sign in to do that
Don't have an account?
PageReference Error
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;
}
}
You need 2 braces after System.Debug("Finished Page Load"); statement and you only have one.
Add the extra brace and code will compile
System.Debug('Finished Page Load');
}
}
thanks a lot man it works...