• Surinder Singh 25
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 8
    Replies
/*
 *  Purpose: Defaults Business segment as per Custom settings data and populates this field.
 *           Products__c = "Support Service Requested"
 *           Calculates SLA Lapse Days on Opportunity
 *           Calculate response Time on Opportunity
 *           
 *  @Author: Pranjal Singh           
 **/
public class DFCS_defaultBusinessSegment
{
  public static Integer i =0;
  //public static Integer RECORD_COUNT = [SELECT count() FROM BusinessSegment__c];
  public static long hours;
  public static Integer value;
  public static ID  BussId  = [select Id from BusinessHours where isdefault = true].ID;

 /*   public static void defaultBusinessSegment(List<Opportunity> oppList)
    {
       
        for(Opportunity opp: oppList){
            while(i != RECORD_COUNT){
                i++;
                BusinessSegment__c obj = BusinessSegment__c.getValues('BS-'+i); //Support Service
               if((opp.Product_Type__c == obj.Product_Family__c) &&
                    (opp.Products__c == obj.Support_Service__c))
                {   
                   opp.BusinessSegment__c = obj.Business_Segment__c;
              }
            }
        }
    }
  
  */
  public static void SLA_Lapse_Days(List<Opportunity> oppList) 
  {
    Date CurDate= system.Today(); 
   // if(bh == null) bh = [select Id from BusinessHours where isdefault = true ];
    for(Opportunity opp: oppList)
     {
        if(opp.Opportunity_SLA_Commitment_Date__c!=Null)
           {
           
             if((opp.Release_Date__c!=Null)&&(opp.Release_Date__c>opp.Opportunity_SLA_Commitment_Date__c))
              {
           
              hours = Math.abs(BusinessHours.diff(BussId,opp.Release_Date__c,opp.Opportunity_SLA_Commitment_Date__c)/1000/60/60); 
              value = hours.intValue();
              value= value/9;
              opp.SLA_Lapase_Days__c=value;
              }
              
              if((opp.Release_Date__c==Null)&&(opp.Opportunity_SLA_Commitment_Date__c<=CurDate))
              {
              
              hours = Math.abs(BusinessHours.diff(BussId,opp.Opportunity_SLA_Commitment_Date__c,CurDate)/1000/60/60); 
              value = hours.intValue();
              value= value/9;
              opp.SLA_Lapase_Days__c=value;
              }
              
             if((opp.Release_Date__c!=Null)&&(opp.Release_Date__c<opp.Opportunity_SLA_Commitment_Date__c)||(opp.Release_Date__c==Null)&&(opp.Opportunity_SLA_Commitment_Date__c>=CurDate))
              {
              opp.SLA_Lapase_Days__c=0;
              }
              
              } 
             
           }
     
     }
  
  
  
  
  
  

}
{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")} Var r = Confirm("Are you sure, you want to send email"); if (r==true) { sforce.apex.execute("ContactsendEmail","sendEmail",{Email:"{!Contact.Email}"}); alert("Contact Email " + {!Contact.Email}); alert("Email Sent Successfully"); }
Class -
global class ContactsendEmail { webservice static void sendEmail(String Email) { Messaging.Singleemailmessage mail = new Messaging.Singleemailmessage(); mail.setToAddresses(new String[] {'surinder.b.singh@accenture.com'}); mail.setReplyTo('noreply@privatebudget.com'); mail.setSenderDisplayName('Private Budget App'); mail.setSubject('Private Budget records for ' + Date.today().month() + ' ' + Date.today().year()); mail.setBccSender(false); mail.setUseSignature(false); mail.setPlainTextBody('This is a test'); system.debug('@@@@ sendEmail - mail : ' + mail); Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); } }

