Skip to main content
added 230 characters in body
Source Link
Trigger CreateList on Campaign ( after insert ) {
List<Opportunity> opp = new List<Opportunity>(  );
List <OpportunityContactRole> ocrole = new List<OpportunityContactRole>(  );
public integer iOPPCount {get; set;
}

public integer icount {get; set;
}
    
for( Campaign camp : trigger.new ){
    if( camp.Create_List__c == True ){
        String sCamp= String.valueof( camp.id );
        iOPPCount  = [SELECT count(  ) FROM CampaignMember WHERE CampaignId =:sCamp];
        if ( iOPPCount  > 0 ){                
            // camp.addError( String.Valueof( iOPPCount ) );
            List<CampaignMember> camps = [SELECT id,FirstName,LastName,CompanyOrAccount,ContactId FROM CampaignMember WHERE CampaignId =:sCamp];            
            
            for( CampaignMember CM : camps ){
                String sEvent = String.valueof( camp.EventIDName__c );
                String sName = String.valueof( CM.FirstName ) + ' ' + String.valueof( CM.LastName );
                icount = [SELECT count(  ) FROM Opportunity WHERE Campaign__c =:camp.Id and Name=:sEvent +'-' + sName];
                
                if ( icount == 0 ){                    
                    
                    // camp.addError( sEvent + '-' + sLast );
                    //Opportunity  op = new Opportunity( Campaign__c=camp.Id,Name=sEvent+ '-' + sName,CloseDate=camp.EndDate,StageName='Prospecting' ); 
                    Opportunity op = new Opportunity( 
                    Campaign__c=camp.Id,
                    Name=sEvent +'-' + sName,
                    CloseDate=camp.EndDate,
                    StageName='Prospecting',
                    Contact__c= cm.ContactId );                                                            
                    opp.add( op );                                                                       
                    
                }
                
                insert opp;    
                
                for( Opportunity ops : opp ){
                    string sOppId = String.Valueof( ops.get( 'id' ) );
                    string sConId = String.Valueof( ops.get( 'Contact__c' ) );
                    // camp.addError( String.Valueof( opp[0].id ) );        
                    
                    OpportunityContactRole ocr = new OpportunityContactRole( 
                    OpportunityId = sOppId,
                    //ContactId = cm.ContactId,
                    ContactId = sConId,
                    IsPrimary = TRUE );
                    ocrole.add( ocr );
                    
                }
                
                insert ocrole;    
                
                // insert ocrole;        
                
            }
              
            
        }
         else if( iOPPCount  < 0 ){
            //do nothing
            
        }
        
        /*  {
            List<Contact> OPPList =[Select Name from  Contact];
            for ( Contact OPP : OPPList  )
            {
                String sOPPList= String.Valueof( OPP.get( 'Name' ) );
                OOpportunity o = new Opportunity( Campaign = camp.id, Name=camp.Name + '-' + sOPPList ,Contact__c =camp.Contact__c );
                ot.add( o );
                
            }
            
            insert ot;
            
        }
         */
        
    }
    
    
}

}

