+ Start a Discussion
lawlaw 

Initial term of field expression must be a concrete SObject: LIST<Product_Detail__c> at line 274

Hello Everyone

 

Any help would be greatly appreciated

 

Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST<Product_Detail__c> at line 274 column 24

 

  public string SelectedAccountId { get; set; }
     public void DeleteDetail()
   {
    // if for any reason we are missing the reference
      if (SelectedAccountId == null) {     
         return;
      }
    
      // find the detail record within the collection
      Product_Detail__c tobeDeleted = null;
     
      for(List<Product_Detail__c> a : products.values())
     // for(Product_Detail__c a : products)
       if (a.name = SelectedAccountId) {
         tobeDeleted = a.name;    <<<<<<Line 274
          break;         
        }     
      //if account record found delete it
      if (tobeDeleted != null) {
       Delete tobeDeleted;
      }
    
      //refresh the data
      //LoadData();
   }   

Best Answer chosen by Admin (Salesforce Developers) 
tomcollinstomcollins

Your current error is because you be comparing a.name to SelectedAccountId.

 

And why aren't you just using SOQL to find products where name = SelectedAccountId and then delete the matching records?

 

You're using a lot of Apex code to do something easily handled by SOQL.

 

Product_Detail__c toBeDeleted = [SELECT Id FROM Products WHERE Name = :SelectedAccountId LIMIT 1];
if (toBeDeleted != null) delete toBeDeleted;

I hope this helps.

All Answers

Rakesh Aggarwal.ax1406Rakesh Aggarwal.ax1406

Can you try changeing your for loop as:

 

  for(Product_Detail__c a : products.values())
     / if (a.name = SelectedAccountId) {
         tobeDeleted = a.name;  
          break;         
        }     

 

Let me know if this works.

 

Thanks

Rakesh Aggarwal

lawlaw

Now I receive the following error

 

Error: Compile Error: Illegal assignment from String to SOBJECT:Product_Detail__c at line 275 column 10

Rakesh Aggarwal.ax1406Rakesh Aggarwal.ax1406

Can you post your complete code? Basically I need to see what your products map hold. products.values() should return list of Product_Detail__c records

Rajesh SriramuluRajesh Sriramulu

Hi

 

Replace this code:

 

if (a[0].name = SelectedAccountId)
         tobeDeleted = a[0].name;   
          break;       

 

Regards,
Rajesh.

sivaextsivaext

hi

 

  for(List<Product_Detail__c> a : products.values())
     // for(Product_Detail__c a : products)
       if (a.name = SelectedAccountId) {
         tobeDeleted = a.name;    <<<<<<Line 274
          break;         
        }     

 

List<Product_Detail__c> this is a list of product details values.

here is "a" is list not single record.

you want first record "a[0].name" in place of a.name

 

try this

List<Product_Detail__c> a=products.values();

for(product_Detail__c  an:a)

{

if (a.name = SelectedAccountId) {
         tobeDeleted = a.name;    
          break;         
        }     

   

}


Jerun JoseJerun Jose

Okay, I dont know what the others have been saying.

 

You cant do this.

  tobeDeleted = a.name;

The reason is because, you are trying to assign a field value (a.Name) to a complete record.

 

tobeDeleted is the variable for a complete Product_Detail__c record. You cant assign one fields value to a complete record. What you can do is to tell which field of tobeDeleted you want to assign to, or to tell to assign the complete record info.

 

So.

tobeDeleted.name = a.name;

will be valid

and

tobeDeleted = a;

will be valid

 

But. I see that 'a' does not also point to a single record.

If you had done

for(Product_Detail__c a : products)

then 'a' would point a single product_detail__c record and so you can do a.Name

 

since you did

for(List<Product_Detail__c> a : products.values())

'a' now points a list of records, so you would need to pick one record of the list before you can dereference it to get the name info.

so something like using a[0].name would work in this case.

 

Thats not all;

you have declared tobeDeleted= null.

you cannot dereference a null object.

Meaning, you cannot assign the values for something which is null, so when you try to do

tobeDeleted.name = a.name;

you will get a runtime exception because you are trying to assign the name field value for something which does not exist (something which is null)

 

to get this resolved, you need to set the tobedeleted variable to point something proper, like creating a new record and making tobedeleted point to that, 

Product_Detail__c tobedeleted= new Product_Detail__c();

Still not done.

 

when you try to do

Delete tobeDeleted;

 

The system will complain about ID not specified in a delete call.

This is because, you are telling the system to delete a record, but the record does not have an ID on it for the system to find and delete.

 

For this, you will need to have tobedeleted point to some existing record, like

tobedeleted = a; or tobedeleted= a[0], whichever is applicable.

 

lawlaw

Hello 

 

I attempted to implement your suggestions however I am still receiving this error:

Error: Compile Error: Illegal assignment from String to SOBJECT:Product_Detail__c at line 276 column 12.  All other suggestions above produced errors also.

 

public string SelectedAccountId { get; set; }
public void DeleteDetail()
{
// if for any reason we are missing the reference
if (SelectedAccountId == null) {
return;
}

// find the detail record within the collection
//Product_Detail__c tobeDeleted = null;
Product_Detail__c tobedeleted= new Product_Detail__c();
// for(List<Product_Detail__c> a : products.values()){
for(Product_Detail__c a : products)

{
if (a = SelectedAccountId){    <<<<<LINE 276
tobeDeleted = a;
break;
}
//if account record found delete it
}if (tobeDeleted != null) {
Delete tobeDeleted;
}

//refresh the data
//LoadData();
}


tomcollinstomcollins

Your current error is because you be comparing a.name to SelectedAccountId.

 

And why aren't you just using SOQL to find products where name = SelectedAccountId and then delete the matching records?

 

You're using a lot of Apex code to do something easily handled by SOQL.

 

Product_Detail__c toBeDeleted = [SELECT Id FROM Products WHERE Name = :SelectedAccountId LIMIT 1];
if (toBeDeleted != null) delete toBeDeleted;

I hope this helps.

This was selected as the best answer
lawlaw

Thanks !  Any  suggestions on how to refresh the custom VF Page after the delete?

 

Final Code:

public string SelectedAccountId { get; set; }
public void DeleteDetail()
{
if (SelectedAccountId == null) {
return;
}
Product_Detail__c toBeDeleted = [SELECT name FROM Product_Detail__c WHERE Name = :SelectedAccountId LIMIT 1];
if (toBeDeleted != null) delete toBeDeleted;

s shekars shekar
i am getting the same error can anyone help me

trigger accountduplicatetrigger on Account (before insert,before update) {
for(account a:trigger.new){
  list<Account>acc= [select id,from account where  name=:a.name=:a.rating rating  from account];
if(acc.size()>0){
acc.name.adderror('you cant create duplicate account');
}
}
}
sai sandeep chilakapatisai sandeep chilakapati
Hi s shekar,
Replace this code:
trigger AccountDuplicateTrigger on Account (before insert, before update)

{
for(Account a:Trigger.new)
{
List<Account> acc=[Select id,Name from Account where Name=:a.Name and Rating=:a.Rating];
if(acc.size()>0)
{
a.addError('You Cannot Create the Duplicate Account with same Name');
}
}
}
sai sandeep chilakapatisai sandeep chilakapati
Hi s shekar,
Replace this code:
a.Name.addError('You Cannot Create the Duplicate Account with same Name');
Simha YadavSimha Yadav
wrong code it is not bulkfied