• Long Truong
  • NEWBIE
  • 30 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 17
    Replies

I wrote a trigger so that when the Account Name is updated, the Subgrantee Profile (custom object, linked by look up relationship) Name is also updated.

For example: Account name is ABC, and Subgratee Profile name is 123-ABC. When the Account name is updated to EFG, Subgrantee Profile name should become 123-EFG.

I checked the debug pritn out, and all the values is as it should be, but the new name for the subgrantee profile is not being save???

trigger updateAcountNameonSubProfile on Account(after update)
    {
    for (Account a:Trigger.new)
    {
        try
        {   
//select the related Subgrantee Profile
            List<Subgrantee_Profile__c> lstRR=[Select r.Id,r.Name, r.Subgrantee__c from  Subgrantee_Profile__c r where r.Subgrantee__c in : Trigger.newMap.keyset()];
            system.debug('>>>list size: '+lstRR.size());
            for(Subgrantee_Profile__c objRR : lstRR)
   {
                system.debug('>>>updating this sub profile:'+objRR.name);
                if(Trigger.newMap.containskey(objRR.Subgrantee__c) )
                objRR.Name=Trigger.newMap.get(objRR.Subgrantee__c).Mailing_State__c + Trigger.newMap.get(objRR.Subgrantee__c).Associated_Project_Number__c+' - '+Trigger.newMap.get(objRR.Subgrantee__c).Name;
                system.debug('>>>New subgrantee profile name:'+objRR.Name);
            }
            update lstRR;
//the new name is correct, but the record in Salesforce is not updated????           
 System.debug('>>>after updating list - new sub profile name: '+ lstRR.get(0).name  );
        }catch(Exception ex)
        {
            Trigger.new[0].addError('Error in resource request updates --'+ ex.getMessage());
        }
    }
    }

I copy and paste this sample code from Salesforce into the execute anonymous, but I get this error:

Line: 4, Column: 34
Only top-level class methods can be declared static

Why would a sample code from Salesforce not work? Thanks!

@isTest
                    
