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
Samantha StarlingSamantha Starling 

Expression cannot be assigned

I am getting a save error that my expression cannot be assigned. I've read every post related to the error and am unable to figure out how to fix my code. One post said I couldn't use an autonumber (which one of the fields I was using was) so I changed the field type to just number. What I need this to do is, once the two Oppty Number fields match, the fields from the custom object Production Details will send over to the fields on the Opportunity Product.

Any suggestions??

global class PlayerConversion{
    webService
static String copyPlayerDetails(Id ProductionDetailId){
        List<Production_Detail__c> lstProductionDetail =
            [
                SELECT 
                    Id, 
                    Shipping_Costs__c,
                    Act_Postage_Total__c,
                    Per_Piece_Cost__c 
                  
                    
                FROM 
                    Production_Detail__c 
                WHERE 
                    Id = :ProductionDetailId
            ];

       List <OpportunityLineItem> lstOpportunityLineItem = new List<OpportunityLineItem>();

    if(OpportunityLineItem.Opportunity_Product_Number__c == Production_Detail__c.Opportunity_Product__c){
for(Production_Detail__c player : lstProductionDetail){

              
                    lstOpportunityLineItem.add(
                        new OpportunityLineItem()
                            );
                           OpportunityLineItem.Shipping_Costs__c=Production_Detail__c.Shipping_Costs__c;
                           OpportunityLineItem.Postage_Cost__c=Production_Detail__c.Act_Postage_Total__c;
                           OpportunityLineItem.Per_Piece_Cost__c=Production_Detail__c.Per_Piece_Cost__c
                       
                        ;
}
               }     
      try{   
            INSERT lstOpportunityLineItem;
            return lstOpportunityLineItem[0].Id; 
        }
        catch (Exception ex){
            
            return('Error');
        }     
}
}     
 
Balaji Chowdary GarapatiBalaji Chowdary Garapati
@samantha:

The If loop from above code:

 if(OpportunityLineItem.Opportunity_Product_Number__c == Production_Detail__c.Opportunity_Product__c)

OpportunityLineItem,Production_Detail__c you were refering to in the above statement doesnt look like varaible names, they were object api names! For comparision between values, you need to use instances for those objects not object api names directly.

For eg.,

Account is object Api name, where

Account acc=new Account(); // acc is varaible/intanse of object account which can hold values for each property(field) that belongs to Account object.


Hope it helps,


Thanks,
balaji
Samantha StarlingSamantha Starling
Thanks for the reply, Balaji, but I'm afraid I am so new to using any kind of Apex that none of this helps. I am using code from this (http://www.saaspie.com/2014/11/03/copying-data-from-one-object-with-a-button-click-in-salesforce/) to create a button and class that I need substituting my objects for the ones here. When I was adding my IF statement that if the values in those two fields on the objects matched the field weren't recognized until I added the object in front. I have been researching since I received your reply and see that I should use oli for Opportunity Line Item but have no idea about how to prepare for Production Details, which is a custom object. With all that said, thanks again, but I'm not sure how to proceed with the info you gave me. Also,  I ran the debug I got an error that global type must be contained in a global class so I am off to research that as well... much to learn!! :)
Balaji Chowdary GarapatiBalaji Chowdary Garapati

@Samantha:

  If you can give the elobarated requirement, i can modify / help you in completing your code!


Thanks,
Balaji
Samantha StarlingSamantha Starling

Oh my gosh...that would be awesome!! 

We have a custom object called Production Details. A Production Detail is created after an Opportunity Product is created. When the Opportunity Product is created, it is assigned a number by the user (oli.OpportunityProductNumber). That number is sent to production to be used when creating the Production Detail. Once the Production Detail is created and the Opportunity Product Number field is populated on that object with the matching number from the Oppty Prod and saved, I need the data in the shipping, postage and per piece cost fields to be sent to the same fields on the Oppty Product via clicking the "Send to Oppty Prod" button. The code for that button is below but it all seems to be working ok.

BUTTON:
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/31.0/apex.js")} 
//Calling Class and Method 
var result = sforce.apex.execute( 
"ProductionDetailConversion", 
"copyProductionDetail", 

ProductionDetailId : "{!Production_Detail__c.Id}" 

); 
if(result=="Error") 

window.alert("Copy Failed! Error has occurred"); 



else 

window.alert( 
'The Production Detail fields have been successfully copied to the Opportunity Product' 
); 

}

Balaji Chowdary GarapatiBalaji Chowdary Garapati
Few questions:
 
Is there any direct relationship between Opportunity Line Item and Product Detail except the Opportunity Product Number?
Is OpportunityProductNumber Unique among Opportunity Line Item as well as Product detail records?
In the code you pasted in the begining, you are trying to insert OpportunityLineItem is it what you are looking for which contradicts the requriement ! I think you need to update instead of inserting! Am i correct?

In the button you were trying to call a class called ProductionDetailConversion and method in it named copyProductionDetail where as the class and the method you pasted in the actual post were different( PlayerConversion and copyPlayerDetails).

Please confirm!

Thanks,
Balaji
Balaji Chowdary GarapatiBalaji Chowdary Garapati
You used the term Opportunity Product multiple time in the requirement you given, I assumed it as OpportunityLineItem Object! Is it correct? 

:)
Samantha StarlingSamantha Starling
They are both have master detail relationships with Opportunity and I've created lookups on each to the other. Opportunity Product # is unique to each oli and the related Production Detail will have that same number so we have something to match by. And yes, update not insert :) I also saw that I had missed updating Player conversion to Production Detail Conversion. The reference to "player" was from the code I copied. And yes...Oppty Prod = oli : That's what we call it in the user/admin world...LOL 
Balaji Chowdary GarapatiBalaji Chowdary Garapati
:) Okay try these:


