0

I've created a custom object called Close Plan Contact Role (CPCR). My plan is to use a scheduled apex class to periodically move data from Opportunity Contact Role (OppCR) and into CPCR every hour. My code is below. Can someone please help fix what's wrong?

public class addOppCRtoCPCR {

    public addOppCRtoCPCR() {

        Map<Id,String> OppCRlMap = new Map<Id,String>();

        // Query all Close Plan contact roles.

        List<Close_Plan_Contact_Role__c> CPCRList     = [ SELECT id, Contact__c, IsDeleted__c, IsPrimary__c, Opportunity__c, Role__c
                                                          FROM Close_Plan_Contact_Role__c ];

        // Query all Opportunity contact roles. Place them in a list
        List<OpportunityContactRole> OppCRlist      = [ SELECT id, ContactId, IsDeleted, IsPrimary, OpportunityId, Role
                                                        FROM OpportunityContactRole ];

                            /* ADD MISSING RECORDS FROM OppCRlist to CPCRList */

        // If OppCRlist is larger than CPCRList, add missing contacts to CPCRList
        if(OppCRlist.size() > CPCRList.size()){            

            for(Integer i = 0; i < OppCRlist.size(); i++ ){
                OppCRlMap.put(OppCRlist.id, 'NoValue');
            }

            // Loop through OppCRlist
            for(Close_Plan_Contact_Role__c CPCR : CPCRList){

                if(!OppCRlMap.contains(CPCR)){

                    // Create a new Close_Plan_Contact_Role__c record
                    <Close_Plan_Contact_Role__c> CPCRrecord = new <Close_Plan_Contact_Role__c>();

                    // populate Close_Plan_Contact_Role__c fields
                    CPCRrecord.Contact__c       = CPCR.ContactId;
                    CPCRrecord.IsDeleted__c     = CPCR.IsDeleted;
                    CPCRrecord.IsPrimary__c     = CPCR.IsPrimary;
                    CPCRrecord.Opportunity__c   = CPCR.OpportunityId;
                    CPCRrecord.Role__c          = CPCR.Role;

                    // Add new record to set
                    CPCRList.add(CPCRrecord);
                }
            }
        insert CPCRList;
        }
    }
}
2
  • What IS Wrong? It would be extremely helpful if you could let us know so we do not have to spend a lot of time looking for issues that may not even be what you are asking about. Also good to review How to Ask
    – Eric
    Jan 19, 2017 at 18:41
  • Everything looks right to me, but SFDC keeps giving generic errors like: Error: Compile Error: expecting right curly bracket, found '<' at line 30 column 20
    – Rock Tober
    Jan 19, 2017 at 18:53

1 Answer 1

3

Your issue is here:

<Close_Plan_Contact_Role__c> CPCRrecord = new <Close_Plan_Contact_Role__c>();

Should be:

Close_Plan_Contact_Role__c CPCRrecord = new Close_Plan_Contact_Role__c();

Not sure why you thought the < > were needed

2
  • total brain fart on my part.
    – Rock Tober
    Jan 19, 2017 at 18:58
  • 1
    it happens to all of us
    – Eric
    Jan 19, 2017 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.