Javascript code fires on a custom button on contact. I ma getting error like - "A problem with Javascript on this button - Unexpected identifier
I am getting too many DML 10001 error while updating a account record.
For that Account record their are more than 2000 contact records.
Please suggest some solutions for this issue.
 for (Contact c : [SELECT Id,accountId,Mailing_Street_1__c,Mailing_City__c,Mailing_Country__c,Mailing_State_Province_US_CA_Only__c,Mailing_Zonex__c ,Account.Physical_Street_1__c,Account.Physical_City__c,
                          Account.Physical_Country__c,Account.UGS_Zone_Ownership__c,Account.Physical_State_Province_US_CA_Only__c
                          FROM contact WHERE accountId in :acctsWithNewAddresses.keySet()]) 
        {        
            Account parentAccount = acctsWithNewAddresses.get(c.accountId);
            
            // Access the "old" record by its ID in oldmapAccount
            Account oldacc = oldmapAccount.get(parentAccount.Id);
            
            if(c.Mailing_Street_1__c == oldacc.Physical_Street_1__c && c.Mailing_City__c == oldacc.Physical_City__c &&  
               c.Mailing_Country__c == oldacc.Physical_Country__c && c.Mailing_State_Province_US_CA_Only__c == oldacc.Physical_State_Province_US_CA_Only__c)
            
            {
                c.Mailing_County_Province__c = parentAccount.Physical_County_Province__c;
                c.Mailing_Street_1__c = parentAccount.Physical_Street_1__c;
                c.Mailing_Street_2__c = parentAccount.Physical_Street_2__c;
                c.Mailing_City__c = parentAccount.Physical_City__c;
                c.Mailing_Zip_Postal_Code__c = parentAccount.Physical_Zip_Postal_Code__c;
                c.Mailing_Country__c = parentAccount.Physical_Country__c;
                c.Mailing_State_Province_US_CA_Only__c = parentAccount.Physical_State_Province_US_CA_Only__c;           
                updatedContacts.add(c);
                
            }
        }
        update updatedContacts;
When a user is added to a chatter group, Email notification is sent to user that you are added to this particular group. Business wants a Footer test in the email. I have set Chatter Email Setting footer with the text provided by business. But still emails are not showing That footer text.
Am i missing anything ?
trigger UpdTeamMember on Account_Plan_Team_Member__c (before insert, before update, after update) {


Public string level;

list<account_plan__share> sharerec = new list<account_plan__share>();

list<account_plan_team_member__c> members = new list<account_plan_team_member__c> ();
members.add(trigger.new[0]);

if(trigger.isbefore && trigger.isupdate) 
{
 if(trigger.old[0].ap_access__c <> trigger.new[0].ap_access__c) 
{
    id userid = trigger.new[0].siemens_user__c;
    id parentid = trigger.new[0].account_plan__c;

      for(account_plan__share share : [select accesslevel from account_plan__share where userorgroupid=:userid and parentid=:parentid]) 
      {
        level = trigger.new[0].AP_access__c;
        if(level=='Read Only') {share.accesslevel = 'Read';}
        if(level=='Read / Write') {share.accesslevel = 'Edit';}

        sharerec.add(share);
      }
       update sharerec;
}
}

if(trigger.isbefore && trigger.isinsert) 
{
    id userid = trigger.new[0].siemens_user__c;
    id parentid = trigger.new[0].account_plan__c;

      for(account_plan__share share : [select accesslevel from account_plan__share where userorgroupid=:userid and parentid=:parentid])
      {
        level = trigger.new[0].AP_access__c;
        if(level=='Read Only') {share.accesslevel = 'Read';}
        if(level=='Read / Write') {share.accesslevel = 'Edit';}
         system.debug('---' + share.userorgroupid);

        sharerec.add(share);
       }

   insert sharerec;
}
} // end of trigger
/** Controller to add Contacts to Portfolio Suspect  **/
/** vf page - MultiselectContactAC **/
/** GSI Project **/
/** Owner - Shikha Mishra **/