private class TestRunAs {
   public static testMethod void testRunAs() {
      // Setup test data
      // This code runs as the system user
      Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
      User u = new User(Alias = 'standt', Email='standarduser@testorg.com', 
      EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
      LocaleSidKey='en_US', ProfileId = p.Id, 
      TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@testorg.com');

      System.runAs(u) {
         // The following code runs as user 'u' 
         System.debug('Current User: ' + UserInfo.getUserName());
         System.debug('Current Profile: ' + UserInfo.getProfileId()); 
      }
   }
}

 
I have a custom object (contact request form ), and when you click the "Search Contact" button, it takes you to a VF page. When I use it as an internal Salesforce user, everything works fine. When I use it as a portal user , it used to work fine, but now the page keep loading and loading. When you click the "x" button on the browser, and click the "Search contact" button again, it works. What is wrong here? Thanks!
I have this wrapper class with 68% code coverage. Below is the class and the test class. Could some one please help me increase the code coverage? Thanks!
public with sharing class CRequestForm_Wrapper {
    
    public List<ContactReq> wrapperList {get;set;}
    public Contact cContact=new Contact();
    public Contact_Request_Form__c cRForm=new Contact_Request_Form__c();
    public Contact_Request_Form__c cRFormNotes {get;set;}
    public boolean errormsg=false;
    public boolean ApprovalFormShowChangeDetails {get;set;}
    public String errorDetail='';
    
    public Boolean isPartnerSubgrantee {get;set;}
    public Boolean noRoleFound {get;set;}
    public List<SelectOption> subgranteeRolesList {get;set;}
    public List<SelectOption> partnerProfilesList {get;set;}
    

    public CRequestForm_Wrapper(ApexPages.StandardController controller)
    {
      String id=ApexPages.currentPage().getParameters().get('cid');
      if(id!=null)
      {
          cContact=[select Id,LastName,FirstName,MI__c,Fax,MobilePhone,HomePhone,OtherPhone,Email,Title,Department,Contact_Mailing_Street_1__c ,Contact_Mailing_Street_2__c
                            ,Contact_Mailing_City__c ,Contact_Mailing_Zip_Code__c ,SSAI_Sponsors__c,SSAI_Directors__c,
                            SSAI_Fiscals__c,D2D_Contacts__c,Contact_Shipping_Street_1__c, SSAI_SCSEP_Role__c
                            ,Contact_Shipping_Street_2__c ,Contact_Shipping_City__c ,Contact_Shipping_Zip_Code__c ,
                            Contact_Fax__c , Contact_Mailing_State__c ,Contact_Shipping_State__c,Shipping_Organization__c,Mailing_Organization__c,Shipping_Department__c,AccountId from Contact where id =:id limit 1];
                          wrapperList=new List<ContactReq>();
                            
          wrapperList.add(new ContactReq( NewCRequest(cContact), cContact));
          
      }
      String cRid=ApexPages.currentPage().getParameters().get('id');
      if(cRid!=null)
      {
        cRForm=[select Id, Subgrantee_Name__c, Subgrantee_Name__r.IsPartner,Last_Name__c,First_Name__c,MI__c, SSAI_SCSEP_Role__c,
                    Fax_Phone__c, Mobile_Phone__c, Home_Phone__c, Business_Phone__c,
                    Email_Address__c, Job_Title__c, Department_B__c, Department_S__c,
                    Organization_S__c, Organization_B__c,
                    Address_Line_1B__c, Address_Line_2B__c, City_B__c, Zip_Code_B__c, Business_State__c,
                    SSAI_Fiscal__c, SSAI_Spon__c, SSAI_Directors__c, D2D_Contacts__c,
                    Address_Line_1S__c, Address_Line_2S__c, City_S__c, Zip_Code_S__c, Shipping_State__c,
                    Notes__c, Is_Create_User__c, Role__c, Profile__c, Contact__c, Forms_and_Information__c,Pay_by_Pay__c,Report_of_Costs_SA1_and_SA2__c,Salesforce_Portal_Account__c,SCSEP_Eligibility_Determination__c, SPARQ__c,Is_Delete_Request__c from Contact_Request_Form__c where id =:cRid limit 1];
        cRFormNotes=cRForm;
    
        if(CRFormNotes.Subgrantee_Name__c!=null && CRFormNotes.Contact__c==null)
        {
            ApprovalFormShowChangeDetails = false;
            isPartnerSubgrantee = CRFormNotes.Subgrantee_Name__r.IsPartner;
            noRoleFound = false;
            subgranteeRolesList = getPartnerRoles(CRFormNotes.Subgrantee_Name__c);
            partnerProfilesList = getPartnerProfiles();
        }
        else{
            ApprovalFormShowChangeDetails = true;
            cContact=[select Id,LastName,FirstName,MI__c,Fax,MobilePhone,HomePhone,OtherPhone,Email,Title, SSAI_SCSEP_Role__c,Department,Contact_Mailing_Street_1__c ,Contact_Mailing_Street_2__c
                        ,Contact_Mailing_City__c ,Contact_Mailing_Zip_Code__c ,SSAI_Sponsors__c,SSAI_Directors__c,
                        SSAI_Fiscals__c,D2D_Contacts__c,Contact_Shipping_Street_1__c 
                        ,Contact_Shipping_Street_2__c ,Contact_Shipping_City__c ,Contact_Shipping_Zip_Code__c ,
                        Contact_Fax__c , Contact_Mailing_State__c ,Contact_Shipping_State__c,Shipping_Organization__c,Mailing_Organization__c,Shipping_Department__c,AccountId from Contact where id =:CRFormNotes.Contact__c limit 1];
            wrapperList=new List<ContactReq>();
                        
            wrapperList.add(new ContactReq( cRFormNotes, cContact));
        }
      }
                                       
    }
    
    public Contact_Request_Form__c NewCRequest(Contact cContact)
    {
        
        System.debug('Inside shree');
        Contact_Request_Form__c  c  = new Contact_Request_Form__c();
            c.Subgrantee_Name__c    =cContact.AccountId;                    
            c.Last_Name__c          =cContact.LastName ;
            c.First_Name__c         =cContact.FirstName ;
            c.MI__c                 =cContact.MI__c ;
            
            c.Fax_Phone__c          =cContact.Fax ;
            c.Mobile_Phone__c       =cContact.MobilePhone; 
            c.Home_Phone__c         =cContact.HomePhone ;
            c.Business_Phone__c     =cContact.OtherPhone ;
            
            c.Email_Address__c      =cContact.Email ;
            c.Job_Title__c          =cContact.Title; 
            c.SSAI_SCSEP_Role__c    =cContact.SSAI_SCSEP_Role__c;
            c.Department_B__c       =cContact.Department;
            c.Department_S__c       =cContact.Shipping_Department__c;
            
            c.Organization_S__c     =cContact.Shipping_Organization__c;
            c.Organization_B__c     =cContact.Mailing_Organization__c;
                    
            
            c.Address_Line_1B__c    =cContact.Contact_Mailing_Street_1__c;  
            c.Address_Line_2B__c    =cContact.Contact_Mailing_Street_2__c ; 
            c.City_B__c             =cContact.Contact_Mailing_City__c ; 
            c.Zip_Code_B__c         =cContact.Contact_Mailing_Zip_Code__c ; 
            c.Business_State__c     =cContact.Contact_Mailing_State__c  ;
            
            c.SSAI_Fiscal__c        =cContact.SSAI_Fiscals__c  ;
            c.SSAI_Spon__c          =cContact.SSAI_Sponsors__c  ;
            c.SSAI_Directors__c     =cContact.SSAI_Directors__c  ;
            c.D2D_Contacts__c       =cContact.D2D_Contacts__c  ;
            
            c.Address_Line_1S__c    =cContact.Contact_Shipping_Street_1__c;  
            c.Address_Line_2S__c    =cContact.Contact_Shipping_Street_2__c ; 
            c.City_S__c             =cContact.Contact_Shipping_City__c  ;
            c.Zip_Code_S__c         =cContact.Contact_Shipping_Zip_Code__c;  
            c.Shipping_State__c     =cContact.Contact_Shipping_State__c  ;
            
            //c.Fax_Phone__c        =cContact.Contact_Fax__c  ;
            c.Fax_Phone__c          =cContact.Fax  ;
            c.Contact__c            =cContact.Id;
            c.Notes__c              ='';
            
            return c;
        
        
    }
    public boolean geterrormsg()
    { 
        return errormsg;
    }
    public String geterrorDetail()
    { 
        return errorDetail;
    }

    public class ContactReq{
        
        public Contact_Request_Form__c CReq{get;set;}
        public Contact c{get;set;}

         public ContactReq(Contact_Request_Form__c CReq , Contact c)
        {
            this.CReq = CReq;
            this.c = c;
        }

    
    }
    
    public Pagereference Save()
    {        
        Pagereference p =new Pagereference('/a02/o');
        Contact_Request_Form__c  NewContactRequest= wrapperList[0].CReq;
        NewContactRequest.Status__c='New';
        List <String> checkStatus=new List<string>() ;
        checkStatus.add('New');
        checkStatus.add('Submitted');
        List<Contact_Request_Form__c> ExistingCRform=[select Id,Subgrantee_Name__c,Email_Address__c,Status__c from Contact_Request_Form__c where 
                                                        Email_Address__c =:NewContactRequest.Email_Address__c 
                                                        and Subgrantee_Name__c =:NewContactRequest.Subgrantee_Name__c 
                                                        and Status__c IN :checkStatus limit 1];
        if(ExistingCRform.size()!=0)
        {
            errorDetail='Contact Request Form with status [ '+ExistingCRform[0].Status__c +']already exists for the email id ['+ExistingCRform[0].Email_Address__c+']and Sub-Garentee['+ExistingCRform[0].Subgrantee_Name__c+']';
            errormsg=true;     
            return null;
        }
        else
        {
            insert NewContactRequest;
            return p;
        }
    } 
    
    public Pagereference Submit()
    {        
        Pagereference p =new Pagereference('/a02/o');
        Contact_Request_Form__c  NewContact= wrapperList[0].CReq;
        NewContact.Status__c='Submitted';
        upsert NewContact;
        return p;
    } 
    public Pagereference onApprove()
    {        
        if(validate())
        {
            Id CRequestId=ApexPages.currentPage().getParameters().get('id');
            Pagereference p =new Pagereference('/'+CRequestId);
            Contact_Request_Form__c  editCrForm= new Contact_Request_Form__c(Id=CRequestId);
            editCrForm.Status__c='Approved';
            editCrForm.Notes__c=cRForm.Notes__c;
            if(CRForm.IS_Create_User__c && CRFormNotes.Contact__c==null)
            {
                editCRForm.IS_Create_User__c = CRForm.IS_Create_User__c;
                editCRForm.Role__c = CRForm.Role__c;
                editCRForm.Profile__c = CRForm.Profile__c;
            }
            List<RecordType> recordTypeVals= [select Id from RecordType where Name = 'Form Approver' limit 1];
            editCrForm.RecordTypeId=recordTypeVals[0].id;
            upsert editCrForm;
            return p;
        }
        else
        {
            return null;
        }
    } 
    public Pagereference onReject()
    {        
        Id CRequestId=ApexPages.currentPage().getParameters().get('id');
        Pagereference p =new Pagereference('/'+CRequestId);
        Contact_Request_Form__c  editCrForm= new Contact_Request_Form__c(Id=CRequestId);
        editCrForm.Status__c='Rejected';
        editCrForm.Notes__c=cRForm.Notes__c;
        List<RecordType> recordTypeVals= [select Id from RecordType where Name = 'Form Approver' limit 1];
        editCrForm.RecordTypeId=recordTypeVals[0].id;
        upsert editCrForm;
        return p;
    }
    public Pagereference onSubmit()
    {        
        Id CRequestId=ApexPages.currentPage().getParameters().get('id');
        Pagereference p =new Pagereference('/'+CRequestId);
        Contact_Request_Form__c  editCrForm= new Contact_Request_Form__c(Id=CRequestId);
        editCrForm.Status__c='Submitted';
        upsert editCrForm;
        return p;
    } 
    
    public List<selectOption> getPartnerRoles(Id accId)
    {
        List<UserRole> urList = new List<UserRole>();
        List<SelectOption> rolesList = new List<SelectOption>();
        rolesList.add(new SelectOption('','--None--'));
        
        if(isPartnerSubgrantee)
        {
            urList = [Select Id, Name from UserRole where PortalType = 'Partner' and PortalAccountId = :accId];
            if(urList.size()>0)
            {
                for(UserRole ur : urList)
                {
                    rolesList.add(new SelectOption(ur.Id,ur.Name));
                }
            }
            else
            {
                noRoleFound = true;
                //ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'No Role found. The user will be created with default Role'));
            }
        }
        /*else
        {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'No Role found. Please enable the Subgrantee for Partner Portal'));
        }*/

            return rolesList;
    } 
    
    public List<selectOption> getPartnerProfiles()
    {
        List<Profile> prList = new List<Profile>();
        prList = [Select Id, Name from Profile where UserType = 'PowerPartner' and Name != 'Gold Partner User' order by Name];
        
        List<SelectOption> profilesList = new List<SelectOption>();
        profilesList.add(new SelectOption('','--None--'));
        
        if(prList.size()>0)
        {
            for(Profile pr : prList)
            {
                profilesList.add(new SelectOption(pr.Id,pr.Name));
            }
            return profilesList;
        }
        else
        {
            System.debug('No Partner Profile found');
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'No Partner Profile found'));
            return null;
        }
    } 
    
    public Boolean validate()
    {
        System.debug('*****'+CRForm.Is_Create_User__c+'*****'+CRForm.Profile__c+'*****'+CRForm.Role__c);
        if(CRForm.Is_Create_User__c)
        {
            if(noRoleFound && CRForm.Profile__c==null)
            {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please choose a profile'));
                return false;
            }
            else if(!noRoleFound && CRForm.Profile__c==null && CRForm.Role__c==null)
            {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please choose role & profile'));
                return false;
            }
        }
        
        return true;
    }
    
    }

and this is the test class:

@isTest
private class CRequestForm_Wrapper_Test {

    static testmethod void constructor_Test() {
        Test.startTest();
        PageReference pageRef = Page.CRequestModify;
        Test.setCurrentPage(pageRef);
        
        SFDC_IDs__c SSAIIDs = SFDC_IDs__c.getValues('SSAI');
        Id saProfileId = SSAIIDs.System_Administrator_Profile_ID__c;
        
        User sau =
           [select UserRoleId
               from User
               where ProfileId = :saProfileId
               and isActive = true
               limit 1];
        
        System.runAs(sau) {
        
        Account newAcc=new Account(Name='Test Account');
        insert newAcc;
        
        Contact newContact=new Contact();
        newContact.LastName='Last Name';
        newContact.FirstName='First Name';
        newContact.AccountId=newAcc.Id;
        insert newContact;
        
        ApexPages.currentPage().getParameters().put('cid', newContact.Id);
        
        Contact_Request_Form__c newRec1 =new  Contact_Request_Form__c( Contact__c = newContact.Id,Last_Name__c='Last Name Test',First_Name__c='First Name Test',Email_Address__c='TEST2@MAIL.COM',Status__c='Submitted');
        insert newRec1;
        
        ApexPages.currentPage().getParameters().put('Id', newRec1.Id);
        
        ApexPages.StandardController controller = new ApexPages.StandardController(newRec1);
        CRequestForm_Wrapper WrapperC=new CRequestForm_Wrapper(controller);
        
        
        //String nextPage = WrapperC.save().getUrl();
        //System.assertNotEquals(nextPage, '');
        String nextPage = WrapperC.onApprove().getUrl();
        System.assertNotEquals(nextPage, '');
        nextPage = WrapperC.onSubmit().getUrl();
        System.assertNotEquals(nextPage, '');
nextPage = WrapperC.onReject().getUrl();
        
        
        Contact_Request_Form__c newRec2 =new  Contact_Request_Form__c( Contact__c = newContact.Id);
        
        
        ApexPages.currentPage().getParameters().put('Id', newRec2.Id);
        
        ApexPages.StandardController controller2 = new ApexPages.StandardController(newRec2);
        CRequestForm_Wrapper WrapperC2=new CRequestForm_Wrapper(controller2);
        
        
        nextPage = WrapperC2.save().getUrl();
        System.assertNotEquals(nextPage, '');
        }
        
        Test.stopTest();
    }
        

}
 


 

