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
SFManiSFMani 

Trigger for creating automatically creating an invoice when an opportunity is created with amount field filled.

I need help in creating a trigger which can automatically generate an invoice when an opportunity is created with the amount field filled.
Best Answer chosen by SFMani
yogesh_sharmayogesh_sharma
Here In is a reserve keyword. Please use another word here. And as per the salesforce best practise if you are using Object then use Obj prefix in object. objInvoice. Try this and tell me if it helps you. 

All Answers

Shashikant SharmaShashikant Sharma
You could start learning trigger development from 
http://www.sfdc99.com/beginner-tutorials/
http://forceschool.blogspot.in/search/label/Apex%20Triggers

If you face any issues let me know.

Thanks
Shashikant
yogesh_sharmayogesh_sharma
You can write before isnert trigger on Opportunity. And use amount field when you will generate an invoice from triiger.
SFManiSFMani

Hi Yogesh

I have created this trigger.Could you please check and let me know what is the error here. Please bear with me as I am new to triggers. Thanks.

trigger invoiceGenerate on Opportunity (before insert) {
   
List<Invoice1__c> invoiceList = new List<Invoice1__c>();

for(opportunity opp:trigger.new){
if(opp.Amount==0){

Invoice1__c in= new Invoice1__c(Name='TestInvoice'); 
invoiceList.add(in);
}
}

insert invoiceList;

}

yogesh_sharmayogesh_sharma
What error you are facing?Please elaborate your error. So it will be easy for me to provide you better solution.
SFManiSFMani

Invoice1__c in= new Invoice1__c(Name='TestInvoice'); 

in this line it says a semicolon expected but found in. I don't get why it is giving this error.

yogesh_sharmayogesh_sharma
Here In is a reserve keyword. Please use another word here. And as per the salesforce best practise if you are using Object then use Obj prefix in object. objInvoice. Try this and tell me if it helps you. 
This was selected as the best answer