function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kitsunebravekitsunebrave 

Cloning issue of Custom Object and Opportunity with Partners

hi,
I have a custom clone button from a Support Order custom detail page and I am retrieving an Opportunity with Partners to clone a new support order with a new Opportunity using profile different than Sys Administrator such as New Profile without Sys Admin permission setting eg: below

1. Ventyx Finance/Accounting (it is not a sys admin)
2. Ventyx Finance/Accounting Manage with report (it is not a sys admin)

I am getting a error message Is Invalid field IsPrimary from the standard Partner object in salesforce.com. This field seems like any not sys admin does not have access to that object to be cloned.

Also I tried changing the Organization Wide-Default OWD and that did not avoid the error. It seems like I do not have visiable Partner object setting to add spefici permission set to partner fields such as Primary or Active or wherever salesforce does not provide User Interface to make those changes.

There is a work around to avoid this issue and sucessfully clone a Partner record? Please help me with this problem.
Thanks.
Debug log output:
15:15:52.27 (1287536739)|USER_DEBUG|[503]|DEBUG|>>>>>>saveFunctionality ExceptionInvalid field IsPrimary
15:15:52.27 (1287581051)|USER_DEBUG|[504]|DEBUG|>>>>>>saveFunctionality Exceptionnull
15:15:52.27 (1287611412)|USER_DEBUG|[505]|DEBUG|>>>>>>saveFunctionality Exception597
15:15:52.27 (1287634702)|USER_DEBUG|[506]|DEBUG|>>>>>>saveFunctionality ExceptionClass.SupportOrder_ManualCloneController.insertOpp: line 597, column 1
Class.SupportOrder_ManualCloneController.saveFunctionality: line 210, column 1
Class.SupportOrder_ManualCloneController.save: line 160, column 1
15:15:52.27 (1287815984)|USER_DEBUG|[507]|DEBUG|>>>>>>saveFunctionality ExceptionSystem.SObjectException
15:15:52.27 (1287946803)|VF_PAGE_MESSAGE|Invalid field IsPrimary null 597 Class.SupportOrder_ManualCloneController.insertOpp: line 597, column 1
Class.SupportOrder_ManualCloneController.saveFunctionality: line 210, column 1
Class.SupportOrder_ManualCloneController.save: line 160, column 1 System.SObjectException
following is a code portion when the error message display as well as the screenshot with the error.
for(Integer i=0;i<lstOPT.size();i++){
            if (lstOPT.get(i).IsPrimary != null) {
                System.debug('>>>>>>>Manual Clone: '+lstOPT.get(i).IsPrimary);
                Partner opt2 = new Partner();
                Boolean primary = OpportunityPartner.IsPrimary.getDescribe().isUpdateable();
                System.debug('Manual Clone Partner Describe field: '+primary);
                Boolean creatable = true;
                opt2.IsPrimary = lstOPT.get(i).IsPrimary;
                //opt2.AccountFromId = opt.AccountFromId;
                opt2.AccountToId = lstOPT.get(i).AccountToId;
                opt2.OpportunityId = opp.Id;       
                opt2.Role = lstOPT.get(i).Role; 
            
                newLstOPT.add(opt2);
            }   
        }
        if (!newLstOCR.isEmpty()) {
            insert newLstOCR;
        }
        
        if (!newLstOPT.isEmpty()) {
            insert newLstOPT;
        }
        upsert opp;
        return opp.Id;
    }

IsPrimary exception