Trigger CreateList on Campaign ( after insert ) {
List<Opportunity> opp = new List<Opportunity>(  );
List <OpportunityContactRole> ocrole = new List<OpportunityContactRole>(  );
public integer iOPPCount {get; set;
}

public integer icount {get; set;
}
    
for( Campaign camp : trigger.new ){
    if( camp.Create_List__c == True ){
        String sCamp= String.valueof( camp.id );
        iOPPCount  = [SELECT count(  ) FROM CampaignMember WHERE CampaignId =:sCamp];
        if ( iOPPCount  > 0 ){                
            // camp.addError( String.Valueof( iOPPCount ) );
            List<CampaignMember> camps = [SELECT id,FirstName,LastName,CompanyOrAccount,ContactId FROM CampaignMember WHERE CampaignId =:sCamp];            
            
            for( CampaignMember CM : camps ){
                String sEvent = String.valueof( camp.EventIDName__c );
                String sName = String.valueof( CM.FirstName ) + ' ' + String.valueof( CM.LastName );
                icount = [SELECT count(  ) FROM Opportunity WHERE Campaign__c =:camp.Id and Name=:sEvent +'-' + sName];
                
                if ( icount == 0 ){                    
                    
                    // camp.addError( sEvent + '-' + sLast );
                    //Opportunity  op = new Opportunity( Campaign__c=camp.Id,Name=sEvent+ '-' + sName,CloseDate=camp.EndDate,StageName='Prospecting' ); 
                    Opportunity op = new Opportunity( 
                    Campaign__c=camp.Id,
                    Name=sEvent +'-' + sName,
                    CloseDate=camp.EndDate,
                    StageName='Prospecting',
                    Contact__c= cm.ContactId );                                                            
                    opp.add( op );                                                                       
                    
                }
                
                insert opp;    
                
                for( Opportunity ops : opp ){
                    string sOppId = String.Valueof( ops.get( 'id' ) );
                    string sConId = String.Valueof( ops.get( 'Contact__c' ) );
                    // camp.addError( String.Valueof( opp[0].id ) );        
                    
                    OpportunityContactRole ocr = new OpportunityContactRole( 
                    OpportunityId = sOppId,
                    //ContactId = cm.ContactId,
                    ContactId = sConId,
                    IsPrimary = TRUE );
                    ocrole.add( ocr );
                    
                }
                
                insert ocrole;    
                
                // insert ocrole;        
                
            }
              
            
        }
         else if( iOPPCount  < 0 ){
            //do nothing
            
        }
        
        /*  {
            List<Contact> OPPList =[Select Name from  Contact];
            for ( Contact OPP : OPPList  )
            {
                String sOPPList= String.Valueof( OPP.get( 'Name' ) );
                O
Trigger CreateList on Campaign ( after insert ) {
List<Opportunity> opp = new List<Opportunity>(  );
List <OpportunityContactRole> ocrole = new List<OpportunityContactRole>(  );
public integer iOPPCount {get; set;
}

public integer icount {get; set;
}
    
for( Campaign camp : trigger.new ){
    if( camp.Create_List__c == True ){
        String sCamp= String.valueof( camp.id );
        iOPPCount  = [SELECT count(  ) FROM CampaignMember WHERE CampaignId =:sCamp];
        if ( iOPPCount  > 0 ){                
            // camp.addError( String.Valueof( iOPPCount ) );
            List<CampaignMember> camps = [SELECT id,FirstName,LastName,CompanyOrAccount,ContactId FROM CampaignMember WHERE CampaignId =:sCamp];            
            
            for( CampaignMember CM : camps ){
                String sEvent = String.valueof( camp.EventIDName__c );
                String sName = String.valueof( CM.FirstName ) + ' ' + String.valueof( CM.LastName );
                icount = [SELECT count(  ) FROM Opportunity WHERE Campaign__c =:camp.Id and Name=:sEvent +'-' + sName];
                
                if ( icount == 0 ){                    
                    
                    // camp.addError( sEvent + '-' + sLast );
                    //Opportunity  op = new Opportunity( Campaign__c=camp.Id,Name=sEvent+ '-' + sName,CloseDate=camp.EndDate,StageName='Prospecting' ); 
                    Opportunity op = new Opportunity( 
                    Campaign__c=camp.Id,
                    Name=sEvent +'-' + sName,
                    CloseDate=camp.EndDate,
                    StageName='Prospecting',
                    Contact__c= cm.ContactId );                                                            
                    opp.add( op );                                                                       
                    
                }
                
                insert opp;    
                
                for( Opportunity ops : opp ){
                    string sOppId = String.Valueof( ops.get( 'id' ) );
                    string sConId = String.Valueof( ops.get( 'Contact__c' ) );
                    // camp.addError( String.Valueof( opp[0].id ) );        
                    
                    OpportunityContactRole ocr = new OpportunityContactRole( 
                    OpportunityId = sOppId,
                    //ContactId = cm.ContactId,
                    ContactId = sConId,
                    IsPrimary = TRUE );
                    ocrole.add( ocr );
                    
                }
                
                insert ocrole;    
                
                // insert ocrole;        
                
            }
              
            
        }
         else if( iOPPCount  < 0 ){
            //do nothing
            
        }
        
        /*  {
            List<Contact> OPPList =[Select Name from  Contact];
            for ( Contact OPP : OPPList  )
            {
                String sOPPList= String.Valueof( OPP.get( 'Name' ) );
                Opportunity o = new Opportunity( Campaign = camp.id, Name=camp.Name + '-' + sOPPList ,Contact__c =camp.Contact__c );
                ot.add( o );
                
            }
            
            insert ot;
            
        }
         */
        
    }
    
    
}

}

