• Mohan SFDC 25
  • NEWBIE
  • -2 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 4
    Replies
I have a requirement. I have a object obj1 and another obj obj2 which are not direct related. 
obj1 is related to contact and contact is related to obj2. so now my requirement is 
suppose in obj1 if I am inserting a field f1 , then in obj 2 field2 should add the value which already exists and display the total value.
that means suppose in field f1 contains 100 value and obj2 field2 contains 200 values then it should update the field2 values by adding field1 value and display the total value.
Please try to help me.
Thanks in advance
Hi All,

pls help me in code coverage 
This is my controller class
public with sharing class Solution{

    public Boolean displayPopup {get;set;}
    public List<Object__c> Records {get; set;} 
    public User username {get; set;} 
    public string userid {get; set;}
    public String searchTerm {get; set;}
    public String selecteduser {get; set;}
    public String uId {get; set;}
    public List<User> UserTemp = new List<User>();
    
    // To load data into the table
    public PACV_SolutionsTab_CC(ApexPages.StandardController controller) 
    {
        userid = Userinfo.getUserId();       
        Records =   [SELECT Name,some fields,Owner.name FROM Object__c WHERE CreatedById = :userid]; 
        system.debug(Records);
    } 
     
    
    // User Auto Complete related code
    public String getSearchTerm() 
    {
        return null;
    }
     // For auto complete functionality
    
        @RemoteAction
        public static List<User> searchuser(String searchTerm) {
       
       // System.debug('user Name is: '+searchTerm );
        List<User> user = Database.query('SELECT Name,Id FROM User where Name like \'%' + String.escapeSingleQuotes(searchTerm) + '%\' Limit 20');  
            system.debug('user'+user);
        return user;
    }
    // Assigns permission sets to the appropriate users
    // This is run as part of the setup wizard and after installations.       
            
      public  PageReference AssignPermissionSets()
        {
          PermissionSet ps = [SELECT ID From PermissionSet WHERE Name = 'Custom_Permissionset'];
          list <PermissionSetAssignment> PSAssignments = new list <PermissionSetAssignment>();
          List<User> users = [SELECT ID,(Select id,AssigneeId FROM PermissionSetAssignments WHERE PermissionSetID = :ps.Id) FROM User WHERE Profile.UserLicense.Name= 'Salesforce Platform' AND IsActive = true AND Id = :selecteduser];
            for( User u : users ){
                if(u.PermissionSetAssignments.size() == 0) 
                PSAssignments.add( new PermissionSetAssignment(AssigneeId = u.id,PermissionSetId = ps.ID ) );
                }
                insert PSAssignments;
              displayPopup = false;
                return null;
        }
    
    // To show popup and its functionality
    
    public void showPopup()
    {       
        displayPopup = true;    
    }
    
    public void closePopup() 
    {
        displayPopup = false;        
    }
    
}

This is my test class
@isTest
public class TabNametest
{
public static testMethod void SolutionTabMethod() {
        
     
        Object__c o = new Object__c (Name='Test',Contact_Phone__c='0987654321',Supplier_Phone__c='1234567890');
        insert o;
       Profile p1 = [select id from Profile where name='Standard Platform User']; 

        User opUser = new user(alias = 'test123', email='test123@noemail.com',emailencodingkey='UTF-8', firstName='Pawan', lastname='Testing', 
                               languagelocalekey='en_US',localesidkey='en_US', profileid = p1.Id, country='United States',
                               timezonesidkey='America/Los_Angeles', username='test01@noemail.com'); 
            insert opUser;
			
			/*
            PermissionSet ps = [SELECT ID From PermissionSet WHERE Name = 'Custom_Permissionset'];
            insert new PermissionSetAssignment(AssigneeId = opUser.id, PermissionSetId = ps.Id );
			*/
			
            PageReference myPage = Page.Solution;
            myPage.getParameters().put('id', o.Id);  
            Test.setCurrentPage(myPage);    
            ApexPages.StandardController control = new ApexPages.Standardcontroller(o);
            Solution pageControl = new Solution(control); 
            pageControl.showPopup();   
            pageControl.closePopup();
			try
			{
				pageControl.selecteduser = opUser.id;
				pageControl.AssignPermissionSets();
			}Catch(Exception ee)	
			{}
    }

}