I have a Subgrantee object, and a Subgrantee Profile object, with a master-child relation ship (Subgrantee = master, Subgrantee Profile=child). I want to write a trigger so that:
- when the Name field in Subgrantee is updated
- The Subgrantee Profile name is also update (it's not the same, you have to append something to it)
Thanks
Someone else created a class and test class that works fine: CRequestForm_SearchController and CRequestForm_SearchController_test.
I made some edits to the class in sandbox, and copied the test class, so now I have a new class and a new test class: TESTCRequestForm_SearchController and TESTCRequestForm_SearchController_test. But I can't push it to production because the code coverage is only 68%. I have mannually tested it as an end-user and it works fine. Can anyone please help?
I have created a Custom Object called Subgrantee Profile, using the SubgranteeProfileController. There's a Visuaforce page (let's cal it page 1) that renders the fields under different tabs. I want to clone this Visualforce page into Visualforce page 2, delete some tabs, and assign it to a specific profile A.

I have changed the setting under:
- Profile > Enable Visualforce Page
- changed the Page Layout Assignment
- changed the Security setting of the Visualforce Page 2.

But when I log in as a profile A user, I can only see page 1. The only way I can make page 2 show, is to go Create > Object > Subgrantee Profile > Buttons, Links, and Action > View, and change the content source to page 2. But this change the view to page 2 for ALL profiles, which I don't want.

