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
Pedro PaivaPedro Paiva 

I would like to use Role values from OpportunityContactRole in a Custom Object

It is possible to use the Role picklist values (which are dinamycally set by the user) from the OpportunityContactRole standard object in a new Custom Object ? I was thinking in having a custom object with a text field named: Role__c and in a Visualforce page having a SelectList with SelectOptions to use the picklist retrieving by the apex controller, but my list is blank:

This is my Apex Controller:
 
public class OppContactRoleController  {

	public List<OppContactRole__c> oppContactRoles {get; private set;}
	public List<SelectOption> pickListValuesList {get; set;}
	public String strSelected  {get;set;}

	public OppContactRoleController(ApexPages.StandardController stdController) {
		Id oppId = stdController.getId();
		strSelected = 'None';
        oppContactRoles = (oppId == null) ? new List<OppContactRole__c>() : 
            [SELECT Id, Role__c, isPrimary__c,Contact__c,Contact__r.Name,Opportunity__c FROM OppContactRole__c WHERE Opportunity__c = :oppId];
		List<SelectOption> pickListValuesList= new List<SelectOption>();
		Schema.DescribeFieldResult fieldResult = OpportunityContactRole.Role.getDescribe();
		List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
		for( Schema.PicklistEntry pickListVal : ple){
			//pickListValuesList.add(pickListVal.getLabel());
			pickListValuesList.add( new SelectOption(pickListVal.getLabel(), pickListVal.getLabel()));
		}
		System.debug('[OppContactRoleController] :: pickListValuesList '+pickListValuesList);  
	}

	public List<SelectOption> getItems(){
		return this.pickListValuesList;
	}

	public PageReference customSave() {
		System.debug('[OppContactRoleController] :: custom saver');
		try {
            upsert(oppContactRoles);
        } catch(System.DMLException e) {
            ApexPages.addMessages(e);
            return null;
        }
        //  After successful Save, navigate to the default view page
        //PageReference redirectSuccess = new ApexPages.StandardController(Opportunity).view();
        return null;
	}

}

And this is my VF page:
 
<apex:page standardController="Opportunity"  extensions="OppContactRoleController">
    <apex:form >
        <apex:pageBlock >
            <apex:pageMessages />
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!customSave}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!oppContactRoles}" var="ocr">
                <apex:column value="{!ocr.Contact__r.Name}"/>
                <apex:column headerValue="Role">
                    <apex:selectList value="{!ocr.Role__c}">
                        <apex:selectOptions value="{!items}"/>
                    </apex:selectList>
                </apex:column>
                <apex:column headerValue="Primary">
                    <apex:inputField value="{!ocr.isPrimary__c}"/>
                </apex:column>
            </apex:pageBlockTable>      
        </apex:pageBlock>
    </apex:form>
</apex:page>
Is there a different way to do this and what i'm doing wrong here ? 

Thank for any help in advance.