You need to sign in to do that
Don't have an account?
getting bulkification issues on SOQL query () : Error List has more than 1 row for assignment to SObject 20
Getting error on Line no 13.
- public class CloneInternshipOpportunity {
- public static void createInternshipOpportunity(List<alu_Internship_Cycle__c> internCycle) {
- /*try{*/
- Map<Id,alu_Internship_Cycle__c> mapIdbyNewInternCyc = new Map<Id,alu_Internship_Cycle__c>(internCycle);
- System.debug('mapIdbyNewInternCyc'+mapIdbyNewInternCyc);
- Map<Id,alu_Internship_Cycle__c> mapIdbyOldInternCyc = new Map<Id,alu_Internship_Cycle__c> ([
- SELECT Id, Name, Start_Date__c
- FROM alu_Internship_Cycle__c
- WHERE Id NOT IN: mapIdbyNewInternCyc.keySet()
- AND Start_Date__c =: mapIdbyNewInternCyc.values().Start_Date__c.addYears(-1)]);
- System.debug('mapIdbyOldInternCyc '+mapIdbyOldInternCyc);
- List<Opportunity> oppListByOldCyc = [
- SELECT id, Name, RecordTypeId, AccountId, Account.Name, Internship_Cycle__c, Internship_Cycle__r.Name, CloseDate, StageName
- FROM Opportunity
- WHERE Internship_Cycle__c IN: mapIdbyOldInternCyc.KeySet()
- ];
- System.debug('oppListByOldCyc '+oppListByOldCyc);
- //Set<Opportunity> oppsToClone = new Set<Opportunity>();
- List<Opportunity> oppsToClone = new List<Opportunity>();
- for(Id tmp : mapIdbyNewInternCyc.keySet()){
- for(Opportunity opp : oppListByOldCyc){
- Opportunity opps = new Opportunity();
- opps.Name = 'Clone Opportunity';
- opps.RecordTypeId = opp.RecordTypeId;
- opps.CloseDate = opp.CloseDate;
- opps.StageName = opp.StageName;
- opps.AccountId = opp.AccountId;
- opps.Internship_Cycle__c = tmp;
- oppsToClone.add(opps);
- }
- }
- //List<Opportunity> op = new List<Opportunity>(oppsToClone);
- insert oppsToClone;
- System.debug('Opportunity>>>'+oppsToClone);
- /*}catch (Exception e){
- system.debug('Error '+e.getMessage() +' '+e.getLineNumber());
- }*/
- }
- }
Actually the code mapIdbyNewInternCyc.values() return a list from map values. Try below code