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
Salesforce Admin 110Salesforce Admin 110 

code error

problem with code
i need to refactor this code:
error = Initial term of field expression must be a concrete SObject: List<pba__Listing__c&gt line 31
public without sharing class copylistingpricetproperty {

    public static void resisales(List<pba__Property__c> propertyIds){
        Id recId = Schema.SObjectType.pba__Property__c.getRecordTypeInfosByName().get('Residential Sales').getRecordTypeId();
        
        

   /*    list<pba__Property__c> properties = [select id, name, published__C from pba__Property__c where id in :propertyIds and published__c = true];
                set<id> propertiesset = new set<id>();
        
       
        for(pba__Property__c prop : properties) 
            
                propertiesset.add(prop.Id);    */  

     
        list<pba__Listing__c> listings = [select id, pba__ListingPrice_pb__c,pba__Status__c,pba__Property__c,  recordtypeid, name from pba__Listing__c where /* id in :propertiesset  and */	recordtypeid = :recId and pba__Status__c = 'Approved']; 
        
        set<id>listset = new set<id>();
        for(pba__Listing__c lists : listings)
            listset.add(lists.pba__Property__c);
        
          
      
        List<pba__Property__c> propstoUpdate = new List<pba__Property__c>(); 
        
     for(pba__Property__c propp : propertyIds)
         if( listset.contains(propp.id)) 
      
     
         listings.pba__ListingPrice_pb__c = propp.Asking_price__c;
         
     
        update propsToUpdate;
        
    
        
        
        
  
        
        
    }
  
}

 
Mahesh DMahesh D
Hi,

Please do let me know if it works, I implemented it based on my understanding.
 
public without sharing class copylistingpricetproperty {

    public static void resisales(List<pba__Property__c> propertyIds){
		
		Id recId = Schema.SObjectType.pba__Property__c.getRecordTypeInfosByName().get('Residential Sales').getRecordTypeId();
        
        List<pba__Property__c> properties = [select id, name, published__C from pba__Property__c where id in :propertyIds and published__c = true];
        Set<id> propertiesSet = new Set<id>();
        
        if(!properties.isEmpty() {
			for(pba__Property__c prop : properties) {
				propertiesSet.add(prop.Id);  
			}
		 
			list<pba__Listing__c> listings = [select id, pba__ListingPrice_pb__c, pba__Status__c, pba__Property__c,  recordtypeid, name from pba__Listing__c where recordtypeid = :recId and pba__Status__c = 'Approved']; 
			
			Map<Id, pba__Listing__c> listPropMap = new Map<Id, pba__Listing__c>();
			
			for(pba__Listing__c lists : listings) {
				listPropMap.put(lists.pba__Property__c, lists);
			} 
			
			for(pba__Property__c prop : properties) {
				if(listPropMap.get(prop.Id) != null) {
					prop.Asking_price__c = listPropMap.get(prop.Id).pba__ListingPrice_pb__c;
				}
			}
			
			update properties;
		}
    }
}

Also if possible paste your full requirement if it doesn't work.

Please do let me know if it helps you.


Regards,
Mahesh