1

In no way am I a developer, but our SalesForce developer quit so I (an admin) have to add this functionality.

Before the developer quit, he created an Export Compliance page, so when the user clicks on an opportunity it will take them to an APEX page and ask the user questions and the user will answer yes or no if the opportunity complies. What I'm wanting to do is have the administrator profiles be excluded from this Export Compliance. I imagine I would have some kind of 'If statement' that looks a the system administrator profile?

Also, there are 3 apex classes that has to do with Export Compliance. ExportCheckApproval, ExportCheckMasterHandler, ExportCheckPageController so I'm not really sure where I should add the code either.

Here's the code from ExportCheckPageController:

 PageReference pr1;

        if(opp.RecordTypeId == sgiRT || opp.RecordTypeId == apacRT){
        if(!opp.isExportCompleted__c && exportCheck.Id == null){
            pr1 = new PageReference('/apex/ExportCheckPage1?oppId='+ opp.Id);
            pr1.setRedirect(true); 
        }
    }
    else{
        pr1 = new PageReference('/' + opp.id);
        pr1.getParameters().put('nooverride', '1');
    }
    return pr1;





 PageReference pr;

    if((UserInfo.getuserId() == opp.ownerid) &&
        (opp.RecordTypeId == sgiRT || opp.RecordTypeId == apacRT)){
            //if(!opp.isExportCompleted__c && exportCheck.Id == null){
                    pr = new PageReference('/apex/ExportCheckPage1?oppId='+ opp.Id);
                    pr.setRedirect(true); 
            //}
            }
    else{
    pr = new PageReference('/' + opp.id);
    pr.getParameters().put('nooverride', '1');
        }

    return pr; 

Thank you so much in advance!

2
  • Hi Matt and welcome to SFSE. One way you could do this would be to query for profiles where the name is not equal to "Administrator". The 3 classes you've told us are custom (meaning your Dev wrote them), so we'd at least need to know what was in them to help. Personally though, I'd advise your employer you're not a developer and simply aren't trained in this particular skillset. At least, that's what it sounds like!
    – Dan Jones
    Jan 13, 2016 at 16:25
  • Hi Poet, thank you for your reply. I realize I'm not trained for this skill set but have some coding experience so I thought I'd try and tackle the issue. I can read code decently and understand most of it, but syntax kills me. I've update the post if you would like to look at the Controller's code where I think you would handle all the queries for the user information.
    – Matt
    Jan 13, 2016 at 16:56

1 Answer 1

0

It seems like you have a action method define in your visualforce page which call your redirect method which check and redirect for compliance page so put following code inside your redirect method

public PageReference redirect(){
//*************get the sys admin id***************
Id SYS_ADMIN_PROFILE_ID = [select ProfileId 
             from User 
             where Profile.Name = 'System Administrator'].ProfileId
    PageReference pr;
    if((UserInfo.getProfileId() != SYS_ADMIN_PROFILE_ID) &&
    (opp.RecordTypeId == sgiRT || opp.RecordTypeId == apacRT)){
        if(!opp.isExportCompleted__c && exportCheck.Id == null){
            pr = new PageReference('/apex/ExportCheckPage1?oppId='+ opp.Id);
            pr.setRedirect(true); 
        }
    }
    else{
        pr = new PageReference('/' + opp.id);
        pr.getParameters().put('nooverride', '1');
    }
    return pr;
}  

if you have multiple system administrator custom profile.

String Profilename = [select Name from profile where id=:UserInfo.getProfileId()]

if(!Profilename.tolowercase().contains('admin') &&
    (opp.RecordTypeId == sgiRT || opp.RecordTypeId == apacRT)

if you have opportunity owner

if(UserInfo.getuserId()== opp.ownerid &&
    (opp.RecordTypeId == sgiRT || opp.RecordTypeId == apacRT)
14
  • 1
    Those Admin profiles could be custom profiles and there could be several of them depending on the size of the org. So, he may need to query for multiple profile names which will return a list of Ids. He'll then need to adjust your code accordingly.
    – crmprogdev
    Jan 13, 2016 at 18:24
  • yes I agree. I have only given the start point to him with best case scenario. @crmprogdev
    – Himanshu
    Jan 13, 2016 at 19:22
  • thank y'all so much. I assume I would just add the custom system admin profiles by adding 'or' statements?
    – Matt
    Jan 13, 2016 at 19:56
  • check the updated answer. @Matt
    – Himanshu
    Jan 13, 2016 at 20:07
  • @Himanshu sorry to keep changing the requirements but when I got the code working my boss changes the requirements :( It's of going off profile name he just wants users that are 'opportunity owners' to see the compliance page. how would I go about that?
    – Matt
    Jan 14, 2016 at 20:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .