Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- Error: Compile Error: Illegal assignment from SOBJ...
turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
0
Error: Compile Error: Illegal assignment from SOBJECT:Cu stomer_Pro duct__c to Id at line 11 column 9
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
08-02-2010 08:25 AM
I am writing a test class and am running into this error:
Error: Compile Error: Illegal assignment from SOBJECT:Customer_Product__c to Id at line 11 column 9
Here is my test class:
@isTest
private class BulkDensityTest{
testmethod private static void TestTrigger() {
Customer_Product__c cp = new Customer_Product__c
(name = 'apple');
insert cp;
Customer_Bulk_Density__c c = new Customer_Bulk_Density__c ();
c.Name = '4';
c.Metric_Label__c = 'kg/m3';
c.Customer_Product__c = cp;
insert c;
System.debug('c:' + c);
c = [SELECT ID, Name FROM Customer_Bulk_Density__c WHERE id = :c.id];
System.debug('c:' + c);
System.assertEquals(c.Customer_Product__c, c.Name);
Profile p = [select id from profile where name='Standard User'];
User u = new User(alias = 'standt', email='standarduser@testorg.com',
emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
localesidkey='en_US', profileid = p.Id,
timezonesidkey='America/Los_Angeles', username='standarduser@testorg.com');
System.runAs(u) {
// The following code runs as user 'u'
System.debug('Current User: ' + UserInfo.getUserName());
System.debug('Current Profile: ' + UserInfo.getProfileId()); }
}
}
Here is the trigger:
trigger BulkDensityConversion on Customer_Bulk_Density__c (before insert) {
Set<Id> bIds = new Set<Id>();
list<Customer_Bulk_Density__c> customerBulkDensityList = new List<Customer_Bulk_Density__c>();
if(StaticClass.doNotExecute ==true)
{
system.debug('Inserting'+StaticClass.doNotExecute) ;
for(Customer_Bulk_Density__c c:trigger.new)
{
bIds.add(c.id);
if(c.Metric_Label__c =='Lbs./ft3')
{
Double conversion = Double.valueof(c.Name) * 16.018;
Long L1 = conversion.round();
Customer_Bulk_Density__c s = new Customer_Bulk_Density__c(
Metric_Label__c = 'Kg/m3',
Name = String.Valueof(L1) + String.ValueOf(' ') + String.Valueof('Kg/m3'),
Customer_Product__c=c.Customer_Product__c,
Customer_Product_2__c=c.Customer_Product_2__c,
Customer_Product_3__c=c.Customer_Product_3__c
);
customerBulkDensityList.add(s);
}
else
{
Double conversion1 = Double.valueof(c.Name) * 1 / 16.018;
Long L2 = conversion1.round();
Customer_Bulk_Density__c s = new Customer_Bulk_Density__c(
Metric_Label__c = 'Lbs/ft3',
Name = String.Valueof(L2) + String.ValueOf(' ') + String.Valueof('Lbs./ft3'),
Customer_Product__c=c.Customer_Product__c,
Customer_Product_2__c=c.Customer_Product_2__c,
Customer_Product_3__c=c.Customer_Product_3__c
);
customerBulkDensityList.add(s);
}
}
StaticClass.doNotExecute =false;
if(!customerBulkDensityList.isEmpty())
{
insert customerBulkDensityList;
}
System.debug('****1 : B Id size '+ bIds.size());
}
else
{
StaticClass.doNotExecute =true;
}
}
How to I solve the error?
Thank you again
Solved! Go to Solution.
0
Re: Error: Compile Error: Illegal assignment from SOBJECT:Cu stomer_Pro duct__c to Id at line 11 colum
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
08-02-2010 08:59 AM
c.Customer_Product__c = cp; is the issue.
You are trying to set an Id (the c.Customer_Product__c field) to a full sObject (cp).
Try
c.Customer_Product__c = cp.Id;