So in short, my question is: can I assign 2 visualforce pages of the same custom object to different profiles?

Thanks,

I wrote a trigger so that when the Account Name is updated, the Subgrantee Profile (custom object, linked by look up relationship) Name is also updated.

For example: Account name is ABC, and Subgratee Profile name is 123-ABC. When the Account name is updated to EFG, Subgrantee Profile name should become 123-EFG.

I checked the debug pritn out, and all the values is as it should be, but the new name for the subgrantee profile is not being save???

trigger updateAcountNameonSubProfile on Account(after update)
    {
    for (Account a:Trigger.new)
    {
        try
        {   
//select the related Subgrantee Profile
            List<Subgrantee_Profile__c> lstRR=[Select r.Id,r.Name, r.Subgrantee__c from  Subgrantee_Profile__c r where r.Subgrantee__c in : Trigger.newMap.keyset()];
            system.debug('>>>list size: '+lstRR.size());
            for(Subgrantee_Profile__c objRR : lstRR)
   {
                system.debug('>>>updating this sub profile:'+objRR.name);
                if(Trigger.newMap.containskey(objRR.Subgrantee__c) )
                objRR.Name=Trigger.newMap.get(objRR.Subgrantee__c).Mailing_State__c + Trigger.newMap.get(objRR.Subgrantee__c).Associated_Project_Number__c+' - '+Trigger.newMap.get(objRR.Subgrantee__c).Name;
                system.debug('>>>New subgrantee profile name:'+objRR.Name);
            }
            update lstRR;
//the new name is correct, but the record in Salesforce is not updated????           
 System.debug('>>>after updating list - new sub profile name: '+ lstRR.get(0).name  );
        }catch(Exception ex)
        {
            Trigger.new[0].addError('Error in resource request updates --'+ ex.getMessage());
        }
    }
    }