public with sharing class AddContacttoAttributedCampaign{ 

    public AttributedCampaign__c attc;
    public ContactAttributedCampaign__c cac {get;set;} 
    public list<ContactAttributedCampaign__c> cacList{get;set;}
    public string attid; 
    public string accid; 
    @TestVisible public list<wrapContact> wrapContactList {get; set;} 
    public list<Contact> selectedContacts {get; set;}
    public integer totalRecs = 0;
    public integer index =0;
    public integer blockSize = 100; 
    public integer NoOfRecords = 1;
    public integer TotalPages;
    public integer sizeOfStartIndex;

    public AddContacttoAttributedCampaign(ApexPages.StandardController stdController)
  {
        this.attc = (AttributedCampaign__c)stdController.getRecord();
        attid =ApexPages.currentPage().getParameters().get('attid'); 
        accid =ApexPages.currentPage().getParameters().get('accid');
        cac = new ContactAttributedCampaign__c();
        attc = new AttributedCampaign__c ();
        for(AggregateResult result :[SELECT COUNT(Id) intVal FROM Contact where AccountId=:accid])
            {
                totalRecs+=(Integer)result.get('intVal');
            }
        TotalPages = totalRecs/blocksize;

        cacList = [Select Name, Attributed_Campaign__c, Contact__c, Include_in_Marketing_Activity__c from ContactAttributedCampaign__c where Attributed_Campaign__c =: attid order by Name];
      system.debug('cacList##'+cacList.size()) ;
      wrapContactList = new list<wrapContact>();
        for (contact c : [Select Id, Name, title, Job_Role__c, Job_Function__c from Contact where AccountId =: accid and Contact_Status__c = 'Active' Order by Name ASC LIMIT : blockSize OFFSET:index ])
        {
            wrapContactList.add(new wrapContact(c));
        }
         sizeOfStartIndex = wrapContactList.size();
  } 
public void beginning()
{   
    wrapContactList.clear();
    NoOfRecords =1;
    index = 0;
    for (contact c : [Select Id, Name, title, Job_Role__c, Job_Function__c from Contact where AccountId =: accid and Contact_Status__c = 'Active' Order by Name ASC LIMIT : blockSize OFFSET:index])
        {
            wrapContactList.add(new wrapContact(c));
        }
   
}

public void previous()
{
 wrapContactList.clear();   
 if(NoOfRecords > 1)
 {
   index = index - blocksize;
 for (contact c : [Select Id, Name, title, Job_Role__c, Job_Function__c from Contact where AccountId =: accid and Contact_Status__c = 'Active' Order by Name ASC LIMIT : blockSize OFFSET:index])         
        {
            wrapContactList.add(new wrapContact(c));
        }
     NoOfRecords=NoOfRecords -1 ;
     
 }
  else
  {
    beginning(); 
  }
}
public void next()
{   
 wrapContactList.clear();
   
    if(NoOfRecords < TotalPages)
    {
                 index = index + blocksize;
               system.debug('index value in last next--' + index);
                for (contact c : [Select Id, Name, title, Job_Role__c, Job_Function__c from Contact where AccountId =: accid and Contact_Status__c = 'Active' Order by Name ASC LIMIT : blockSize OFFSET:index])
                    {
                        wrapContactList.add(new wrapContact(c));
                    }
               // index = index + wrapContactList.size();
               NoOfRecords= NoOfRecords+1;
    }
    else
    {
        
       for (contact c : [Select Id, Name, title, Job_Role__c, Job_Function__c from Contact where AccountId =: accid and Contact_Status__c = 'Active' Order by Name ASC LIMIT : blockSize OFFSET:index])
                    {
                        wrapContactList.add(new wrapContact(c));
                    } 
        
    }
    
}

public void end()
{   
wrapContactList.clear();

if(NoOfRecords <=totalPages)
{index = totalRecs - blocksize;
 
for(contact c : [Select Id, Name, title, Job_Role__c, Job_Function__c from Contact where AccountId =: accid and Contact_Status__c = 'Active' Order by Name ASC LIMIT : blockSize OFFSET:index])
                {  wrapContactList.add(new wrapContact(c));} NoOfRecords = TotalPages;
         
   
}
}
    
public boolean getDisableNext()
{
    if(sizeOfStartIndex < blocksize)
      {
           return true;
       }
      else
       {
           return false;
      }
}


    
}