deleted 1112 characters in body
Source Link
triggerTrigger CreateList on Campaign ( after insert ) {
List<Opportunity> opp = new List<Opportunity>(  );
List <OpportunityContactRole> ocrole = new List<OpportunityContactRole>(  );
 public integer iOPPCount {get; set; 
} 

public integer icount {get; set;}


}
    
for( Campaign camp : trigger.new ){
     if( camp.Create_List__c == True ){
             String sCamp= String.valueof( camp.id );
             iOPPCount  = [SELECT count(  ) FROM CampaignMember WHERE CampaignId =:sCamp];
             if ( iOPPCount  > 0 ){                
                // camp.addError( String.Valueof( iOPPCount ) );
                 List<CampaignMember> camps = [SELECT id,FirstName,LastName,CompanyOrAccount,ContactId FROM CampaignMember WHERE CampaignId =:sCamp];            
                 
                 for( CampaignMember CM : camps ){
                     String sEvent = String.valueof( camp.EventIDName__c );
                     String sName = String.valueof( CM.FirstName ) + ' ' + String.valueof( CM.LastName );
                     icount = [SELECT count(  ) FROM Opportunity WHERE Campaign__c =:camp.Id and Name=:sEvent +'-' + sName];
                     
                     if ( icount == 0 ){                    
                         
                     // camp.addError( sEvent + '-' + sLast );
                    //Opportunity  op = new Opportunity( Campaign__c=camp.Id,Name=sEvent+ '-' + sName,CloseDate=camp.EndDate,StageName='Prospecting' ); 
                    Opportunity op = new Opportunity(
   
                    Campaign__c=camp.Id,
                      Name=sEvent +'-' + sName,
                      CloseDate=camp.EndDate,
                      StageName='Prospecting',
                      Contact__c= cm.ContactId );                                                            
                    opp.add( op );                                                                       
                    
                }
                
                insert opp;    
              
   
                for( Opportunity ops : opp ){
                     string sOppId = String.Valueof( ops.get( 'id' ) );
                     string sConId = String.Valueof( ops.get( 'Contact__c' ) );
                    // camp.addError( String.Valueof( opp[0].id ) );        
                                      
  
                   OpportunityContactRole ocr = new OpportunityContactRole( 
                    OpportunityId = sOppId,
                    //ContactId = cm.ContactId,
                    ContactId = sConId,
                    IsPrimary = TRUE );
                     ocrole.add( ocr );
                    }
                 insert ocrole;    }
                 
               // insert ocrole;        
               }  
             } else if(iOPPCount  < 0){
       // insert ocrole;        //do nothing
             }
      
          /*  {}
                
      List<Contact> OPPList =[Select Name from  Contact];
            }
         forelse if( Contact OPPiOPPCount : OPPList< 0 ){
                    //do {nothing
                     
     String sOPPList= String.Valueof( OPP.get( 'Name' ) );}
         
        /*  {
       Opportunity o = new Opportunity( CampaignList<Contact> =OPPList camp.id,=[Select Name=camp.Name + '-' + sOPPList ,Contact__cfrom =camp.Contact__c );Contact];
                    for ( Contact OPP : ot.add(OPPList o );
                     }{
                String sOPPList= String.Valueof( OPP.get( 'Name' insert) ot;);
                 } */
         }
 }

}O
trigger CreateList on Campaign (after insert) {
List<Opportunity> opp = new List<Opportunity>();
List <OpportunityContactRole> ocrole = new List<OpportunityContactRole>();
 public integer iOPPCount {get; set;}
public integer icount {get; set;}




for( Campaign camp : trigger.new ){
     if( camp.Create_List__c == True ){
             String sCamp= String.valueof(camp.id);
             iOPPCount  = [SELECT count() FROM CampaignMember WHERE CampaignId =:sCamp];
             if (iOPPCount  > 0 ){                
                // camp.addError(String.Valueof(iOPPCount));
                 List<CampaignMember> camps = [SELECT id,FirstName,LastName,CompanyOrAccount,ContactId FROM CampaignMember WHERE CampaignId =:sCamp];            
                 
                 for(CampaignMember CM : camps){
                     String sEvent = String.valueof(camp.EventIDName__c);
                     String sName = String.valueof(CM.FirstName) + ' ' + String.valueof(CM.LastName);
                     icount = [SELECT count() FROM Opportunity WHERE Campaign__c =:camp.Id and Name=:sEvent +'-' + sName];
                     
                     if (icount == 0){                    
                         
                     // camp.addError(sEvent + '-' + sLast);
                  //Opportunity  op = new Opportunity(Campaign__c=camp.Id,Name=sEvent+ '-' + sName,CloseDate=camp.EndDate,StageName='Prospecting'); 
                  Opportunity op = new Opportunity(
                      Campaign__c=camp.Id,
                      Name=sEvent +'-' + sName,
                      CloseDate=camp.EndDate,
                      StageName='Prospecting',
                      Contact__c= cm.ContactId );                                                            
                   opp.add(op);                                                                       
                  }
                        insert opp;    
              
                  for(Opportunity ops : opp){
                     string sOppId = String.Valueof(ops.get('id'));
                     string sConId = String.Valueof(ops.get('Contact__c'));
                // camp.addError(String.Valueof(opp[0].id));        
                                       
                   OpportunityContactRole ocr = new OpportunityContactRole(
                    OpportunityId = sOppId,
                    //ContactId = cm.ContactId,
                    ContactId = sConId,
                    IsPrimary = TRUE);
                     ocrole.add(ocr);
                    }
                 insert ocrole;    
                 
               // insert ocrole;        
               }  
             } else if(iOPPCount  < 0){
                 //do nothing
             }
               /*  {
                     List<Contact> OPPList =[Select Name from  Contact];
                     for ( Contact OPP : OPPList  )
                     {
                         String sOPPList= String.Valueof( OPP.get( 'Name' ) );
                         Opportunity o = new Opportunity( Campaign = camp.id, Name=camp.Name + '-' + sOPPList ,Contact__c =camp.Contact__c );
                         ot.add( o );
                     }
                     insert ot;
                 } */
         }
 }

}
Trigger CreateList on Campaign ( after insert ) {
List<Opportunity> opp = new List<Opportunity>(  );
List <OpportunityContactRole> ocrole = new List<OpportunityContactRole>(  );
public integer iOPPCount {get; set; 
} 

public integer icount {get; set;
}
    
for( Campaign camp : trigger.new ){
    if( camp.Create_List__c == True ){
        String sCamp= String.valueof( camp.id );
        iOPPCount  = [SELECT count(  ) FROM CampaignMember WHERE CampaignId =:sCamp];
        if ( iOPPCount  > 0 ){                
            // camp.addError( String.Valueof( iOPPCount ) );
            List<CampaignMember> camps = [SELECT id,FirstName,LastName,CompanyOrAccount,ContactId FROM CampaignMember WHERE CampaignId =:sCamp];            
            
            for( CampaignMember CM : camps ){
                String sEvent = String.valueof( camp.EventIDName__c );
                String sName = String.valueof( CM.FirstName ) + ' ' + String.valueof( CM.LastName );
                icount = [SELECT count(  ) FROM Opportunity WHERE Campaign__c =:camp.Id and Name=:sEvent +'-' + sName];
                
                if ( icount == 0 ){                    
                    
                    // camp.addError( sEvent + '-' + sLast );
                    //Opportunity  op = new Opportunity( Campaign__c=camp.Id,Name=sEvent+ '-' + sName,CloseDate=camp.EndDate,StageName='Prospecting' ); 
                    Opportunity op = new Opportunity(  
                    Campaign__c=camp.Id,
                    Name=sEvent +'-' + sName,
                    CloseDate=camp.EndDate,
                    StageName='Prospecting',
                    Contact__c= cm.ContactId );                                                            
                    opp.add( op );                                                                       
                    
                }
                
                insert opp;    
                
                for( Opportunity ops : opp ){
                    string sOppId = String.Valueof( ops.get( 'id' ) );
                    string sConId = String.Valueof( ops.get( 'Contact__c' ) );
                    // camp.addError( String.Valueof( opp[0].id ) );        
                     
                    OpportunityContactRole ocr = new OpportunityContactRole( 
                    OpportunityId = sOppId,
                    //ContactId = cm.ContactId,
                    ContactId = sConId,
                    IsPrimary = TRUE );
                    ocrole.add( ocr );
                    
                }
                
                insert ocrole;    
                
                // insert ocrole;        
                 
            }
               
            
        }
         else if( iOPPCount  < 0 ){
            //do nothing
             
        }
         
        /*  {
            List<Contact> OPPList =[Select Name from  Contact];
            for ( Contact OPP : OPPList  )
            {
                String sOPPList= String.Valueof( OPP.get( 'Name' ) );
                O
code formatting
Source Link
Novarg
  • 5.3k
  • 1
  • 30
  • 59
trigger CreateList on Campaign (after insert) {
List<Opportunity> opp = new List<Opportunity>();
List <OpportunityContactRole> ocrole = new List<OpportunityContactRole>();
 public integer iOPPCount {get; set;}
public integer icount {get; set;}

for( Campaign camp : trigger.new ){ if( camp.Create_List__c == True ){ String sCamp= String.valueof(camp.id); iOPPCount = [SELECT count() FROM CampaignMember WHERE CampaignId =:sCamp]; if (iOPPCount > 0 ){
// camp.addError(String.Valueof(iOPPCount)); List camps = [SELECT id,FirstName,LastName,CompanyOrAccount,ContactId FROM CampaignMember WHERE CampaignId =:sCamp];





for( Campaign camp : trigger.new ){
     if( camp.Create_List__c == True ){
             String sCamp= String.valueof(camp.id);
             iOPPCount  = [SELECT count() FROM CampaignMember WHERE CampaignId =:sCamp];
             if (iOPPCount  > 0 ){                
                // camp.addError(String.Valueof(iOPPCount));
                 List<CampaignMember> camps = [SELECT id,FirstName,LastName,CompanyOrAccount,ContactId FROM CampaignMember WHERE CampaignId =:sCamp];            
                 
                 for(CampaignMember CM : camps){
                     String sEvent = String.valueof(camp.EventIDName__c);
                     String sName = String.valueof(CM.FirstName) + ' ' + String.valueof(CM.LastName);
                     icount = [SELECT count() FROM Opportunity WHERE Campaign__c =:camp.Id and Name=:sEvent +'-' + sName];
                     
                     if (icount == 0){                    
                         
                     // camp.addError(sEvent + '-' + sLast);
                  //Opportunity  op = new Opportunity(Campaign__c=camp.Id,Name=sEvent+ '-' + sName,CloseDate=camp.EndDate,StageName='Prospecting'); 
                  Opportunity op = new Opportunity(
                      Campaign__c=camp.Id,
                      Name=sEvent +'-' + sName,
                      CloseDate=camp.EndDate,
                      StageName='Prospecting',
                      Contact__c= cm.ContactId );                                                            
                   opp.add(op);                                                                       
                  }
                        insert opp;    
              
                 for(Opportunity ops : opp){
                     string sOppId = String.Valueof(ops.get('id'));
                     string sConId = String.Valueof(ops.get('Contact__c'));
                // camp.addError(String.Valueof(opp[0].id));        
                                       
                  OpportunityContactRole ocr = new OpportunityContactRole(
                    OpportunityId = sOppId,
                    //ContactId = cm.ContactId,
                    ContactId = sConId,
                    IsPrimary = TRUE);
                     ocrole.add(ocr);
                    }
                 insert ocrole;    
                 
               // insert ocrole;        
               }  
             } else if(iOPPCount  < 0){
                 //do nothing
             }
               /*  {
                     List<Contact> OPPList =[Select Name from  Contact];
                     for ( Contact OPP : OPPList  )
                     {
                         String sOPPList= String.Valueof( OPP.get( 'Name' ) );
                         Opportunity o = new Opportunity( Campaign = camp.id, Name=camp.Name + '-' + sOPPList ,Contact__c =camp.Contact__c );
                         ot.add( o );
                     }
                     insert ot;
                 } */
         }
 }

}

}

}