I have a custom object (contact request form ), and when you click the "Search Contact" button, it takes you to a VF page. When I use it as an internal Salesforce user, everything works fine. When I use it as a portal user , it used to work fine, but now the page keep loading and loading. When you click the "x" button on the browser, and click the "Search contact" button again, it works. What is wrong here? Thanks!
I have this wrapper class with 68% code coverage. Below is the class and the test class. Could some one please help me increase the code coverage? Thanks!
public with sharing class CRequestForm_Wrapper {
    
    public List<ContactReq> wrapperList {get;set;}
    public Contact cContact=new Contact();
    public Contact_Request_Form__c cRForm=new Contact_Request_Form__c();
    public Contact_Request_Form__c cRFormNotes {get;set;}
    public boolean errormsg=false;
    public boolean ApprovalFormShowChangeDetails {get;set;}
    public String errorDetail='';
    
    public Boolean isPartnerSubgrantee {get;set;}
    public Boolean noRoleFound {get;set;}
    public List<SelectOption> subgranteeRolesList {get;set;}
    public List<SelectOption> partnerProfilesList {get;set;}
    

    public CRequestForm_Wrapper(ApexPages.StandardController controller)
    {
      String id=ApexPages.currentPage().getParameters().get('cid');
      if(id!=null)
      {
          cContact=[select Id,LastName,FirstName,MI__c,Fax,MobilePhone,HomePhone,OtherPhone,Email,Title,Department,Contact_Mailing_Street_1__c ,Contact_Mailing_Street_2__c
                            ,Contact_Mailing_City__c ,Contact_Mailing_Zip_Code__c ,SSAI_Sponsors__c,SSAI_Directors__c,
                            SSAI_Fiscals__c,D2D_Contacts__c,Contact_Shipping_Street_1__c, SSAI_SCSEP_Role__c
                            ,Contact_Shipping_Street_2__c ,Contact_Shipping_City__c ,Contact_Shipping_Zip_Code__c ,
                            Contact_Fax__c , Contact_Mailing_State__c ,Contact_Shipping_State__c,Shipping_Organization__c,Mailing_Organization__c,Shipping_Department__c,AccountId from Contact where id =:id limit 1];
                          wrapperList=new List<ContactReq>();
                            
          wrapperList.add(new ContactReq( NewCRequest(cContact), cContact));
          
      }
      String cRid=ApexPages.currentPage().getParameters().get('id');
      if(cRid!=null)
      {
        cRForm=[select Id, Subgrantee_Name__c, Subgrantee_Name__r.IsPartner,Last_Name__c,First_Name__c,MI__c, SSAI_SCSEP_Role__c,
                    Fax_Phone__c, Mobile_Phone__c, Home_Phone__c, Business_Phone__c,
                    Email_Address__c, Job_Title__c, Department_B__c, Department_S__c,
                    Organization_S__c, Organization_B__c,
                    Address_Line_1B__c, Address_Line_2B__c, City_B__c, Zip_Code_B__c, Business_State__c,
                    SSAI_Fiscal__c, SSAI_Spon__c, SSAI_Directors__c, D2D_Contacts__c,
                    Address_Line_1S__c, Address_Line_2S__c, City_S__c, Zip_Code_S__c, Shipping_State__c,
                    Notes__c, Is_Create_User__c, Role__c, Profile__c, Contact__c, Forms_and_Information__c,Pay_by_Pay__c,Report_of_Costs_SA1_and_SA2__c,Salesforce_Portal_Account__c,SCSEP_Eligibility_Determination__c, SPARQ__c,Is_Delete_Request__c from Contact_Request_Form__c where id =:cRid limit 1];
        cRFormNotes=cRForm;
    
        if(CRFormNotes.Subgrantee_Name__c!=null && CRFormNotes.Contact__c==null)
        {
            ApprovalFormShowChangeDetails = false;
            isPartnerSubgrantee = CRFormNotes.Subgrantee_Name__r.IsPartner;
            noRoleFound = false;
            subgranteeRolesList = getPartnerRoles(CRFormNotes.Subgrantee_Name__c);
            partnerProfilesList = getPartnerProfiles();
        }
        else{
            ApprovalFormShowChangeDetails = true;
            cContact=[select Id,LastName,FirstName,MI__c,Fax,MobilePhone,HomePhone,OtherPhone,Email,Title, SSAI_SCSEP_Role__c,Department,Contact_Mailing_Street_1__c ,Contact_Mailing_Street_2__c
                        ,Contact_Mailing_City__c ,Contact_Mailing_Zip_Code__c ,SSAI_Sponsors__c,SSAI_Directors__c,
                        SSAI_Fiscals__c,D2D_Contacts__c,Contact_Shipping_Street_1__c 
                        ,Contact_Shipping_Street_2__c ,Contact_Shipping_City__c ,Contact_Shipping_Zip_Code__c ,
                        Contact_Fax__c , Contact_Mailing_State__c ,Contact_Shipping_State__c,Shipping_Organization__c,Mailing_Organization__c,Shipping_Department__c,AccountId from Contact where id =:CRFormNotes.Contact__c limit 1];
            wrapperList=new List<ContactReq>();
                        
            wrapperList.add(new ContactReq( cRFormNotes, cContact));
        }
      }
                                       
    }
    
    public Contact_Request_Form__c NewCRequest(Contact cContact)
    {
        
        System.debug('Inside shree');
        Contact_Request_Form__c  c  = new Contact_Request_Form__c();
            c.Subgrantee_Name__c    =cContact.AccountId;                    
            c.Last_Name__c          =cContact.LastName ;
            c.First_Name__c         =cContact.FirstName ;
            c.MI__c                 =cContact.MI__c ;
            
            c.Fax_Phone__c          =cContact.Fax ;
            c.Mobile_Phone__c       =cContact.MobilePhone; 
            c.Home_Phone__c         =cContact.HomePhone ;
            c.Business_Phone__c     =cContact.OtherPhone ;
            
            c.Email_Address__c      =cContact.Email ;
            c.Job_Title__c          =cContact.Title; 
            c.SSAI_SCSEP_Role__c    =cContact.SSAI_SCSEP_Role__c;
            c.Department_B__c       =cContact.Department;
            c.Department_S__c       =cContact.Shipping_Department__c;
            
            c.Organization_S__c     =cContact.Shipping_Organization__c;
            c.Organization_B__c     =cContact.Mailing_Organization__c;
                    
            
            c.Address_Line_1B__c    =cContact.Contact_Mailing_Street_1__c;  
            c.Address_Line_2B__c    =cContact.Contact_Mailing_Street_2__c ; 
            c.City_B__c             =cContact.Contact_Mailing_City__c ; 
            c.Zip_Code_B__c         =cContact.Contact_Mailing_Zip_Code__c ; 
            c.Business_State__c     =cContact.Contact_Mailing_State__c  ;
            
            c.SSAI_Fiscal__c        =cContact.SSAI_Fiscals__c  ;
            c.SSAI_Spon__c          =cContact.SSAI_Sponsors__c  ;
            c.SSAI_Directors__c     =cContact.SSAI_Directors__c  ;
            c.D2D_Contacts__c       =cContact.D2D_Contacts__c  ;
            
            c.Address_Line_1S__c    =cContact.Contact_Shipping_Street_1__c;  
            c.Address_Line_2S__c    =cContact.Contact_Shipping_Street_2__c ; 
            c.City_S__c             =cContact.Contact_Shipping_City__c  ;
            c.Zip_Code_S__c         =cContact.Contact_Shipping_Zip_Code__c;  
            c.Shipping_State__c     =cContact.Contact_Shipping_State__c  ;
            
            //c.Fax_Phone__c        =cContact.Contact_Fax__c  ;
            c.Fax_Phone__c          =cContact.Fax  ;
            c.Contact__c            =cContact.Id;
            c.Notes__c              ='';
            
            return c;
        
        
    }
    public boolean geterrormsg()
    { 
        return errormsg;
    }
    public String geterrorDetail()
    { 
        return errorDetail;
    }

    public class ContactReq{
        
        public Contact_Request_Form__c CReq{get;set;}
        public Contact c{get;set;}

         public ContactReq(Contact_Request_Form__c CReq , Contact c)
        {
            this.CReq = CReq;
            this.c = c;
        }

    
    }
    
    public Pagereference Save()
    {        
        Pagereference p =new Pagereference('/a02/o');
        Contact_Request_Form__c  NewContactRequest= wrapperList[0].CReq;
        NewContactRequest.Status__c='New';
        List <String> checkStatus=new List<string>() ;
        checkStatus.add('New');
        checkStatus.add('Submitted');
        List<Contact_Request_Form__c> ExistingCRform=[select Id,Subgrantee_Name__c,Email_Address__c,Status__c from Contact_Request_Form__c where 
                                                        Email_Address__c =:NewContactRequest.Email_Address__c 
                                                        and Subgrantee_Name__c =:NewContactRequest.Subgrantee_Name__c 
                                                        and Status__c IN :checkStatus limit 1];
        if(ExistingCRform.size()!=0)
        {
            errorDetail='Contact Request Form with status [ '+ExistingCRform[0].Status__c +']already exists for the email id ['+ExistingCRform[0].Email_Address__c+']and Sub-Garentee['+ExistingCRform[0].Subgrantee_Name__c+']';
            errormsg=true;     
            return null;
        }
        else
        {
            insert NewContactRequest;
            return p;
        }
    } 
    
    public Pagereference Submit()
    {        
        Pagereference p =new Pagereference('/a02/o');
        Contact_Request_Form__c  NewContact= wrapperList[0].CReq;
        NewContact.Status__c='Submitted';
        upsert NewContact;
        return p;
    } 
    public Pagereference onApprove()
    {        
        if(validate())
        {
            Id CRequestId=ApexPages.currentPage().getParameters().get('id');
            Pagereference p =new Pagereference('/'+CRequestId);
            Contact_Request_Form__c  editCrForm= new Contact_Request_Form__c(Id=CRequestId);
            editCrForm.Status__c='Approved';
            editCrForm.Notes__c=cRForm.Notes__c;
            if(CRForm.IS_Create_User__c && CRFormNotes.Contact__c==null)
            {
                editCRForm.IS_Create_User__c = CRForm.IS_Create_User__c;
                editCRForm.Role__c = CRForm.Role__c;
                editCRForm.Profile__c = CRForm.Profile__c;
            }
            List<RecordType> recordTypeVals= [select Id from RecordType where Name = 'Form Approver' limit 1];
            editCrForm.RecordTypeId=recordTypeVals[0].id;
            upsert editCrForm;
            return p;
        }
        else
        {
            return null;
        }
    } 
    public Pagereference onReject()
    {        
        Id CRequestId=ApexPages.currentPage().getParameters().get('id');
        Pagereference p =new Pagereference('/'+CRequestId);
        Contact_Request_Form__c  editCrForm= new Contact_Request_Form__c(Id=CRequestId);
        editCrForm.Status__c='Rejected';
        editCrForm.Notes__c=cRForm.Notes__c;
        List<RecordType> recordTypeVals= [select Id from RecordType where Name = 'Form Approver' limit 1];
        editCrForm.RecordTypeId=recordTypeVals[0].id;
        upsert editCrForm;
        return p;
    }
    public Pagereference onSubmit()
    {        
        Id CRequestId=ApexPages.currentPage().getParameters().get('id');
        Pagereference p =new Pagereference('/'+CRequestId);
        Contact_Request_Form__c  editCrForm= new Contact_Request_Form__c(Id=CRequestId);
        editCrForm.Status__c='Submitted';
        upsert editCrForm;
        return p;
    } 
    
    public List<selectOption> getPartnerRoles(Id accId)
    {
        List<UserRole> urList = new List<UserRole>();
        List<SelectOption> rolesList = new List<SelectOption>();
        rolesList.add(new SelectOption('','--None--'));
        
        if(isPartnerSubgrantee)
        {
            urList = [Select Id, Name from UserRole where PortalType = 'Partner' and PortalAccountId = :accId];
            if(urList.size()>0)
            {
                for(UserRole ur : urList)
                {
                    rolesList.add(new SelectOption(ur.Id,ur.Name));
                }
            }
            else
            {
                noRoleFound = true;
                //ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'No Role found. The user will be created with default Role'));
            }
        }
        /*else
        {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'No Role found. Please enable the Subgrantee for Partner Portal'));
        }*/

            return rolesList;
    } 
    
    public List<selectOption> getPartnerProfiles()
    {
        List<Profile> prList = new List<Profile>();
        prList = [Select Id, Name from Profile where UserType = 'PowerPartner' and Name != 'Gold Partner User' order by Name];
        
        List<SelectOption> profilesList = new List<SelectOption>();
        profilesList.add(new SelectOption('','--None--'));
        
        if(prList.size()>0)
        {
            for(Profile pr : prList)
            {
                profilesList.add(new SelectOption(pr.Id,pr.Name));
            }
            return profilesList;
        }
        else
        {
            System.debug('No Partner Profile found');
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'No Partner Profile found'));
            return null;
        }
    } 
    
    public Boolean validate()
    {
        System.debug('*****'+CRForm.Is_Create_User__c+'*****'+CRForm.Profile__c+'*****'+CRForm.Role__c);
        if(CRForm.Is_Create_User__c)
        {
            if(noRoleFound && CRForm.Profile__c==null)
            {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please choose a profile'));
                return false;
            }
            else if(!noRoleFound && CRForm.Profile__c==null && CRForm.Role__c==null)
            {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please choose role & profile'));
                return false;
            }
        }
        
        return true;
    }
    
    }

