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
Surendra123Surendra123 

Error in product trigger

Error: Compile Error: Entity 'Product' not accessible in version 29.0 at line 1 column 1  please help me thanks in advance

 

 

trigger updateNewvalues on product2 (before update) {


   for (Product2 prod: Trigger.new) {
               if(prod.Ampics_PL__c !=null &&  Product.Ampics_PL__c == 'Utilix') {
                
             String str = 'Utilix';
             String[] sstr = str.split('/');
              system.debug(sstr[0]);
              system.debug(sstr[1]);
           
              System.debug('--*Product Value is changed*--');
              
              System.debug('**Ampics_PL__c  :'+prod.sstr[0]);
              
       }
       
       else{
              prod.Pieces_in_Pack__c = '1';  
       }
   }
}

Best Answer chosen by Admin (Salesforce Developers) 
Deepa.B.AnkaliDeepa.B.Ankali
@Surendra123,

prod.Pieces_in_Pack__c = '1'; In this line,
update it to
prod.Pieces_in_Pack__c = 1;
Or
prod.Pieces_in_Pack__c = (Deicmal)1;
Or
prod.Pieces_in_Pack__c = Deicmal.valueOf(1);

All Answers

hitesh90hitesh90

Hi surendra,

 

You have to update your trigger code. in trigger try to use prod. instead of Product.

see below updated trigger code.

 

Apex Trigger:

trigger updateNewvalues on product2 (before update) {
    for (Product2 prod: Trigger.new) {
        if(prod.Ampics_PL__c !=null &&  prod.Ampics_PL__c == 'Utilix') {
            String str = 'Utilix';
            String[] sstr = str.split('/');
            system.debug(sstr[0]);
            system.debug(sstr[1]);    
            System.debug('--*Product Value is changed*--');    
            System.debug('**Ampics_PL__c  :'+prod.sstr[0]);    
        }else{
            prod.Pieces_in_Pack__c = '1';  
        }
    }
}

 

 

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
My Blog:- http://mrjavascript.blogspot.in/

Deepa.B.AnkaliDeepa.B.Ankali

@surendra123

 

In this line :

 if(prod.Ampics_PL__c !=null &&  Product.Ampics_PL__c == 'Utilix') {

 

Change Product.Ampics_PL__c to prod.Ampics_PL__c 

Surendra123Surendra123

Error: Compile Error: Invalid field sstr for SObject Product2 at line 9 column 46

Deepa.B.AnkaliDeepa.B.Ankali

@Surendra123,

 

System.debug('**Ampics_PL__c  :'+prod.sstr[0]);

 

Remove prod in this line. sstr is a string that you created in previous steps. its not product's field.

Surendra123Surendra123

Error: Compile Error: Illegal assignment from String to Decimal at line 11 column 13

 

trigger updateNewvalues on product2 (before update) {
    for (Product2 prod: Trigger.new) {
        if(prod.Ampics_PL__c !=null &&  prod.Ampics_PL__c == 'Utilix') {
            String str = 'Utilix';
            String[] sstr = str.split('/');
            system.debug(sstr[0]);
            system.debug(sstr[1]);    
            System.debug('--*Product Value is changed*--');    
            System.debug('**Ampics_PL__c  :'+sstr[0]);    
        }else{
            prod.Pieces_in_Pack__c = '1';  
        }
    }
}

Deepa.B.AnkaliDeepa.B.Ankali
@Surendra123,

What is the data type of Pieces_in_Pack__c field in product?
Surendra123Surendra123

Deepa,

 

 

Its number The datatype for Pieces_in_Pack__c is a number

Deepa.B.AnkaliDeepa.B.Ankali
@Surendra123,

prod.Pieces_in_Pack__c = '1'; In this line,
update it to
prod.Pieces_in_Pack__c = 1;
Or
prod.Pieces_in_Pack__c = (Deicmal)1;
Or
prod.Pieces_in_Pack__c = Deicmal.valueOf(1);
This was selected as the best answer
Surendra123Surendra123

if i give any value in the product description such as Management/123

 

i need to update /123 in the Pieces_in_Pack__c = '1';

Surendra123Surendra123

Deepa,

 

 

if there is any value in the product description as mananagement/2345  we need to place the 2345 in the piece of packs if there is no value it must default to 1

Deepa.B.AnkaliDeepa.B.Ankali
@Surendra123,

You can check for numeric in the string and parse accordingly. If it contains blank value then assign '1' to it.