trigger CreateList on Campaign (after insert) {
List<Opportunity> opp = new List<Opportunity>();
List <OpportunityContactRole> ocrole = new List<OpportunityContactRole>();
 public integer iOPPCount {get; set;}
public integer icount {get; set;}

for( Campaign camp : trigger.new ){ if( camp.Create_List__c == True ){ String sCamp= String.valueof(camp.id); iOPPCount = [SELECT count() FROM CampaignMember WHERE CampaignId =:sCamp]; if (iOPPCount > 0 ){
// camp.addError(String.Valueof(iOPPCount)); List camps = [SELECT id,FirstName,LastName,CompanyOrAccount,ContactId FROM CampaignMember WHERE CampaignId =:sCamp];

             for(CampaignMember CM : camps){
                 String sEvent = String.valueof(camp.EventIDName__c);
                 String sName = String.valueof(CM.FirstName) + ' ' + String.valueof(CM.LastName);
                 icount = [SELECT count() FROM Opportunity WHERE Campaign__c =:camp.Id and Name=:sEvent +'-' + sName];
                 
                 if (icount == 0){                    
                     
                 // camp.addError(sEvent + '-' + sLast);
              //Opportunity  op = new Opportunity(Campaign__c=camp.Id,Name=sEvent+ '-' + sName,CloseDate=camp.EndDate,StageName='Prospecting'); 
              Opportunity op = new Opportunity(
                  Campaign__c=camp.Id,
                  Name=sEvent +'-' + sName,
                  CloseDate=camp.EndDate,
                  StageName='Prospecting',
                  Contact__c= cm.ContactId );                                                            
               opp.add(op);                                                                       
              }
                    insert opp;    
          
             for(Opportunity ops : opp){
                 string sOppId = String.Valueof(ops.get('id'));
                 string sConId = String.Valueof(ops.get('Contact__c'));
            // camp.addError(String.Valueof(opp[0].id));        
                                   
              OpportunityContactRole ocr = new OpportunityContactRole(
                OpportunityId = sOppId,
                //ContactId = cm.ContactId,
                ContactId = sConId,
                IsPrimary = TRUE);
                 ocrole.add(ocr);
                }
             insert ocrole;    
             
           // insert ocrole;        
           }  
         } else if(iOPPCount  < 0){
             //do nothing
         }
           /*  {
                 List<Contact> OPPList =[Select Name from  Contact];
                 for ( Contact OPP : OPPList  )
                 {
                     String sOPPList= String.Valueof( OPP.get( 'Name' ) );
                     Opportunity o = new Opportunity( Campaign = camp.id, Name=camp.Name + '-' + sOPPList ,Contact__c =camp.Contact__c );
                     ot.add( o );
                 }
                 insert ot;
             } */
     }

}

}