and this is the test class:

@isTest
private class CRequestForm_Wrapper_Test {

    static testmethod void constructor_Test() {
        Test.startTest();
        PageReference pageRef = Page.CRequestModify;
        Test.setCurrentPage(pageRef);
        
        SFDC_IDs__c SSAIIDs = SFDC_IDs__c.getValues('SSAI');
        Id saProfileId = SSAIIDs.System_Administrator_Profile_ID__c;
        
        User sau =
           [select UserRoleId
               from User
               where ProfileId = :saProfileId
               and isActive = true
               limit 1];
        
        System.runAs(sau) {
        
        Account newAcc=new Account(Name='Test Account');
        insert newAcc;
        
        Contact newContact=new Contact();
        newContact.LastName='Last Name';
        newContact.FirstName='First Name';
        newContact.AccountId=newAcc.Id;
        insert newContact;
        
        ApexPages.currentPage().getParameters().put('cid', newContact.Id);
        
        Contact_Request_Form__c newRec1 =new  Contact_Request_Form__c( Contact__c = newContact.Id,Last_Name__c='Last Name Test',First_Name__c='First Name Test',Email_Address__c='TEST2@MAIL.COM',Status__c='Submitted');
        insert newRec1;
        
        ApexPages.currentPage().getParameters().put('Id', newRec1.Id);
        
        ApexPages.StandardController controller = new ApexPages.StandardController(newRec1);
        CRequestForm_Wrapper WrapperC=new CRequestForm_Wrapper(controller);
        
        
        //String nextPage = WrapperC.save().getUrl();
        //System.assertNotEquals(nextPage, '');
        String nextPage = WrapperC.onApprove().getUrl();
        System.assertNotEquals(nextPage, '');
        nextPage = WrapperC.onSubmit().getUrl();
        System.assertNotEquals(nextPage, '');
nextPage = WrapperC.onReject().getUrl();
        
        
        Contact_Request_Form__c newRec2 =new  Contact_Request_Form__c( Contact__c = newContact.Id);
        
        
        ApexPages.currentPage().getParameters().put('Id', newRec2.Id);
        
        ApexPages.StandardController controller2 = new ApexPages.StandardController(newRec2);
        CRequestForm_Wrapper WrapperC2=new CRequestForm_Wrapper(controller2);
        
        
        nextPage = WrapperC2.save().getUrl();
        System.assertNotEquals(nextPage, '');
        }
        
        Test.stopTest();
    }
        

}
 


 

