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
uHaveOptionsuHaveOptions 

Button action won't work on different profile

We created a convert button that will convert from one object to another.  It works on Administrator profile but wont work on other profile.  I enabled all APEX Classes Access and Visualforce Page Access but it still doesnt work.  Any work around you can think of? 

what I've done
- redo the APEX
- recreate the VF Page

 

APEX CLASS
public class ControllerProposalConvertView {
    public Id pId;
    public String convertedAccountId;

    public ControllerProposalConvertView(ApexPages.StandardController stdController){
        pId = ApexPages.CurrentPage().getParameters().get('id');
        System.Debug('#######leadId:' + pId);
    }


    public PageReference convert(){

        try{
        Proposal__c p = [SELECT Id, name, Already_Converted__c, Property__c, Square_Footage__c, Lot_Size__c, Lot__c, Cap_Rate__c, Term__c, NOI__c, Lease_Commencement_Date__c, Rent_Commencement_Date__c, Lease_Expiration_Date__c, Years_Remaining__c, Lease_Notes__c, Gross_Leasable_Area__c, Options__c, Original_Lease_Term__c, Suggested_List_Price__c, Broker_Relationship__c, Broker_Relationship2__c, Commission__c, Escrow_Fees__c, Existing_Debt_Retirement__c, Pre_Payment_Penalty__c, Title_Fees__c, Transfer_Tax__c FROM Proposal__c WHERE Id=:pId LIMIT 1];
        
        if (p.Already_Converted__c  =='Not Converted'){
        Listing__c c=new Listing__c(Name=p.Name, Property__c=p.Property__c, Square_Footage__c=p.Square_Footage__c,  Lot_Size__c=p.Lot_Size__c, Lot__c=p.Lot__c, Cap_Rate__c=p.Cap_Rate__c, Term__c=p.Term__c, NOI__c=p.NOI__c, Lease_Commencement_Date__c=p.Lease_Commencement_Date__c, Rent_Commencement_Date__c=p.Rent_Commencement_Date__c, Lease_Expiration_Date__c=p.Lease_Expiration_Date__c, Years_Remaining__c=p.Years_Remaining__c, Lease_Notes__c=p.Lease_Notes__c,Gross_Leasable_Area__c=p.Gross_Leasable_Area__c,Options__c=p.Options__c,Original_Lease_Term__c=p.Original_Lease_Term__c,Suggested_List_Price__c=p.Suggested_List_Price__c,Broker_Relationship__c=p.Broker_Relationship__c, Broker_Relationship2__c=p.Broker_Relationship2__c,Commission__c=p.Commission__c, Escrow_Fees__c=p.Escrow_Fees__c,Existing_Debt_Retirement__c=p.Existing_Debt_Retirement__c,Pre_Payment_Penalty__c=p.Pre_Payment_Penalty__c,Title_Fees__c=p.Title_Fees__c,Transfer_Tax__c=p.Transfer_Tax__c);

        System.Debug('#######c :' + c );
        insert c;
        p.Already_Converted__c='Converted';
       update p;
        convertedAccountId = c.Id;
        System.Debug('#######convertedAccountId :' + convertedAccountId );
        }
        
        else{
                String sServerName = ApexPages.currentPage().getHeaders().get('Host');
        sServerName = 'https://'+sServerName+'/';
        PageReference retPage = new PageReference(sServerName + '/apex/ProposalConvertView2?id='+ pId); 
        retPage.setRedirect(true);
        System.Debug('#######ALREADYCONVERTED' );
        
        return retPage;
        }
        
        }
        
        catch(Exception e){
            System.Debug('#######Error  - Exception [' + e.getMessage() + ']');
            return null;
        }
        String sServerName = ApexPages.currentPage().getHeaders().get('Host');
        sServerName = 'https://'+sServerName+'/';
        System.Debug('#######sServerName :' + sServerName );
        PageReference retPage = new PageReference(sServerName + convertedAccountId); 
        System.Debug('#######retPage :' + retPage );
        retPage.setRedirect(true);


        return retPage;
    } 
    public PageReference back(){
            String sServerName = ApexPages.currentPage().getHeaders().get('Host');
        sServerName = 'https://'+sServerName+'/';
        System.Debug('#######sServerName :' + sServerName );
        PageReference retPage = new PageReference(sServerName + pId); 
        System.Debug('#######retPage :' + retPage );
        retPage.setRedirect(true);
        
        return retPage;
    }      
}


VF PAGE 1

<apex:page standardController="Proposal__c" extensions="ControllerProposalConvertView"> <apex:outputPanel layout="block" style="font-weight:bold"> You are about to convert this proposal to a listing. Are you sure you want to do this? </apex:outputPanel> <apex:form > <apex:commandButton action="{!convert}" value="OK" id="OK" rerender="hiddenBlock"/> <apex:commandButton action="{!back}" value="Cancel" id="Cancel" /> </apex:form> <apex:outputPanel layout="block" style="font-weight:bold"></apex:outputPanel> </apex:page>

VF PAGE 2

<apex:page standardController="Proposal__c" extensions="ControllerProposalConvertView"> <apex:outputPanel layout="block" style="font-weight:bold; color:red;"> This proposal has already been converted to a listing. Please click the button below to return to your proposal. </apex:outputPanel> <apex:form > <apex:commandButton action="{!back}" value="Back" id="Cancel"/> </apex:form> </apex:page>

Hope this help for visuals
 

Best Answer chosen by uHaveOptions
ProlayProlay
Where are you assigning pid variable to the corresponding ID? Please check the code

All Answers

ProlayProlay
Did you check whether the profiles other than System Admin have the read access to Proposal and Listing objects? 
uHaveOptionsuHaveOptions
@Prolay Yes.  Custom Object Permission is fully enabled.  
ProlayProlay
Instead of String can you declare the 
ID convertedAccountId = NULL;

Then check whether is it getting redirected or not.
ProlayProlay
Where are you assigning pid variable to the corresponding ID? Please check the code
This was selected as the best answer
uHaveOptionsuHaveOptions
We figured out the issue.  One of the field is not matching to the convert of another field.  We ran a debug and saw the issue from there.  Thanks.