• chiru123
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies

Hi all,

 

I have a user picklist on lookup

1.user

2.Customer portal user

 

how to hide the customer portal user in the picklist.Is it possible that is a standard functionality

Is there any method to achive this one

 

any ideas?

 

Thanks!

 

 

 

Hi All,

 

Apex Class:

 


/*class B2BCancelPage used by B2BCancelPage page*/
public class B2BCancelPage
{
//Variables declaration
public B2BCampaign__c b2bCampaignObject{get;set;}
public boolean isValidUser{get;set;}
public B2BUtilities utilityObject{get;set;}

/* Constructor function:
This function is executed when the page loads the first time, and every time it is refreshed
This function maps the VF page fields to the project record using the ID
*/
public B2BCancelPage(ApexPages.StandardController controller) {
utilityObject=new B2BUtilities();
isValidUser = True;
b2bCampaignObject = new B2BCampaign__c(ID=ApexPages.currentPage().getParameters().get('ID'));
String UserID = UserInfo.getUserId();
String UserRoleID = UserInfo.getUserRoleId();
String strstatus= [Select Status__c from B2BCampaign__c where ID = :b2bCampaignObject.ID].Status__c;
String submitterName = [Select SubmittedBy__r.name from B2BCampaign__c where ID = :b2bCampaignObject.ID].SubmittedBy__r.name;

List<B2BCampaign__Share> AccessLevels = [select AccessLevel from B2BCampaign__Share where UserorGroupID = :UserID and ParentID = :b2bCampaignObject.ID and AccessLevel in ('Edit','All')];
for (B2BCampaign__Share al : AccessLevels)
{
if((strstatus == B2BUtilities.status_submittedToMSA || strstatus == B2BUtilities.status_submittedToB2B ) && submitterName <> Userinfo.getName())
isValidUser = False;
}
if(UserRoleID == B2BUtilities.roleId_B2BbizAdmin && (strstatus == B2BUtilities.status_submittedToMSA || strstatus == B2BUtilities.status_submittedToB2B ))
isValidUser = False;
}

/* save function:
- This function is executed when the user clicks the Save button after filling in the data for the fields
- This function performs data validations to make sure all required fields are filled in
- It updates the Cancellation details to the object
- It closes all the pending tasks as completed
- It recalls all pending Approval processes
*/
public PageReference save(){
// If the reason is selected as Other, but the details are not filled in
if(b2bCampaignObject.Reason_for_Cancellation__c == 'Other (please specify)' && b2bCampaignObject.OTHER_Reason__c == null){
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL, 'Please Enter the reason in OTHER Reason Field');
ApexPages.addMessage(myMsg);
return null;
}
// If the reason is selected as Duplicate, but the Duplicate project number is not filled in
else if(b2bCampaignObject.Reason_for_Cancellation__c == 'Duplicate project request' && b2bCampaignObject.Duplicate_Project_No__c == null){
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL, 'Please select the Duplicate Project Number from the lookup');
ApexPages.addMessage(myMsg);
return null;
}

// If the reason is not Other, then the Other Reason details field should be blanked out
if(b2bCampaignObject.Reason_for_Cancellation__c <> 'Other (please specify)'){
b2bCampaignObject.OTHER_Reason__c = null;
}
// If the reason is not Duplicate, then the Duplicate project number field should be blanked out
if(b2bCampaignObject.Reason_for_Cancellation__c <> 'Duplicate project request'){
b2bCampaignObject.Duplicate_Project_No__c = null;
}


// Recalling any pending Approval process
List<ProcessInstanceWorkitem> workitem = new List<ProcessInstanceWorkitem>([select Id from ProcessInstanceWorkitem where ProcessInstance.TargetObjectId = :b2bCampaignObject.ID and ProcessInstance.Status = 'Pending']);
Approval.ProcessWorkItemRequest pwr = new Approval.ProcessWorkItemRequest();

for (ProcessInstanceWorkitem w : workitem)
{
pwr.setWorkitemId(w.ID);
pwr.setComments('Recalling the Approval Request since the project has been Cancelled');
pwr.setAction('Removed');
Approval.ProcessResult pr = Approval.process(pwr);
}


// Closing all Pending tasks Related to that project as Completed
List<Task> lstAssignTask = new List<Task>();
lstAssignTask = [select Id from task where WhatId =:b2BCampaignObject.Id and Status != 'Completed' ];
for(Task t : lstAssignTask ){
t.status = 'Completed';
t.description = 'Closing the task as Completed since the project has been Cancelled';
}

try{
update lstAssignTask;
}
catch (DMLException e){
ApexPages.addMessages(e);
}

catch (Exception e){
ApexPages.addMessages(e);
}

try{
// Updating the Status, Cancelled by, and Cancel datetime values
b2bCampaignObject.Cancelled_Datetime__c = datetime.now(); // Current datetime of cancellation
b2bCampaignObject.Cancelled_By__c = userInfo.getUserId(); // current log in user
b2bCampaignObject.status__c=B2BUtilities.status_cancelled;
update b2bCampaignObject;
}

catch (DMLException e){
ApexPages.addMessages(e);
}

catch (Exception e){
ApexPages.addMessages(e);
}

//Redirect the user to the View page after the request has been cancelled
PageReference pageRef= new ApexPages.StandardController(b2bCampaignObject).view();
pageRef.setRedirect(true);
return pageRef ;
}

/* cancel function:
- This function is executed when the user clicks the cancel button
- It redirects the user to the View page of the project
*/
public PageReference cancel(){
PageReference pageRef= new ApexPages.StandardController(b2bCampaignObject).view();
pageRef.setRedirect(true);
return pageRef ;
}

}

 

 

 

Here is the test class code:

 

@isTest
private class B2BTest_TestB2BCancelPage {
    
    static testMethod void TestB2BCancelPageMethod1(){    
      PageReference pageRef = Page.B2Bcancelpage;
      Test.setCurrentPage(pageRef);
      
      B2BCampaign__c objb2b = new B2BCampaign__c();
      objb2b.Status__c = 'test1';
      objb2b.Market__c = 'test2';
      objb2b.Region__c = 'test3';
      objb2b.Name = 'test3';
      objb2b.Project_Type__c = 'test4';
      System.debug('!!!!!!!!'+UserInfo.getUserId());
      
      
      objb2b.Back_Up_Requestor1__c = '005e0000000JVMM'; 
      objb2b.Requestor_Name__c = UserInfo.getUserId();
      objb2b.Sub_Project_Type__c = 'test1';
      objb2b.Reason_for_Cancellation__c = 'Other (please specify)';
      objb2b.OTHER_Reason__c = '';
      //objb2b.Reason_for_Cancellation__c = 'Duplicate project request';
      //objb2b.Duplicate_Project_No__c = null;
      
      insert objb2b;
      System.debug('@@@@@@@'+objb2b);
      
      objb2b.Reason_for_Cancellation__c = 'ddfdfdfbfd';
      objb2b.OTHER_Reason__c = 'bnbnbnnbnbmnbnmbn';
      update objb2b; 
      System.debug('########'+objb2b);
      
      ApexPages.currentPage().getParameters().put('id',objb2b.id);
      B2BCancelPage bc = new B2BCancelPage(new ApexPages.standardController(objb2b));
       bc.save();
       bc.cancel();

}

 

 

Can any body suggest me to do the complete code coverage

In this I have coverd 65%

 

 

Hi All,

 

Apex Class:

 


/*class B2BCancelPage used by B2BCancelPage page*/
public class B2BCancelPage
{
//Variables declaration
public B2BCampaign__c b2bCampaignObject{get;set;}
public boolean isValidUser{get;set;}
public B2BUtilities utilityObject{get;set;}

/* Constructor function:
This function is executed when the page loads the first time, and every time it is refreshed
This function maps the VF page fields to the project record using the ID
*/
public B2BCancelPage(ApexPages.StandardController controller) {
utilityObject=new B2BUtilities();
isValidUser = True;
b2bCampaignObject = new B2BCampaign__c(ID=ApexPages.currentPage().getParameters().get('ID'));
String UserID = UserInfo.getUserId();
String UserRoleID = UserInfo.getUserRoleId();
String strstatus= [Select Status__c from B2BCampaign__c where ID = :b2bCampaignObject.ID].Status__c;
String submitterName = [Select SubmittedBy__r.name from B2BCampaign__c where ID = :b2bCampaignObject.ID].SubmittedBy__r.name;

List<B2BCampaign__Share> AccessLevels = [select AccessLevel from B2BCampaign__Share where UserorGroupID = :UserID and ParentID = :b2bCampaignObject.ID and AccessLevel in ('Edit','All')];
for (B2BCampaign__Share al : AccessLevels)
{
if((strstatus == B2BUtilities.status_submittedToMSA || strstatus == B2BUtilities.status_submittedToB2B ) && submitterName <> Userinfo.getName())
isValidUser = False;
}
if(UserRoleID == B2BUtilities.roleId_B2BbizAdmin && (strstatus == B2BUtilities.status_submittedToMSA || strstatus == B2BUtilities.status_submittedToB2B ))
isValidUser = False;
}

/* save function:
- This function is executed when the user clicks the Save button after filling in the data for the fields
- This function performs data validations to make sure all required fields are filled in
- It updates the Cancellation details to the object
- It closes all the pending tasks as completed
- It recalls all pending Approval processes
*/
public PageReference save(){
// If the reason is selected as Other, but the details are not filled in
if(b2bCampaignObject.Reason_for_Cancellation__c == 'Other (please specify)' && b2bCampaignObject.OTHER_Reason__c == null){
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL, 'Please Enter the reason in OTHER Reason Field');
ApexPages.addMessage(myMsg);
return null;
}
// If the reason is selected as Duplicate, but the Duplicate project number is not filled in
else if(b2bCampaignObject.Reason_for_Cancellation__c == 'Duplicate project request' && b2bCampaignObject.Duplicate_Project_No__c == null){
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL, 'Please select the Duplicate Project Number from the lookup');
ApexPages.addMessage(myMsg);
return null;
}

// If the reason is not Other, then the Other Reason details field should be blanked out
if(b2bCampaignObject.Reason_for_Cancellation__c <> 'Other (please specify)'){
b2bCampaignObject.OTHER_Reason__c = null;
}
// If the reason is not Duplicate, then the Duplicate project number field should be blanked out
if(b2bCampaignObject.Reason_for_Cancellation__c <> 'Duplicate project request'){
b2bCampaignObject.Duplicate_Project_No__c = null;
}


// Recalling any pending Approval process
List<ProcessInstanceWorkitem> workitem = new List<ProcessInstanceWorkitem>([select Id from ProcessInstanceWorkitem where ProcessInstance.TargetObjectId = :b2bCampaignObject.ID and ProcessInstance.Status = 'Pending']);
Approval.ProcessWorkItemRequest pwr = new Approval.ProcessWorkItemRequest();

for (ProcessInstanceWorkitem w : workitem)
{
pwr.setWorkitemId(w.ID);
pwr.setComments('Recalling the Approval Request since the project has been Cancelled');
pwr.setAction('Removed');
Approval.ProcessResult pr = Approval.process(pwr);
}


// Closing all Pending tasks Related to that project as Completed
List<Task> lstAssignTask = new List<Task>();
lstAssignTask = [select Id from task where WhatId =:b2BCampaignObject.Id and Status != 'Completed' ];
for(Task t : lstAssignTask ){
t.status = 'Completed';
t.description = 'Closing the task as Completed since the project has been Cancelled';
}

try{
update lstAssignTask;
}
catch (DMLException e){
ApexPages.addMessages(e);
}

catch (Exception e){
ApexPages.addMessages(e);
}

try{
// Updating the Status, Cancelled by, and Cancel datetime values
b2bCampaignObject.Cancelled_Datetime__c = datetime.now(); // Current datetime of cancellation
b2bCampaignObject.Cancelled_By__c = userInfo.getUserId(); // current log in user
b2bCampaignObject.status__c=B2BUtilities.status_cancelled;
update b2bCampaignObject;
}

catch (DMLException e){
ApexPages.addMessages(e);
}

catch (Exception e){
ApexPages.addMessages(e);
}

//Redirect the user to the View page after the request has been cancelled
PageReference pageRef= new ApexPages.StandardController(b2bCampaignObject).view();
pageRef.setRedirect(true);
return pageRef ;
}