Public PageReference SavePage() 

        selectedContacts = new list<Contact>();
        Set<Id> cacID = new Set<Id>();
        for(ContactAttributedCampaign__c ca :cacList)
        {
            cacID.add(ca.Contact__c);
        }List<ContactAttributedCampaign__c> insertList = new List<ContactAttributedCampaign__c>();

        
        for(wrapContact wrapobj : wrapContactList){
            
            if(wrapobj.isSelected == true)
            {
                 if(!cacID.contains(wrapobj.conn.Id)){
                   ContactAttributedCampaign__c conac = new ContactAttributedCampaign__c(Attributed_Campaign__c=attid,Contact__c=wrapobj.conn.id,Include_in_Marketing_Activity__c=wrapobj.mark) ;
                   //conac.Attributed_Campaign__c = attid; 
                   //conac.Contact__c = wrapobj.conn.id; 
                   //conac.Include_in_Marketing_Activity__c= wrapobj.mark;
                   insertList.add(conac);
                 //  wrapobj.isSelected =False; 
           }
           
                     for(ContactAttributedCampaign__c item : cacList)
                       {if(item.Contact__c == wrapobj.conn.id && item.Include_in_Marketing_Activity__c != wrapobj.mark)
                           {ContactAttributedCampaign__c conac = [select id,Include_in_Marketing_Activity__c from ContactAttributedCampaign__c where Attributed_Campaign__c = :attid and Contact__c = :wrapobj.conn.id]; conac.Include_in_Marketing_Activity__c = wrapobj.mark; insertList.add(conac);
                             }
                         }
                 } 
            }
            upsert insertList;
            
     cacList = [Select Name, Attributed_Campaign__c, Contact__c, Include_in_Marketing_Activity__c  from ContactAttributedCampaign__c where Attributed_Campaign__c =: attid order by Name desc];
        
        return null;
        }
 
    public PageReference redirectBack(){
        return new PageReference('/'+attid);
    }


   @TestVisible public class wrapContact{
        public Contact conn{get; set;}
        public ContactAttributedCampaign__c cac{get;set;}
        public boolean isSelected {get; set;}
        public Boolean mark{get;set;}

            public wrapContact(Contact c){
                this.conn = c;
                this.isSelected = false;                
            }
            public wrapContact(ContactAttributedCampaign__c d){
                this.cac = d;
                this.isSelected = false;  
                this.mark  = d.Include_in_Marketing_Activity__c;
            }
    }    
}


VF Page - 

<apex:page standardController="AttributedCampaign__c" extensions="AddContacttoAttributedCampaign" showHeader="false" sidebar="false"> 
<apex:form id="frm"> 
    <apex:pageMessages />
    
 <apex:pageBlock title="Added Contacts">
     
   <apex:pageBlockTable value="{!cacList}" var="cac">
      <apex:column headerValue="Name" value="{!cac.Name}"/>
      <apex:column headerValue="Portfolio Suspect" value="{!cac.Attributed_Campaign__c}"/>
      <apex:column headerValue="Contact" value="{!cac.Contact__c}"/>
      <apex:column headerValue="Include in Marketing Activity" value="{!cac.Include_in_Marketing_Activity__c}"/>
   </apex:pageBlockTable> 
</apex:pageBlock>   
 
  <apex:pageBlock title="Add Contact to Portfolio Suspect" id="pb"> 
    <apex:pageMessages />
    
    <apex:pageBlock id="pb2">
    <apex:pageBlockSection columns="1">  
     <apex:outputPanel id="myPanel" layout="">
    <apex:pageBlockTable value="{!wrapContactList}" var="aconl">
        <apex:column >
        <apex:facet name="header">

        </apex:facet>
            <apex:inputCheckbox value="{!aconl.isSelected}" id="inputID"/>

        </apex:column>
        <apex:column headerValue="Name">
        <apex:outputfield value="{!aconl.conn.name}"/>
        </apex:column>
        <apex:column headerValue="Title">
        <apex:outputfield value="{!aconl.conn.Title}"/>
        </apex:column>
        <apex:column headerValue="Job Function">
        <apex:outputfield value="{!aconl.conn.Job_Function__c}"/>
        </apex:column>
        <apex:column headerValue="Job Role">
        <apex:outputfield value="{!aconl.conn.Job_Role__c}"/>
        </apex:column>
        <apex:column headerValue="Include in Marketing Activity">
        <apex:inputCheckbox value="{!aconl.mark}" />
        </apex:column>

    </apex:pageBlockTable>
</apex:outputPanel>
    </apex:pageBlockSection>  
    </apex:pageBlock>
    <apex:pageBlockButtons >      
        <apex:commandButton id="addContact" value="Add" action="{!SavePage}" style="align:center;"/>
        <apex:commandButton value="First Page" action="{!beginning}" disabled="{!DisableNext}" reRender="myPanel" />
        <apex:commandButton value="Next" action="{!next}" disabled="{!DisableNext}"   reRender="myPanel" />
         <apex:commandButton value="Prev" action="{!previous}" disabled="{!DisableNext}"   reRender="myPanel"/>
        <apex:commandButton value="Last Page" action="{!end}"  disabled="{!DisableNext}"  reRender="myPanel"/>
        <apex:commandButton id="redirectBack" value="Done" action="{!redirectBack}"/>
        <apex:commandLink action="{!getPageNumbers}" value="P1" rerender="pb"/> 
       
    </apex:pageBlockButtons>
    </apex:pageBlock>     

</apex:form>
</apex:page>

Output - 

