• Prudhvi Paladugu 2
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 5
    Replies
Class -
public with sharing class CaseContractPageController {

     
       public string selectedRecordType {get;set;}
       
       
    public CaseContractPageController(ApexPages.StandardController controller) {

    }
   
   
   public pagereference newPage(){
   
   
   recordType rec = [select id from RecordType where developerName=: selectedRecordType AND sObjectType ='Case'] ;
   
   PageReference pageRef = new PageReference('/500/e?retURL=%2F500%2Fo&RecordType='+rec.id+'&ent=Case');
    pageRef.setredirect(true);  
    return pageRef;
   
   
   }
   
    public pagereference cancelPage(){
   
   PageReference pageRef = new PageReference('https://ctsfullcrm.comcastctsfull.shnpoc.net');
    pageRef.setredirect(true);  
    return pageRef;
   
   
   }
   
   
   }

Test Class-

    static testMethod void newPageTestMethod() {
    
    Account recAccount = new Account(Name='TestAccount');
    Insert recAccount;
    Case recCase = new Case(AccountId=recAccount.Id, RecordTypeId ='012q00000009TUM');
    insert recCase;

   
    Apexpages.standardcontroller sc = new Apexpages.standardcontroller(recCase);
    CaseContractPageController cseController = new CaseContractPageController (sc);
         Id  recordTypeId = [select id from RecordType where Name='LR - NDA'].id;
    
    cseController.selectedRecordType  = 'LR - NDA';
   
    pagereference pagecase = Page.CaseContract;
    Test.setcurrentpage(pagecase);

    system.debug('recordTypeIdTest'+recordTypeId );
    

    pagecase.getParameters().put('rec.id',recordTypeId );

 
 try{
    cseController.newPage();
    }catch(Exception e){}
  
    }



 
Class -
public with sharing class CaseContractPageController {

     
       public string selectedRecordType {get;set;}
       
       
    public CaseContractPageController(ApexPages.StandardController controller) {

    }
   
   
   public pagereference newPage(){
   
   
   recordType rec = [select id from RecordType where developerName=: selectedRecordType AND sObjectType ='Case'] ;
   
   PageReference pageRef = new PageReference('/500/e?retURL=%2F500%2Fo&RecordType='+rec.id+'&ent=Case');
    pageRef.setredirect(true);  
    return pageRef;
   
   
   }
   
    public pagereference cancelPage(){
   
   PageReference pageRef = new PageReference('https://ctsfullcrm.comcastctsfull.shnpoc.net');
    pageRef.setredirect(true);  
    return pageRef;
   
   
   }
   
   
   }

Test Class-

    static testMethod void newPageTestMethod() {
    
    Account recAccount = new Account(Name='TestAccount');
    Insert recAccount;
    Case recCase = new Case(AccountId=recAccount.Id, RecordTypeId ='012q00000009TUM');
    insert recCase;

   
    Apexpages.standardcontroller sc = new Apexpages.standardcontroller(recCase);
    CaseContractPageController cseController = new CaseContractPageController (sc);
         Id  recordTypeId = [select id from RecordType where Name='LR - NDA'].id;
    
    cseController.selectedRecordType  = 'LR - NDA';
   
    pagereference pagecase = Page.CaseContract;
    Test.setcurrentpage(pagecase);

    system.debug('recordTypeIdTest'+recordTypeId );
    

    pagecase.getParameters().put('rec.id',recordTypeId );

 
 try{
    cseController.newPage();
    }catch(Exception e){}
  
    }



 
can you please  give me the example of that code.

I have a custom object Consultant which has a lookup to Account. The Account lookup is made read-only in the Consultant page layout level.


As Sys Admin, I am able to see the Account lookup getting populated when a New Consultant is created from Account related list. But when logged in as a different User, I am not able to see the Account lookup getting populated and since its read-only in the Consultant page layout, no data is available for the User to enter.

The same issue doesn't happen with standard Account - Contact relationship, if Account lookup is made read-only at Contact page layout.

Let me know if anybody can help in this issue!!!

 

Regards,

Karthik.