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
Filipe BaradelliFilipe Baradelli 

Error: Erro de compilação: unexpected token: '='

This code gives me the error : unecpected token '='. It is about the fisrt  '='.
I don't know why this.

Can some one help me?:
 
Product2 pr = new Product2();
    pr.Name = 'PRODUTO TESTE';
    pr.isActive=true;
    insert pr;
    
    PriceBook2 customPriceBook = new PriceBook2();
    customPriceBook.Name='Custom Pricebook';
    customPriceBook.IsActive=true;
    insert customPriceBook;    

    Pricebook2 customPriceBookRec=[select Id from Pricebook2 where id=:customPriceBook.Id];
    Id stdPriceBookRecId = Test.getStandardPricebookId();
    
    PriceBookEntry customPriceBookEntry = new PriceBookEntry();
    customPriceBookEntry.Product2Id=pr.Id;
    customPriceBookEntry.Pricebook2Id=customPriceBookRec.Id;
    customPriceBookEntry.UnitPrice=1000;
    customPriceBookEntry.IsActive=true;
    insert customPriceBookEntry;
    
    Opportunity opp = new Opportunity();
    opp.Name = 'Test';
    opp.CloseDate= System.Today();
    opp.StageName='Prospecting';
    insert opp;
    
    OpportunityLineItem oppLineItem = new OpportunityLineItem();
    oppLineItem.OpportunityId = opp.Id;
    oppLineItem.PricebookEntryId = customPriceBookEntry.Id;
    oppLineItem.UnitPrice =1000;
    oppLineItem.Quantity =1;
    insert oppLineItem;

 
Amit Chaudhary 8Amit Chaudhary 8
PLease update your code like below
Product2 pr = new Product2();
    pr.Name = 'PRODUTO TESTE';
    pr.isActive=true;
    insert pr;
    
    PriceBook2 customPriceBook = new PriceBook2();
    customPriceBook.Name='Custom Pricebook';
    customPriceBook.IsActive=true;
    insert customPriceBook;    

    //Pricebook2 customPriceBookRec = [select Id from Pricebook2 where id = :customPriceBook.Id] ;
    //Id stdPriceBookRecId = Test.getStandardPricebookId();
    
    PriceBookEntry customPriceBookEntry = new PriceBookEntry();
    customPriceBookEntry.Product2Id=pr.Id;
    customPriceBookEntry.Pricebook2Id=customPriceBookRec.Id;
    customPriceBookEntry.UnitPrice=1000;
    customPriceBookEntry.IsActive=true;
    insert customPriceBookEntry;
    
    Opportunity opp = new Opportunity();
    opp.Name = 'Test';
    opp.CloseDate= System.Today();
    opp.StageName='Prospecting';
    insert opp;
    
    OpportunityLineItem oppLineItem = new OpportunityLineItem();
    oppLineItem.OpportunityId = opp.Id;
    oppLineItem.PricebookEntryId = customPriceBookEntry.Id;
    oppLineItem.UnitPrice =1000;
    oppLineItem.Quantity =1;
    insert oppLineItem;

let us know if this will work
Filipe BaradelliFilipe Baradelli
Now the error is from the line where is the sentence :  pr.Name = 'PRODUTO TESTE';
And is the same error, about the '=' .