/* cancel function:
- This function is executed when the user clicks the cancel button
- It redirects the user to the View page of the project
*/
public PageReference cancel(){
PageReference pageRef= new ApexPages.StandardController(b2bCampaignObject).view();
pageRef.setRedirect(true);
return pageRef ;
}

}

 

 

 

Here is the test class code:

 

@isTest
private class B2BTest_TestB2BCancelPage {
    
    static testMethod void TestB2BCancelPageMethod1(){    
      PageReference pageRef = Page.B2Bcancelpage;
      Test.setCurrentPage(pageRef);
      
      B2BCampaign__c objb2b = new B2BCampaign__c();
      objb2b.Status__c = 'test1';
      objb2b.Market__c = 'test2';
      objb2b.Region__c = 'test3';
      objb2b.Name = 'test3';
      objb2b.Project_Type__c = 'test4';
      System.debug('!!!!!!!!'+UserInfo.getUserId());
      
      
      objb2b.Back_Up_Requestor1__c = '005e0000000JVMM'; 
      objb2b.Requestor_Name__c = UserInfo.getUserId();
      objb2b.Sub_Project_Type__c = 'test1';
      objb2b.Reason_for_Cancellation__c = 'Other (please specify)';
      objb2b.OTHER_Reason__c = '';
      //objb2b.Reason_for_Cancellation__c = 'Duplicate project request';
      //objb2b.Duplicate_Project_No__c = null;
      
      insert objb2b;
      System.debug('@@@@@@@'+objb2b);
      
      objb2b.Reason_for_Cancellation__c = 'ddfdfdfbfd';
      objb2b.OTHER_Reason__c = 'bnbnbnnbnbmnbnmbn';
      update objb2b; 
      System.debug('########'+objb2b);
      
      ApexPages.currentPage().getParameters().put('id',objb2b.id);
      B2BCancelPage bc = new B2BCancelPage(new ApexPages.standardController(objb2b));
       bc.save();
       bc.cancel();

}

 

 

Can any body suggest me to do the complete code coverage

In this I have coverd 65%