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
Beth WalterBeth Walter 

Apex code errors

I am trying to create a visual force page, so I can create a custom button that allows me to create a quote right after saving an opportunity. I placed the code in a visual force page. When I try to save it, it gives me an error message. See everything below. How do I fix the error? 


Error: Create_Quote line 55, column 13: The element type "quote" must be terminated by the matching end-tag "</quote>"
Error: The element type "quote" must be terminated by the matching end-tag "</quote>".

<apex:page>
  
trigger QuoteCreate on Opportunity (after insert) {

     
        List<Id> oppIdsList = new List<Id>();

        List<Quote> quoteList = new List<Quote>();

          
         for (Opportunity o : Trigger.new) {

        if(o.FME_AMC_Renewal__c == True)

         
        oppIdsList.add(o.id);

}
        Opportunity[] oppList = [SELECT name, id, account.billingStreet, account.billingCity,

                                    account.billingState, account.billingCountry

                                FROM Opportunity

                                WHERE id IN :oppIdsList];

        for (Opportunity o : oppList) {

        Quote q = new Quote();

        q.name = o.name;

        q.opportunityId = o.id;

        q.billingStreet = o.account.billingStreet;

        q.billingCity = o.account.billingCity;

        q.billingState = o.account.billingState;

        q.billingCountry = o.account.billingCountry;

    quoteList.add(q);

    }

    insert quoteList;

}

</apex:page>
SabrentSabrent
Hello Beth 

There is a fundamental problem in your understanding about visualforce pages and triggers. 
Visualforce page is a user interface i.e the view of the record detail page or view of the record edit page  
Trigger is a code that runs when an event happens.
E.g when a new opportunity is created, create a new quote
When you hit the 'Save' button to create a new opportunity record, an event occurs. 
After Saving the opportunity, the process of automatically creating a new quote record is handled by the code in the trigger. 

In the Use Case you have described, you don't need a button, neither do you need a visualforce page. 
All you need is a trigger, which you have.

I am assuming the trigger 'QuoteCreate ' exists in your org. 
If not, open Developer Console, then go to File , then cllick New then Click Apex Trigger. Copy and paste your trigger in the editor. Click Save

That's it.  Everytime you create a new opportunity record, without pressing any button a Quote record will be created. Quote exists as a related list on the Opportunity record detail page. 

To test , Click the opportunity tab, Click New, click Save. 
Go to Quotes, and you should see a new record on Quotes. 

Let me know if you need further help. 
v varaprasadv varaprasad
Hello Beth,

We cannot write classes in Visualforce pages.
UI = Visualforce pages
Backend = apexclasses
Automotain = Triggers

Hope this helps you!


Thanks
Varaprasad
@For Salesforce Project Support: varaprasad4sfdc@gmail.com


Salesforce latest interview questions  :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1
Beth WalterBeth Walter
I am new to this developing stuff, so I don't know why this is wrong. I tried just inserting the trigger in Sandbox, but I keep getting this error. 

Compile Error: Variable does not exist: FME_AMC_Renewal__c at line 14 column 14

What does it mean? Please help.
SabrentSabrent
FME_AMC_Renewal__c  is a custom field. 
Check if that field exists on the Opportunity object in your org.