Apex Class:
 
Global Class ProductionDetailConversion{
	//Assuming that shippingcost,perpiececost and acttotalcost as number or currency fields
    //Added Debug logs every where so, if it is failing you can add a debug log and see where exactly it is failing
	webService static String copyPlayerDetails(String OppProdNumber,Decimal ShippingCost,Decimal PerPieceCost,Decimal ActTotalCost ){
		
		try{
        System.debug('Passed Parameters**'+OppProdNumber+'**'+ShippingCost+'**'+ActTotalCost+'**'+PerPieceCost);

			//Query the opportunity line item that needs to be update based on opp prod number that we pass from the button code
			OpportunityLineItem OppLineItem=[select id,Shipping_Costs__c,
												Act_Postage_Total__c,
												Per_Piece_Cost__c 
												From OpportunityLineItem 
												Where Opportunity_Product_Number__c=:OppProdNumber limit 1]
			System.debug('Opportunity Line Item Found ****'+OppLineItem);
           //Assign Values We received From Product Detail
			OppLineItem.Shipping_Costs__c=ShippingCost;
			OppLineItem.Act_Postage_Total__c=ActTotalCost;
			OppLineItem.Per_Piece_Cost__c=PerPieceCost;
			
			Update OppLineItem;
			
			return 'Success';//Returning Success Upon successful update 
		
	    }catch(Exception e){
			system.debug('Error Due To ****'+e.getMessage());
			return 'Error';
		}
	
	}
}

Button Code:
 
BUTTON:
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/31.0/apex.js")} 
//Calling Class and Method : Passing All the parameters necessary in order to save a query in the actual class :)
var result = sforce.apex.execute("ProductionDetailConversion","copyProductionDetail", 
{
 OppProdNumber : "{!Production_Detail__c.Opportunity_Product__c}",
 ShippingCost: "{!Production_Detail__c.Shipping_Costs__c}",
 PerPieceCost: "{!Production_Detail__c.Per_Piece_Cost__c}",
 ActTotalCost: "{!Production_Detail__c.Act_Postage_Total__c}"
} 
); 
if(result=="Error") { 
alert("Copy Failed! Error has occurred"); 

} else { 
alert( 'The Production Detail fields have been successfully copied to the Opportunity Product' ); 

}


Let me know if you encounter any issue.,

Mark it as solved! If it solved your issue :)


Cheers,

Thanks,
Balaji
Samantha StarlingSamantha Starling
Good morning, Balaji!

I did get compile errors and have listed them below as I went through and udpated per the error message.I couldn't get past line 34, however.

OpportunityLineItem OppLineItem=[select id,Shipping_Costs__c,
**Error    Error: Compile Error: expecting a semi-colon, found 'OppLineItem' at line 15 column 32**
        OpportunityLineItem ;=[select id,Shipping_Costs__c,
**Error    Error: Compile Error: expecting right curly bracket, found '=' at line 15 column 33**    
         OpportunityLineItem ;}[select id,Shipping_Costs__c THIS IS WHAT I ENDED UP WITH THAT GAVE ME NO ERRORS

  }catch(Exception e){
**Error    Error: Compile Error: expecting right curly bracket, found 'catch' at line 34 column 9**
        }(Exception e){
**Error    Error: Compile Error: expecting right curly bracket, found '(' at line 33 column 9**    
    }(Exception e{
**Error    Error: Compile Error: expecting right curly bracket, found '(' at line 33 column 9**
    }Exception e{ THIS IS WHAT I ENDED UP WITH THAT GAVE ME NO ERRORS

    system.debug('Error Due To ****'+e.getMessage());
**Error    Error: Compile Error: unexpected token: 'system.debug' at line 34 column 12**    
        ('Error Due To ****'+e.getMessage());
**Error    Error: Compile Error: unexpected token: '(' at line 34 column 12**
        'Error Due To ****'+e.getMessage());
**Error    Error: Compile Error: unexpected token: 'Error Due To ****' at line 34 column 8**
I COULD NOT MAKE ENOUGH CORRECTIONS TO GET PAST THIS LINE
 
Samantha StarlingSamantha Starling
Also, while I was reading the code leanring what does what (thank you for those notes!!), I noticed a couple corrections to field and object names. I had missed updating "Player" to 'Production" and the field on the oli that will hold the Actual Postage Cost from the ProdDet is Postage_Cost__c (with the "Actual"). 

Global Class ProductionDetailConversion{
    webService static String copyProductionDetails(String OppProdNumber,Decimal ShippingCost,Decimal PerPieceCost,Decimal ActTotalCost ){
        
        try{
        System.debug('Passed Parameters**'+OppProdNumber+'**'+ShippingCost+'**'+ActTotalCost+'**'+PerPieceCost);
OpportunityLineItem OppLineItem=[select id,Shipping_Costs__c,
                    Postage_Cost__c,
                    Per_Piece_Cost__c 
                    From OpportunityLineItem 
            Where Opportunity_Product_Number__c=:OppProdNumber limit 1]

            System.debug('Opportunity Line Item Found ****'+OppLineItem);

            OppLineItem.Shipping_Costs__c=ShippingCost;
            OppLineItem.Postage_Cost__c=ActTotalCost;
            OppLineItem.Per_Piece_Cost__c=PerPieceCost;
Samantha StarlingSamantha Starling
*(WITHOUT the "Actual")...