User-added image
I have to write an trigger which will do -

When an campaign is added to opportunity ( from campaign influence related list "Add to compaign" button), then if that opportunity has no already existing campaigns(means that campaign is the first one) then make that campaign primary campaign autometically ( if user forget to check primary campaign source checkbox). If user has checked primary campaign source checkbox then nothing to do.

I am not sure on which object i have to write trigger. What will be the trigger. Completely have no idea on this Opp Campaign relationship. Please help me to write trigger.
 Create a batch which looks at all active Opportunities and IF there is only one campaign and the Primary Campaign Acitivity is not checked, check it. There should be no active Opps with Campaigns that do not have a Primary campaign checked.

Basically i have to look all existing opp if there is any opp having only single Campaign records and Primary campaign activity is not checked then i have to check.

I have no idea of Opp and campaign relationship. Please let me know how i can do this.
trigger AssignCloseOppTeamMember on OpportunityTeamMember (after insert) {
List<Opportunity> OpportunityList = new List<Opportunity>();
Map<Id, Id> OppIdOppMemberIdMap = new Map<Id, Id>();

for(OpportunityTeamMember OpportunityTeamMemberObj: Trigger.New){
    if(OpportunityTeamMemberObj.TeamMemberRole =='Portfolio Developer')
    
        OppIdOppMemberIdMap.put(OpportunityTeamMemberObj.OpportunityId , OpportunityTeamMemberObj.Id);
}

for(Opportunity opportunityObj : [Select Id, LocalPortfolioDeveloper__c from Opportunity where Id IN: OppIdOppMemberIdMap.keyset()]){
    if(OppIdOppMemberIdMap.Containskey(opportunityObj.Id)){
        opportunityObj.LocalPortfolioDeveloper__c= OppIdOppMemberIdMap.get(opportunityObj.Id).User.Id;
        OpportunityList.add(opportunityObj);
        }
    }
update OpportunityList;

}
getting error - Compile Error: Initial term of field expression must be a concrete SObject: Id at line 13 column 95
I am getting too many DML 10001 error while updating a account record.
For that Account record their are more than 2000 contact records.
Please suggest some solutions for this issue.
 for (Contact c : [SELECT Id,accountId,Mailing_Street_1__c,Mailing_City__c,Mailing_Country__c,Mailing_State_Province_US_CA_Only__c,Mailing_Zonex__c ,Account.Physical_Street_1__c,Account.Physical_City__c,
                          Account.Physical_Country__c,Account.UGS_Zone_Ownership__c,Account.Physical_State_Province_US_CA_Only__c
                          FROM contact WHERE accountId in :acctsWithNewAddresses.keySet()]) 
        {        
            Account parentAccount = acctsWithNewAddresses.get(c.accountId);
            
            // Access the "old" record by its ID in oldmapAccount
            Account oldacc = oldmapAccount.get(parentAccount.Id);
            
            if(c.Mailing_Street_1__c == oldacc.Physical_Street_1__c && c.Mailing_City__c == oldacc.Physical_City__c &&  
               c.Mailing_Country__c == oldacc.Physical_Country__c && c.Mailing_State_Province_US_CA_Only__c == oldacc.Physical_State_Province_US_CA_Only__c)
            
            {
                c.Mailing_County_Province__c = parentAccount.Physical_County_Province__c;
                c.Mailing_Street_1__c = parentAccount.Physical_Street_1__c;
                c.Mailing_Street_2__c = parentAccount.Physical_Street_2__c;
                c.Mailing_City__c = parentAccount.Physical_City__c;
                c.Mailing_Zip_Postal_Code__c = parentAccount.Physical_Zip_Postal_Code__c;
                c.Mailing_Country__c = parentAccount.Physical_Country__c;
                c.Mailing_State_Province_US_CA_Only__c = parentAccount.Physical_State_Province_US_CA_Only__c;           
                updatedContacts.add(c);
                
            }
        }
        update updatedContacts;