trigger CreateList on Campaign (after insert) {
List<Opportunity> opp = new List<Opportunity>();
List <OpportunityContactRole> ocrole = new List<OpportunityContactRole>();
 public integer iOPPCount {get; set;}
public integer icount {get; set;}




for( Campaign camp : trigger.new ){
     if( camp.Create_List__c == True ){
             String sCamp= String.valueof(camp.id);
             iOPPCount  = [SELECT count() FROM CampaignMember WHERE CampaignId =:sCamp];
             if (iOPPCount  > 0 ){                
                // camp.addError(String.Valueof(iOPPCount));
                 List<CampaignMember> camps = [SELECT id,FirstName,LastName,CompanyOrAccount,ContactId FROM CampaignMember WHERE CampaignId =:sCamp];            
                 
                 for(CampaignMember CM : camps){
                     String sEvent = String.valueof(camp.EventIDName__c);
                     String sName = String.valueof(CM.FirstName) + ' ' + String.valueof(CM.LastName);
                     icount = [SELECT count() FROM Opportunity WHERE Campaign__c =:camp.Id and Name=:sEvent +'-' + sName];
                     
                     if (icount == 0){                    
                         
                     // camp.addError(sEvent + '-' + sLast);
                  //Opportunity  op = new Opportunity(Campaign__c=camp.Id,Name=sEvent+ '-' + sName,CloseDate=camp.EndDate,StageName='Prospecting'); 
                  Opportunity op = new Opportunity(
                      Campaign__c=camp.Id,
                      Name=sEvent +'-' + sName,
                      CloseDate=camp.EndDate,
                      StageName='Prospecting',
                      Contact__c= cm.ContactId );                                                            
                   opp.add(op);                                                                       
                  }
                        insert opp;    
              
                 for(Opportunity ops : opp){
                     string sOppId = String.Valueof(ops.get('id'));
                     string sConId = String.Valueof(ops.get('Contact__c'));
                // camp.addError(String.Valueof(opp[0].id));        
                                       
                  OpportunityContactRole ocr = new OpportunityContactRole(
                    OpportunityId = sOppId,
                    //ContactId = cm.ContactId,
                    ContactId = sConId,
                    IsPrimary = TRUE);
                     ocrole.add(ocr);
                    }
                 insert ocrole;    
                 
               // insert ocrole;        
               }  
             } else if(iOPPCount  < 0){
                 //do nothing
             }
               /*  {
                     List<Contact> OPPList =[Select Name from  Contact];
                     for ( Contact OPP : OPPList  )
                     {
                         String sOPPList= String.Valueof( OPP.get( 'Name' ) );
                         Opportunity o = new Opportunity( Campaign = camp.id, Name=camp.Name + '-' + sOPPList ,Contact__c =camp.Contact__c );
                         ot.add( o );
                     }
                     insert ot;
                 } */
         }
 }

}
Source Link
Loading