I have a Subgrantee object, and a Subgrantee Profile object, with a master-child relation ship (Subgrantee = master, Subgrantee Profile=child). I want to write a trigger so that:
- when the Name field in Subgrantee is updated
- The Subgrantee Profile name is also update (it's not the same, you have to append something to it)
Thanks
Someone else created a class and test class that works fine: CRequestForm_SearchController and CRequestForm_SearchController_test.
I made some edits to the class in sandbox, and copied the test class, so now I have a new class and a new test class: TESTCRequestForm_SearchController and TESTCRequestForm_SearchController_test. But I can't push it to production because the code coverage is only 68%. I have mannually tested it as an end-user and it works fine. Can anyone please help?
I have created a Custom Object called Subgrantee Profile, using the SubgranteeProfileController. There's a Visuaforce page (let's cal it page 1) that renders the fields under different tabs. I want to clone this Visualforce page into Visualforce page 2, delete some tabs, and assign it to a specific profile A.

I have changed the setting under:
- Profile > Enable Visualforce Page
- changed the Page Layout Assignment
- changed the Security setting of the Visualforce Page 2.

But when I log in as a profile A user, I can only see page 1. The only way I can make page 2 show, is to go Create > Object > Subgrantee Profile > Buttons, Links, and Action > View, and change the content source to page 2. But this change the view to page 2 for ALL profiles, which I don't want.

So in short, my question is: can I assign 2 visualforce pages of the same custom object to different profiles?

Thanks,