trigger UpdTeamMember on Account_Plan_Team_Member__c (before insert, before update, after update) {


Public string level;

list<account_plan__share> sharerec = new list<account_plan__share>();

list<account_plan_team_member__c> members = new list<account_plan_team_member__c> ();
members.add(trigger.new[0]);

if(trigger.isbefore && trigger.isupdate) 
{
 if(trigger.old[0].ap_access__c <> trigger.new[0].ap_access__c) 
{
    id userid = trigger.new[0].siemens_user__c;
    id parentid = trigger.new[0].account_plan__c;

      for(account_plan__share share : [select accesslevel from account_plan__share where userorgroupid=:userid and parentid=:parentid]) 
      {
        level = trigger.new[0].AP_access__c;
        if(level=='Read Only') {share.accesslevel = 'Read';}
        if(level=='Read / Write') {share.accesslevel = 'Edit';}

        sharerec.add(share);
      }
       update sharerec;
}
}

if(trigger.isbefore && trigger.isinsert) 
{
    id userid = trigger.new[0].siemens_user__c;
    id parentid = trigger.new[0].account_plan__c;

      for(account_plan__share share : [select accesslevel from account_plan__share where userorgroupid=:userid and parentid=:parentid])
      {
        level = trigger.new[0].AP_access__c;
        if(level=='Read Only') {share.accesslevel = 'Read';}
        if(level=='Read / Write') {share.accesslevel = 'Edit';}
         system.debug('---' + share.userorgroupid);

        sharerec.add(share);
       }

   insert sharerec;
}
} // end of trigger
/** Controller to add Contacts to Portfolio Suspect  **/
/** vf page - MultiselectContactAC **/
/** GSI Project **/
/** Owner - Shikha Mishra **/

public with sharing class AddContacttoAttributedCampaign{ 

    public AttributedCampaign__c attc;
    public ContactAttributedCampaign__c cac {get;set;} 
    public list<ContactAttributedCampaign__c> cacList{get;set;}
    public string attid; 
    public string accid; 
    @TestVisible public list<wrapContact> wrapContactList {get; set;} 
    public list<Contact> selectedContacts {get; set;}
    public integer totalRecs = 0;
    public integer index =0;
    public integer blockSize = 100; 
    public integer NoOfRecords = 1;
    public integer TotalPages;
    public integer sizeOfStartIndex;

    public AddContacttoAttributedCampaign(ApexPages.StandardController stdController)
  {
        this.attc = (AttributedCampaign__c)stdController.getRecord();
        attid =ApexPages.currentPage().getParameters().get('attid'); 
        accid =ApexPages.currentPage().getParameters().get('accid');
        cac = new ContactAttributedCampaign__c();
        attc = new AttributedCampaign__c ();
        for(AggregateResult result :[SELECT COUNT(Id) intVal FROM Contact where AccountId=:accid])
            {
                totalRecs+=(Integer)result.get('intVal');
            }
        TotalPages = totalRecs/blocksize;

        cacList = [Select Name, Attributed_Campaign__c, Contact__c, Include_in_Marketing_Activity__c from ContactAttributedCampaign__c where Attributed_Campaign__c =: attid order by Name];
      system.debug('cacList##'+cacList.size()) ;
      wrapContactList = new list<wrapContact>();
        for (contact c : [Select Id, Name, title, Job_Role__c, Job_Function__c from Contact where AccountId =: accid and Contact_Status__c = 'Active' Order by Name ASC LIMIT : blockSize OFFSET:index ])
        {
            wrapContactList.add(new wrapContact(c));
        }
         sizeOfStartIndex = wrapContactList.size();
  } 
public void beginning()
{   
    wrapContactList.clear();
    NoOfRecords =1;
    index = 0;
    for (contact c : [Select Id, Name, title, Job_Role__c, Job_Function__c from Contact where AccountId =: accid and Contact_Status__c = 'Active' Order by Name ASC LIMIT : blockSize OFFSET:index])
        {
            wrapContactList.add(new wrapContact(c));
        }
   
}

public void previous()
{
 wrapContactList.clear();   
 if(NoOfRecords > 1)
 {
   index = index - blocksize;
 for (contact c : [Select Id, Name, title, Job_Role__c, Job_Function__c from Contact where AccountId =: accid and Contact_Status__c = 'Active' Order by Name ASC LIMIT : blockSize OFFSET:index])         
        {
            wrapContactList.add(new wrapContact(c));
        }
     NoOfRecords=NoOfRecords -1 ;
     
 }
  else
  {
    beginning(); 
  }
}
public void next()
{   
 wrapContactList.clear();
   
    if(NoOfRecords < TotalPages)
    {
                 index = index + blocksize;
               system.debug('index value in last next--' + index);
                for (contact c : [Select Id, Name, title, Job_Role__c, Job_Function__c from Contact where AccountId =: accid and Contact_Status__c = 'Active' Order by Name ASC LIMIT : blockSize OFFSET:index])
                    {
                        wrapContactList.add(new wrapContact(c));
                    }
               // index = index + wrapContactList.size();
               NoOfRecords= NoOfRecords+1;
    }
    else
    {
        
       for (contact c : [Select Id, Name, title, Job_Role__c, Job_Function__c from Contact where AccountId =: accid and Contact_Status__c = 'Active' Order by Name ASC LIMIT : blockSize OFFSET:index])
                    {
                        wrapContactList.add(new wrapContact(c));
                    } 
        
    }
    
}

public void end()
{   
wrapContactList.clear();

if(NoOfRecords <=totalPages)
{index = totalRecs - blocksize;
 
for(contact c : [Select Id, Name, title, Job_Role__c, Job_Function__c from Contact where AccountId =: accid and Contact_Status__c = 'Active' Order by Name ASC LIMIT : blockSize OFFSET:index])
                {  wrapContactList.add(new wrapContact(c));} NoOfRecords = TotalPages;
         
   
}
}
    
public boolean getDisableNext()
{
    if(sizeOfStartIndex < blocksize)
      {
           return true;
       }
      else
       {
           return false;
      }
}


    
}