Not able to cover 28 to 34 lines of code
Hi All,

pls help me in code coverage 
This is my controller class
 
public with sharing class Solution{

    public Boolean displayPopup {get;set;}
    public List<Object__c> Records {get; set;} 
    public User username {get; set;} 
    public string userid {get; set;}
    public String searchTerm {get; set;}
    public String selecteduser {get; set;}
    public String uId {get; set;}
    public List<User> UserTemp = new List<User>();
    
    // To load data into the table
    public PACV_SolutionsTab_CC(ApexPages.StandardController controller) 
    {
        userid = Userinfo.getUserId();       
        Records =   [SELECT Name,some fields,Owner.name FROM Object__c WHERE CreatedById = :userid]; 
        system.debug(Records);
    } 
     
    
    // User Auto Complete related code
    public String getSearchTerm() 
    {
        return null;
    }
     // For auto complete functionality
    
        @RemoteAction
        public static List<User> searchuser(String searchTerm) {
       
       // System.debug('user Name is: '+searchTerm );
        List<User> user = Database.query('SELECT Name,Id FROM User where Name like \'%' + String.escapeSingleQuotes(searchTerm) + '%\' Limit 20');  
            system.debug('user'+user);
        return user;
    }
    // Assigns permission sets to the appropriate users
    // This is run as part of the setup wizard and after installations.       
            
      public  PageReference AssignPermissionSets()
        {
          PermissionSet ps = [SELECT ID From PermissionSet WHERE Name = 'Custom_Permissionset'];
          list <PermissionSetAssignment> PSAssignments = new list <PermissionSetAssignment>();
          List<User> users = [SELECT ID,(Select id,AssigneeId FROM PermissionSetAssignments WHERE PermissionSetID = :ps.Id) FROM User WHERE Profile.UserLicense.Name= 'Salesforce Platform' AND IsActive = true AND Id = :selecteduser];
            for( User u : users ){
                if(u.PermissionSetAssignments.size() == 0) 
                PSAssignments.add( new PermissionSetAssignment(AssigneeId = u.id,PermissionSetId = ps.ID ) );
                }
                insert PSAssignments;
              displayPopup = false;
                return null;
        }
    
    // To show popup and its functionality
    
    public void showPopup()
    {       
        displayPopup = true;    
    }
    
    public void closePopup() 
    {
        displayPopup = false;        
    }
    
}

This is my test class
 
@isTest
public class PACV_SolutionTabTest
{
public static testMethod void SolutionTabMethod() {
        
     
        Object__c o = new Object__c (Name='Test',Contact_Phone__c='0987654321',Supplier_Phone__c='1234567890');
        insert o;
       Profile p1 = [select id from Profile where name='Standard Platform User']; 

        User opUser = new user(alias = 'test123', email='test123@noemail.com',emailencodingkey='UTF-8', firstName='Pawan', lastname='Testing', 
                               languagelocalekey='en_US',localesidkey='en_US', profileid = p1.Id, country='United States',
                               timezonesidkey='America/Los_Angeles', username='test01@noemail.com'); 
            insert opUser;
            PermissionSet ps = [SELECT ID From PermissionSet WHERE Name = 'Custom_Permissionset'];
            insert new PermissionSetAssignment(AssigneeId = opUser.id, PermissionSetId = ps.Id );
        
            PageReference myPage = Page.Solution;
            myPage.getParameters().put('id', o.Id);  
            Test.setCurrentPage(myPage);    
            ApexPages.StandardController control = new ApexPages.Standardcontroller(o);
           Solution pageControl = new Solution(control); 
            pageControl.AssignPermissionSets();
            pageControl.showPopup();   
            pageControl.closePopup();
    }

}

Here i am not able to cover 43, 46 and 47 lines .
please help me
 
Hello Eveyone,

I have created a visualforce page, in that I have a user lookup field and a button 
after selecting user, when I click on submit button I want to assign a permission set to that user(custom permission set). 
please help me on this.
Please telle me how to approach this.

Thanks in advance.
Hello Eveyone,

I have created a visualforce page, in that I have a user lookup field and a button 
after selecting user, when I click on submit button I want to assign a permission set to that user(custom permission set). 
please help me on this.
Please telle me how to approach this.

