You need to sign in to do that
Don't have an account?
Samantha 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');
}
}
}
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');
}
}
}
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:
If you can give the elobarated requirement, i can modify / help you in completing your code!
Thanks,
Balaji
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'
);
}
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
:)
Apex Class:
Button Code:
Let me know if you encounter any issue.,
Mark it as solved! If it solved your issue :)
Cheers,
Thanks,
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
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;