Public PageReference SavePage() 

        selectedContacts = new list<Contact>();
        Set<Id> cacID = new Set<Id>();
        for(ContactAttributedCampaign__c ca :cacList)
        {
            cacID.add(ca.Contact__c);
        }List<ContactAttributedCampaign__c> insertList = new List<ContactAttributedCampaign__c>();

        
        for(wrapContact wrapobj : wrapContactList){
            
            if(wrapobj.isSelected == true)
            {
                 if(!cacID.contains(wrapobj.conn.Id)){
                   ContactAttributedCampaign__c conac = new ContactAttributedCampaign__c(Attributed_Campaign__c=attid,Contact__c=wrapobj.conn.id,Include_in_Marketing_Activity__c=wrapobj.mark) ;
                   //conac.Attributed_Campaign__c = attid; 
                   //conac.Contact__c = wrapobj.conn.id; 
                   //conac.Include_in_Marketing_Activity__c= wrapobj.mark;
                   insertList.add(conac);
                 //  wrapobj.isSelected =False; 
           }
           
                     for(ContactAttributedCampaign__c item : cacList)
                       {if(item.Contact__c == wrapobj.conn.id && item.Include_in_Marketing_Activity__c != wrapobj.mark)
                           {ContactAttributedCampaign__c conac = [select id,Include_in_Marketing_Activity__c from ContactAttributedCampaign__c where Attributed_Campaign__c = :attid and Contact__c = :wrapobj.conn.id]; conac.Include_in_Marketing_Activity__c = wrapobj.mark; insertList.add(conac);
                             }
                         }
                 } 
            }
            upsert insertList;
            
     cacList = [Select Name, Attributed_Campaign__c, Contact__c, Include_in_Marketing_Activity__c  from ContactAttributedCampaign__c where Attributed_Campaign__c =: attid order by Name desc];
        
        return null;
        }
 
    public PageReference redirectBack(){
        return new PageReference('/'+attid);
    }


   @TestVisible public class wrapContact{
        public Contact conn{get; set;}
        public ContactAttributedCampaign__c cac{get;set;}
        public boolean isSelected {get; set;}
        public Boolean mark{get;set;}

            public wrapContact(Contact c){
                this.conn = c;
                this.isSelected = false;                
            }
            public wrapContact(ContactAttributedCampaign__c d){
                this.cac = d;
                this.isSelected = false;  
                this.mark  = d.Include_in_Marketing_Activity__c;
            }
    }    
}


VF Page - 

<apex:page standardController="AttributedCampaign__c" extensions="AddContacttoAttributedCampaign" showHeader="false" sidebar="false"> 
<apex:form id="frm"> 
    <apex:pageMessages />
    
 <apex:pageBlock title="Added Contacts">
     
   <apex:pageBlockTable value="{!cacList}" var="cac">
      <apex:column headerValue="Name" value="{!cac.Name}"/>
      <apex:column headerValue="Portfolio Suspect" value="{!cac.Attributed_Campaign__c}"/>
      <apex:column headerValue="Contact" value="{!cac.Contact__c}"/>
      <apex:column headerValue="Include in Marketing Activity" value="{!cac.Include_in_Marketing_Activity__c}"/>
   </apex:pageBlockTable> 