Thanks in advance.
 
I have a requirement. I have a object obj1 and another obj obj2 which are not direct related. 
obj1 is related to contact and contact is related to obj2. so now my requirement is 
suppose in obj1 if I am inserting a field f1 , then in obj 2 field2 should add the value which already exists and display the total value.
that means suppose in field f1 contains 100 value and obj2 field2 contains 200 values then it should update the field2 values by adding field1 value and display the total value.
Please try to help me.
Thanks in advance
Hi All,

pls help me in code coverage 
This is my controller class
 
public with sharing class Solution{

    public Boolean displayPopup {get;set;}
    public List<Object__c> Records {get; set;} 
    public User username {get; set;} 
    public string userid {get; set;}
    public String searchTerm {get; set;}
    public String selecteduser {get; set;}
    public String uId {get; set;}
    public List<User> UserTemp = new List<User>();
    
    // To load data into the table
    public PACV_SolutionsTab_CC(ApexPages.StandardController controller) 
    {
        userid = Userinfo.getUserId();       
        Records =   [SELECT Name,some fields,Owner.name FROM Object__c WHERE CreatedById = :userid]; 
        system.debug(Records);
    } 
     
    
    // User Auto Complete related code
    public String getSearchTerm() 
    {
        return null;
    }
     // For auto complete functionality
    
        @RemoteAction
        public static List<User> searchuser(String searchTerm) {
       
       // System.debug('user Name is: '+searchTerm );
        List<User> user = Database.query('SELECT Name,Id FROM User where Name like \'%' + String.escapeSingleQuotes(searchTerm) + '%\' Limit 20');  
            system.debug('user'+user);
        return user;
    }
    // Assigns permission sets to the appropriate users
    // This is run as part of the setup wizard and after installations.       
            
      public  PageReference AssignPermissionSets()
        {
          PermissionSet ps = [SELECT ID From PermissionSet WHERE Name = 'Custom_Permissionset'];
          list <PermissionSetAssignment> PSAssignments = new list <PermissionSetAssignment>();
          List<User> users = [SELECT ID,(Select id,AssigneeId FROM PermissionSetAssignments WHERE PermissionSetID = :ps.Id) FROM User WHERE Profile.UserLicense.Name= 'Salesforce Platform' AND IsActive = true AND Id = :selecteduser];
            for( User u : users ){
                if(u.PermissionSetAssignments.size() == 0) 
                PSAssignments.add( new PermissionSetAssignment(AssigneeId = u.id,PermissionSetId = ps.ID ) );
                }
                insert PSAssignments;
              displayPopup = false;
                return null;
        }
    
    // To show popup and its functionality
    
    public void showPopup()
    {       
        displayPopup = true;    
    }
    
    public void closePopup() 
    {
        displayPopup = false;        
    }
    
}

This is my test class
 
@isTest
public class PACV_SolutionTabTest
{
public static testMethod void SolutionTabMethod() {
        
     
        Object__c o = new Object__c (Name='Test',Contact_Phone__c='0987654321',Supplier_Phone__c='1234567890');
        insert o;
       Profile p1 = [select id from Profile where name='Standard Platform User']; 

        User opUser = new user(alias = 'test123', email='test123@noemail.com',emailencodingkey='UTF-8', firstName='Pawan', lastname='Testing', 
                               languagelocalekey='en_US',localesidkey='en_US', profileid = p1.Id, country='United States',
                               timezonesidkey='America/Los_Angeles', username='test01@noemail.com'); 
            insert opUser;
            PermissionSet ps = [SELECT ID From PermissionSet WHERE Name = 'Custom_Permissionset'];
            insert new PermissionSetAssignment(AssigneeId = opUser.id, PermissionSetId = ps.Id );
        
            PageReference myPage = Page.Solution;
            myPage.getParameters().put('id', o.Id);  
            Test.setCurrentPage(myPage);    
            ApexPages.StandardController control = new ApexPages.Standardcontroller(o);
           Solution pageControl = new Solution(control); 
            pageControl.AssignPermissionSets();
            pageControl.showPopup();   
            pageControl.closePopup();
    }

}

Here i am not able to cover 43, 46 and 47 lines .
please help me