• Laquita Scholz
  • NEWBIE
  • 0 Points
  • Member since 2023

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
i want to upload a csv using vf page that would contain parent accounts with corresponding child accounts, and i want to merge them using batch instead of doing this manually but i am getting error " List has more than 1 row for assignment to SObject on line: 35" on my batch, 
my vf page is 
<apex:page controller="MergeChildAccountsController">
    <apex:form enctype="multipart/form-data">
        <apex:inputFile value="{!csvFile}" />
        <apex:commandButton action="{!processCsv}" value="Process CSV" />
    </apex:form>
</apex:page>
============================================
my controler is 
public class MergeChildAccountsController {
    public Blob csvFile { get; set; }
    
    public void processCsv() {
        String[] filelines = csvFile.toString().split('\n');
        List<Account> childAccounts = new List<Account>();
        Map<String, String> parentMap = new Map<String, String>();
        
        for (Integer i = 1; i < filelines.size(); i++) {
            String[] fields = filelines[i].split(',');
            String accountName = fields[0].trim();
            String parentName = fields[1].trim();
            
            Account child = new Account(Name = accountName);
            childAccounts.add(child);
            parentMap.put(accountName, parentName);
        }
        
        Database.executeBatch(new MergeChildAccountsBatch(childAccounts, parentMap));
    }
}
====================================

my batch is 
public class MergeChildAccountsBatch implements Database.Batchable<Account> {
    List<Account> childAccounts;
    Map<String, String> parentMap;
    
    public MergeChildAccountsBatch(List<Account> childAccounts, Map<String, String> parentMap) {
        this.childAccounts = childAccounts;
        this.parentMap = parentMap;
    }
    
    public Iterable<Account> start(Database.BatchableContext bc) {
        return [SELECT Id, Name, ParentId FROM Account WHERE Name IN :parentMap.keySet() OR Id IN :childAccounts];
    }
    
    public void execute(Database.BatchableContext bc, List<Account> parentAccounts) {
        try {
            Map<String, Account> nameToAccountMap = new Map<String, Account>();
            
            for (Account account : parentAccounts) {
                nameToAccountMap.put(account.Name, account);
            }
            
            Set<Account> accountsToMerge = new Set<Account>();
            for (Account child : childAccounts) {
                String parentName = parentMap.get(child.Name);
                if (parentName != null) {
                    List<Account> parentList = [SELECT Id, Name, ParentId FROM Account WHERE Name = :parentName];
                    accountsToMerge.addAll(parentList);
                }
            }
            
            Database.MergeResult[] mergeResults = Database.merge(nameToAccountMap.values(), new List<Account>(accountsToMerge), false);
           system.debug('mergeResults' +mergeResults);
            
            
           /* for (Database.MergeResult result : mergeResults) {
                if (result.isSuccess()) {
                    // do something with the merged account
                } else {
                    // handle the merge failure
                }
            } */
        } catch (Exception e) {
            System.debug('Error: ' + e.getMessage() + ' on line: ' + e.getLineNumber());
        }
    }
    
    public void finish(Database.BatchableContext bc) {
        // do nothing
    }
}

Hello

I tried to install dataloader on my Mac with the IT dpt of my company following this page: 

https://developer.salesforce.com/docs/atlas.en-us.dataLoader.meta/dataLoader/loader_content.htm 

I've tried the normal version + the one using the terminal line. However, when I try to open the app, it just closes as soon as it has opened. Could someone maybe send me an older version of the exec? Or give me the right instructions to install it. Thank you very much

even also i am using readonly  atribute ,  geting same error please do the needful,

Collection size 10,028 exceeds maximum size of 10,000. 


<apex:page controller="Leaddisplay" readOnly="true">

       <apex:pageBlock >
           <apex:DataTable value="{!ld}" var="a">
               <apex:column value="{!a.Lastname}"  headerValue="LastName"/>
            <apex:column value="{!a.company}"  headerValue="companyName"/>
               <apex:column value="{!a.status}"  headerValue="LeadStatus"/>
                     <apex:column value="{!a.phone}"  headerValue="phone"/>
               </apex:DataTable>
             
                 </apex:pageBlock>
      </apex:page>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>....


public class Leaddisplay {
    public list<lead>ld{set;get;}
    public Leaddisplay(){
       // ld= new list<lead>();
       ld=[select  lastname,phone,company,status from lead];
        
    }

}