</apex:pageBlock>   
 
  <apex:pageBlock title="Add Contact to Portfolio Suspect" id="pb"> 
    <apex:pageMessages />
    
    <apex:pageBlock id="pb2">
    <apex:pageBlockSection columns="1">  
     <apex:outputPanel id="myPanel" layout="">
    <apex:pageBlockTable value="{!wrapContactList}" var="aconl">
        <apex:column >
        <apex:facet name="header">

        </apex:facet>
            <apex:inputCheckbox value="{!aconl.isSelected}" id="inputID"/>

        </apex:column>
        <apex:column headerValue="Name">
        <apex:outputfield value="{!aconl.conn.name}"/>
        </apex:column>
        <apex:column headerValue="Title">
        <apex:outputfield value="{!aconl.conn.Title}"/>
        </apex:column>
        <apex:column headerValue="Job Function">
        <apex:outputfield value="{!aconl.conn.Job_Function__c}"/>
        </apex:column>
        <apex:column headerValue="Job Role">
        <apex:outputfield value="{!aconl.conn.Job_Role__c}"/>
        </apex:column>
        <apex:column headerValue="Include in Marketing Activity">
        <apex:inputCheckbox value="{!aconl.mark}" />
        </apex:column>

    </apex:pageBlockTable>
</apex:outputPanel>
    </apex:pageBlockSection>  
    </apex:pageBlock>
    <apex:pageBlockButtons >      
        <apex:commandButton id="addContact" value="Add" action="{!SavePage}" style="align:center;"/>
        <apex:commandButton value="First Page" action="{!beginning}" disabled="{!DisableNext}" reRender="myPanel" />
        <apex:commandButton value="Next" action="{!next}" disabled="{!DisableNext}"   reRender="myPanel" />
         <apex:commandButton value="Prev" action="{!previous}" disabled="{!DisableNext}"   reRender="myPanel"/>
        <apex:commandButton value="Last Page" action="{!end}"  disabled="{!DisableNext}"  reRender="myPanel"/>
        <apex:commandButton id="redirectBack" value="Done" action="{!redirectBack}"/>
        <apex:commandLink action="{!getPageNumbers}" value="P1" rerender="pb"/> 
       
    </apex:pageBlockButtons>
    </apex:pageBlock>     

</apex:form>
</apex:page>

Output - 

User-added image
I have to write an trigger which will do -

When an campaign is added to opportunity ( from campaign influence related list "Add to compaign" button), then if that opportunity has no already existing campaigns(means that campaign is the first one) then make that campaign primary campaign autometically ( if user forget to check primary campaign source checkbox). If user has checked primary campaign source checkbox then nothing to do.

I am not sure on which object i have to write trigger. What will be the trigger. Completely have no idea on this Opp Campaign relationship. Please help me to write trigger.
 Create a batch which looks at all active Opportunities and IF there is only one campaign and the Primary Campaign Acitivity is not checked, check it. There should be no active Opps with Campaigns that do not have a Primary campaign checked.

Basically i have to look all existing opp if there is any opp having only single Campaign records and Primary campaign activity is not checked then i have to check.

I have no idea of Opp and campaign relationship. Please let me know how i can do this.
trigger AssignCloseOppTeamMember on OpportunityTeamMember (after insert) {
List<Opportunity> OpportunityList = new List<Opportunity>();
Map<Id, Id> OppIdOppMemberIdMap = new Map<Id, Id>();

for(OpportunityTeamMember OpportunityTeamMemberObj: Trigger.New){
    if(OpportunityTeamMemberObj.TeamMemberRole =='Portfolio Developer')
    
        OppIdOppMemberIdMap.put(OpportunityTeamMemberObj.OpportunityId , OpportunityTeamMemberObj.Id);
}

for(Opportunity opportunityObj : [Select Id, LocalPortfolioDeveloper__c from Opportunity where Id IN: OppIdOppMemberIdMap.keyset()]){
    if(OppIdOppMemberIdMap.Containskey(opportunityObj.Id)){
        opportunityObj.LocalPortfolioDeveloper__c= OppIdOppMemberIdMap.get(opportunityObj.Id).User.Id;
        OpportunityList.add(opportunityObj);
        }
    }
update OpportunityList;

}
getting error - Compile Error: Initial term of field expression must be a concrete SObject: Id at line 13 column 95