function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Hugo_BHugo_B 

Assigning a variable from a called method in another class

I have 2 classes containing various methods.

In the first class I want to call the class "addInvoice()"

The addInvoice class should return the invoiceID

I would like to take the returned invoiceID and assign it to a variable to be used elsewhere in the class

Here is the call in the first class:
 
InvoiceAdd invoice = new InvoiceAdd();
           String invID = invoice.invID;

This is the method in the second class
Public String InvoiceAdd(String projID, String oppID) {
    system.debug('1');
    Invoice__c inv = new Invoice__c(Project__c = projid);
       system.debug('2');
        insert inv;
        String invID = inv.id;
        system.debug('3');
        system.debug('oppID ' + oppID);
        system.debug('invID ' + invID);
 return invID;
}
 
I just keep getting errors such as:  Error: Compile Error: Invalid type: InvoiceAdd at line 65 column 38

Any help?
 
Best Answer chosen by Hugo_B
Sergio Mac-IntoshSergio Mac-Intosh
Try to call it like this:

String invID = new InvoiceAdd( Variable 1, Variable 2);
 

All Answers

Himanshu ParasharHimanshu Parashar
Hi,

It will be great if you can post your whole code because it is not clear where is line 65 in your current code and they way you are defining and calling is not correct.

Thanks,
Himanshu
Sergio Mac-IntoshSergio Mac-Intosh
Try to call it like this:

String invID = new InvoiceAdd( Variable 1, Variable 2);
 
This was selected as the best answer
Hugo_BHugo_B
Thanks everyone.  Looks like I may have overcomplicated this but it's working.