• Swaroopa Akula 1
  • NEWBIE
  • 30 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 17
    Replies
I have "Type" field values- New logo, New logo- deployment in oppty.

I have to allow the users to select Type value "New logo - deployemtn" whenever the old opporunity has "New logo" and closed date should be in within a year.
example: 1 account has 5 oppotunities and 1 oppty has Type="New logo" and close date is 3/27/2019. If i wanted to create a new opportunity with "New logo - deployemtn" type, it should check the previous opprty and its closed date. if that is in within a year of time then only we should allow the users to create a new opprotunity with type"New logo- deployement". how can i achieve this?
 
I am planning to create a naming convention for the opportunity name. Like 
Acct Name / Product / # Sites/ Partner

(#sites,Partner is the custom fields on opportunity.)
This partner name will be updated after the stage2 on opportunity. How can we automate the opporunity name once partner field enter after stage2 ?
i have a commision cusotm object . i have two fields partner email id field and partner user look up field. i will enter the email id field and partner user username field should get updated automatically. how could i do that?
<apex:page controller="PortalDealListController">
    <apex:pageBlock title="List of Deals">
        
        <apex:pageBlockTable value="{!convertedList}" var="o">
      
            <apex:column value="{!o.Partner_lead_Unique_number__c}"/>
            <apex:column value="{!o.Name}"/>
            <apex:column value="{!o.Need__c}"/>
            <apex:column value="{!o.Net_MRR__c}"/>
            <apex:column value="{!o.CloseDate}"/>
            <apex:column value="{!o.Account.Name}"/>
            <apex:column value="{!o.Deal_Reg_Expiration_Date__c}"/>
            
        </apex:pageBlockTable>
        </apex:pageBlock>
         <apex:pageBlock title="List of Accepted Deals">
         <apex:pageBlockTable value="{!acceptedList}" var="o">
          <apex:column value="{!o.Partner_lead_Unique_number__c}"/>
            <apex:column value="{!o.Name}"/>
            <apex:column value="{!o.Need__c}"/>
            <apex:column value="{!o.Net_MRR__c}"/>
            <apex:column value="{!o.CloseDate}"/>
            <apex:column value="{!o.Account.Name}"/>
            <apex:column value="{!o.Opportunity_Accepted_Date__c}"/>
            <apex:column value="{!o.Deal_Reg_Expiration_Date__c}"/>
                 </apex:pageBlockTable>
                 </apex:pageBlock>
            <apex:pageBlock title="List of Rejected Deals">   
                 <apex:pageBlockTable value="{!rejectedList}" var="o">
            <apex:column value="{!o.Partner_lead_Unique_number__c}"/>
            <apex:column value="{!o.Name}"/>
            <apex:column value="{!o.Need__c}"/>
            <apex:column value="{!o.Net_MRR__c}"/>
            <apex:column value="{!o.CloseDate}"/>
            <apex:column value="{!o.Account.Name}"/>
            <apex:column value="{!o.Opportunity_Accepted_Date__c}"/>
            <apex:column value="{!o.Deal_Reg_Expiration_Date__c}"/>
            <apex:column value="{!o.Opportunity_Rejected_Date__c}"/>
            <apex:column value="{!o.Rejection_Reason__c}"/>
            <apex:column value="{!o.Rejection_Notes__c}"/>
        </apex:pageBlockTable>   
                
        
    </apex:pa
Below is the code:


public without sharing class AryaPortalUserCreationTriggerHandler{
    private static Map<Id, String> emailMap = null;
    private static List<Contact> conListToInsert = null;

    public static void beforeUpdate(Self_Register_User_Request__c[] srs) {
    
    String DUMMY_ACCOUNT  = 'Dummy Account' ;
    List<Contact> conListToInsert = new List<Contact>();
    
    Map<Id, String> emailMap = new Map<Id, String>();
    Map<Id, Self_Register_User_Request__c> dummyMap = new Map<Id, Self_Register_User_Request__c>();
    
    
    for(Self_Register_User_Request__c sr :(List<Self_Register_User_Request__c>) trigger.new)  { 
        System.debug('here is FN: '+sr.FirstName__c);
        System.debug('here is FN: '+sr.LastName__c);
        System.debug('here is FN: '+sr.Email__c);
        System.debug('here is FN: '+sr.AccountName__c);
        if(sr.FirstName__c == null || sr.LastName__c == null || sr.Email__c == null)  
            continue;      
           if(sr.Is_it_Approved__c  = TRUE){
            if(sr.AccountName__c != null ){
                Contact conRecord = new Contact(
                    FirstName = sr.FirstName__c,
                    LastName = sr.LastName__c,
                    Email = sr.Email__c,
                    AccountId = sr.AccountName__c
                );              
                System.debug('adding contact from line 36');
                conListToInsert.add(conRecord); 
            }
           
            if(sr.Email__c != null){
                emailMap.put(sr.Id, sr.Email__c);           
            }
            
            dummyMap.put(sr.Id, sr);                    
        }
    }
    //create Portal User
    if(conListToInsert != null && conListToInsert.size() > 0) {
        insert conListToInsert;
        List<Profile> pList = [select id from Profile where Name = 'Partner Community Login User - Custom'];
        if(!pList.isEmpty()){
            Profile p = pList[0];
            List<User> userListToInsert = new List<User>();
            for(Contact con :conListToInsert) {             
                String alias1 = '';
                if(con.FirstName.length() >= 0)
                    alias1 = con.FirstName.substring(0,1);
                    
                String alias2 = '';
                if(con.LastName.length() >= 4){
                    alias2 = con.LastName.substring(0, 4);        
                }else{
                    alias2 = con.LastName;
                }
                String alias = alias1 + alias2;
                User u = new User(
                    Alias = alias, 
                    Email = con.Email,
                    EmailEncodingKey = 'UTF-8', 
                    FirstName = con.FirstName,
                    LastName = con.LastName, 
                    LanguageLocaleKey = 'en_US', 
                    LocalesIdKey = 'en_US', 
                    ProfileId = p.Id, 
                    ContactId = con.id,
                    TimeZonesIdKey = 'America/Los_Angeles', 
                    UserName = con.Email
                );
                Database.DMLOptions dmo = new Database.DMLOptions();
                dmo.EmailHeader.triggerUserEmail = true;
                u.setOptions(dmo);
                userListToInsert.add(u);
            }
                
            Database.SaveResult[] results = database.insert(userListToInsert, false);
            for(Database.SaveResult sr :results){
               if(!sr.isSuccess()){
                  Database.Error err = sr.getErrors()[0];
                  throw new CustomException(err.getMessage());
                 /* break;*/
               }
            }                       
        }        
    }  
    
   
    //define your custom exception
    public class CustomException extends Exception{}
 
 }   
}


    Usage: This trigger is used to send mail to Portal User which are created 
           from Self Registration Object
     
****************************************************************************/
trigger PortalUserCreation on Self_Register_User_Request__c (before update) {

    
    String DUMMY_ACCOUNT  = 'Dummy Account' ;
    List<Contact> conListToInsert = new List<Contact>();
    
    Map<Id, String> emailMap = new Map<Id, String>();
    Map<Id, Self_Register_User_Request__c> dummyMap = new Map<Id, Self_Register_User_Request__c>();
    
    for(Self_Register_User_Request__c sr :trigger.new) { 
        System.debug('here is FN: '+sr.FirstName__c);
        System.debug('here is FN: '+sr.LastName__c);
        System.debug('here is FN: '+sr.Email__c);
        System.debug('here is FN: '+sr.AccountName__c);
        if(sr.FirstName__c == null || sr.LastName__c == null || sr.Email__c == null)  
            continue;      
           if(sr.Is_it_Approved__c  = TRUE){
            if(sr.AccountName__c != null ){
                Contact conRecord = new Contact(
                    FirstName = sr.FirstName__c,
                    LastName = sr.LastName__c,
                    Email = sr.Email__c,
                    AccountId = sr.AccountName__c
                );              
                System.debug('adding contact from line 36');
                conListToInsert.add(conRecord); 
            }
           
            if(sr.Email__c != null){
                emailMap.put(sr.Id, sr.Email__c);           
            }
            
            dummyMap.put(sr.Id, sr);                    
        }
    }
    //create Portal User
    if(conListToInsert != null && conListToInsert.size() > 0) {
        insert conListToInsert;
        List<Profile> pList = [select id from Profile where Name = 'Partner Community '];
        if(!pList.isEmpty()){
            Profile p = pList[0];
            List<User> userListToInsert = new List<User>();
            for(Contact con :conListToInsert) {             
                String alias1 = '';
                if(con.FirstName.length() >= 0)
                    alias1 = con.FirstName.substring(0,1);
                    
                String alias2 = '';
                if(con.LastName.length() >= 4){
                    alias2 = con.LastName.substring(0, 4);        
                }else{
                    alias2 = con.LastName;
                }
                String alias = alias1 + alias2;
                User u = new User(
                    Alias = alias, 
                    Email = con.Email,
                    EmailEncodingKey = 'UTF-8', 
                    FirstName = con.FirstName,
                    LastName = con.LastName, 
                    LanguageLocaleKey = 'en_US', 
                    LocalesIdKey = 'en_US', 
                    ProfileId = p.Id, 
                    ContactId = con.id,
                    TimeZonesIdKey = 'America/Los_Angeles', 
                    UserName = con.Email
                );
                Database.DMLOptions dmo = new Database.DMLOptions();
                dmo.EmailHeader.triggerUserEmail = true;
                u.setOptions(dmo);
                userListToInsert.add(u);
            }
                
            Database.SaveResult[] results = database.insert(userListToInsert, false);
            for(Database.SaveResult sr :results){
               if(!sr.isSuccess()){
                  Database.Error err = sr.getErrors()[0];
                  throw new CustomException(err.getMessage());
                 /* break;*/
               }
            }                       
        }        
    }  
    
   
    //define your custom exception
    public class CustomException extends Exception{}
    
}
Please help me writing a test class for the below class:

public class portallist{

        public List<Opportunity> getAcceptedList(){
        User u =[SELECT Email, Username FROM User WHERE Id =: UserInfo.getUserId()];
        String usrEmailId= u.Email;

        System.debug('*** Controller Logged in Users Email ID..' + usrEmailId +'**** username' + u.Username);
        List<Opportunity> oppList = [SELECT Partner_lead_Unique_number__c, Name, CloseDate, Account.Name, Opportunity_Accepted_Date__c, Deal_Reg_Expiration_Date__c
                                     FROM Opportunity 
                                     WHERE Portal_User_Email_ID__c=: usrEmailId AND Accept_Opportunity__c ='Accept'];
    
        return oppList;
    }
<apex:page controller="PortalDealListController">
    <apex:pageBlock title="List of Deals">
        
        <apex:pageBlockTable value="{!convertedList}" var="o">
      
            <apex:column value="{!o.Partner_lead_Unique_number__c}"/>
            <apex:column value="{!o.Name}"/>
            <apex:column value="{!o.Need__c}"/>
            <apex:column value="{!o.Net_MRR__c}"/>
            <apex:column value="{!o.CloseDate}"/>
            <apex:column value="{!o.Account.Name}"/>
            <apex:column value="{!o.Deal_Reg_Expiration_Date__c}"/>
            
        </apex:pageBlockTable>
        </apex:pageBlock>
         <apex:pageBlock title="List of Accepted Deals">
         <apex:pageBlockTable value="{!acceptedList}" var="o">
          <apex:column value="{!o.Partner_lead_Unique_number__c}"/>
            <apex:column value="{!o.Name}"/>
            <apex:column value="{!o.Need__c}"/>
            <apex:column value="{!o.Net_MRR__c}"/>
            <apex:column value="{!o.CloseDate}"/>
            <apex:column value="{!o.Account.Name}"/>
            <apex:column value="{!o.Opportunity_Accepted_Date__c}"/>
            <apex:column value="{!o.Deal_Reg_Expiration_Date__c}"/>
                 </apex:pageBlockTable>
                 </apex:pageBlock>
            <apex:pageBlock title="List of Rejected Deals">   
                 <apex:pageBlockTable value="{!rejectedList}" var="o">
            <apex:column value="{!o.Partner_lead_Unique_number__c}"/>
            <apex:column value="{!o.Name}"/>
            <apex:column value="{!o.Need__c}"/>
            <apex:column value="{!o.Net_MRR__c}"/>
            <apex:column value="{!o.CloseDate}"/>
            <apex:column value="{!o.Account.Name}"/>
            <apex:column value="{!o.Opportunity_Accepted_Date__c}"/>
            <apex:column value="{!o.Deal_Reg_Expiration_Date__c}"/>
            <apex:column value="{!o.Opportunity_Rejected_Date__c}"/>
            <apex:column value="{!o.Rejection_Reason__c}"/>
            <apex:column value="{!o.Rejection_Notes__c}"/>
        </apex:pageBlockTable>   
                
        
    </apex:pa
Below is the code:


public without sharing class AryaPortalUserCreationTriggerHandler{
    private static Map<Id, String> emailMap = null;
    private static List<Contact> conListToInsert = null;

    public static void beforeUpdate(Self_Register_User_Request__c[] srs) {
    
    String DUMMY_ACCOUNT  = 'Dummy Account' ;
    List<Contact> conListToInsert = new List<Contact>();
    
    Map<Id, String> emailMap = new Map<Id, String>();
    Map<Id, Self_Register_User_Request__c> dummyMap = new Map<Id, Self_Register_User_Request__c>();
    
    
    for(Self_Register_User_Request__c sr :(List<Self_Register_User_Request__c>) trigger.new)  { 
        System.debug('here is FN: '+sr.FirstName__c);
        System.debug('here is FN: '+sr.LastName__c);
        System.debug('here is FN: '+sr.Email__c);
        System.debug('here is FN: '+sr.AccountName__c);
        if(sr.FirstName__c == null || sr.LastName__c == null || sr.Email__c == null)  
            continue;      
           if(sr.Is_it_Approved__c  = TRUE){
            if(sr.AccountName__c != null ){
                Contact conRecord = new Contact(
                    FirstName = sr.FirstName__c,
                    LastName = sr.LastName__c,
                    Email = sr.Email__c,
                    AccountId = sr.AccountName__c
                );              
                System.debug('adding contact from line 36');
                conListToInsert.add(conRecord); 
            }
           
            if(sr.Email__c != null){
                emailMap.put(sr.Id, sr.Email__c);           
            }
            
            dummyMap.put(sr.Id, sr);                    
        }
    }
    //create Portal User
    if(conListToInsert != null && conListToInsert.size() > 0) {
        insert conListToInsert;
        List<Profile> pList = [select id from Profile where Name = 'Partner Community Login User - Custom'];
        if(!pList.isEmpty()){
            Profile p = pList[0];
            List<User> userListToInsert = new List<User>();
            for(Contact con :conListToInsert) {             
                String alias1 = '';
                if(con.FirstName.length() >= 0)
                    alias1 = con.FirstName.substring(0,1);
                    
                String alias2 = '';
                if(con.LastName.length() >= 4){
                    alias2 = con.LastName.substring(0, 4);        
                }else{
                    alias2 = con.LastName;
                }
                String alias = alias1 + alias2;
                User u = new User(
                    Alias = alias, 
                    Email = con.Email,
                    EmailEncodingKey = 'UTF-8', 
                    FirstName = con.FirstName,
                    LastName = con.LastName, 
                    LanguageLocaleKey = 'en_US', 
                    LocalesIdKey = 'en_US', 
                    ProfileId = p.Id, 
                    ContactId = con.id,
                    TimeZonesIdKey = 'America/Los_Angeles', 
                    UserName = con.Email
                );
                Database.DMLOptions dmo = new Database.DMLOptions();
                dmo.EmailHeader.triggerUserEmail = true;
                u.setOptions(dmo);
                userListToInsert.add(u);
            }
                
            Database.SaveResult[] results = database.insert(userListToInsert, false);
            for(Database.SaveResult sr :results){
               if(!sr.isSuccess()){
                  Database.Error err = sr.getErrors()[0];
                  throw new CustomException(err.getMessage());
                 /* break;*/
               }
            }                       
        }        
    }  
    
   
    //define your custom exception
    public class CustomException extends Exception{}
 
 }   
}


    Usage: This trigger is used to send mail to Portal User which are created 
           from Self Registration Object
     
****************************************************************************/
trigger PortalUserCreation on Self_Register_User_Request__c (before update) {

    
    String DUMMY_ACCOUNT  = 'Dummy Account' ;
    List<Contact> conListToInsert = new List<Contact>();
    
    Map<Id, String> emailMap = new Map<Id, String>();
    Map<Id, Self_Register_User_Request__c> dummyMap = new Map<Id, Self_Register_User_Request__c>();
    
    for(Self_Register_User_Request__c sr :trigger.new) { 
        System.debug('here is FN: '+sr.FirstName__c);
        System.debug('here is FN: '+sr.LastName__c);
        System.debug('here is FN: '+sr.Email__c);
        System.debug('here is FN: '+sr.AccountName__c);
        if(sr.FirstName__c == null || sr.LastName__c == null || sr.Email__c == null)  
            continue;      
           if(sr.Is_it_Approved__c  = TRUE){
            if(sr.AccountName__c != null ){
                Contact conRecord = new Contact(
                    FirstName = sr.FirstName__c,
                    LastName = sr.LastName__c,
                    Email = sr.Email__c,
                    AccountId = sr.AccountName__c
                );              
                System.debug('adding contact from line 36');
                conListToInsert.add(conRecord); 
            }
           
            if(sr.Email__c != null){
                emailMap.put(sr.Id, sr.Email__c);           
            }
            
            dummyMap.put(sr.Id, sr);                    
        }
    }
    //create Portal User
    if(conListToInsert != null && conListToInsert.size() > 0) {
        insert conListToInsert;
        List<Profile> pList = [select id from Profile where Name = 'Partner Community '];
        if(!pList.isEmpty()){
            Profile p = pList[0];
            List<User> userListToInsert = new List<User>();
            for(Contact con :conListToInsert) {             
                String alias1 = '';
                if(con.FirstName.length() >= 0)
                    alias1 = con.FirstName.substring(0,1);
                    
                String alias2 = '';
                if(con.LastName.length() >= 4){
                    alias2 = con.LastName.substring(0, 4);        
                }else{
                    alias2 = con.LastName;
                }
                String alias = alias1 + alias2;
                User u = new User(
                    Alias = alias, 
                    Email = con.Email,
                    EmailEncodingKey = 'UTF-8', 
                    FirstName = con.FirstName,
                    LastName = con.LastName, 
                    LanguageLocaleKey = 'en_US', 
                    LocalesIdKey = 'en_US', 
                    ProfileId = p.Id, 
                    ContactId = con.id,
                    TimeZonesIdKey = 'America/Los_Angeles', 
                    UserName = con.Email
                );
                Database.DMLOptions dmo = new Database.DMLOptions();
                dmo.EmailHeader.triggerUserEmail = true;
                u.setOptions(dmo);
                userListToInsert.add(u);
            }
                
            Database.SaveResult[] results = database.insert(userListToInsert, false);
            for(Database.SaveResult sr :results){
               if(!sr.isSuccess()){
                  Database.Error err = sr.getErrors()[0];
                  throw new CustomException(err.getMessage());
                 /* break;*/
               }
            }                       
        }        
    }  
    
   
    //define your custom exception
    public class CustomException extends Exception{}
    
}
Please help me writing a test class for the below class:

public class portallist{

        public List<Opportunity> getAcceptedList(){
        User u =[SELECT Email, Username FROM User WHERE Id =: UserInfo.getUserId()];
        String usrEmailId= u.Email;

        System.debug('*** Controller Logged in Users Email ID..' + usrEmailId +'**** username' + u.Username);
        List<Opportunity> oppList = [SELECT Partner_lead_Unique_number__c, Name, CloseDate, Account.Name, Opportunity_Accepted_Date__c, Deal_Reg_Expiration_Date__c
                                     FROM Opportunity 
                                     WHERE Portal_User_Email_ID__c=: usrEmailId AND Accept_Opportunity__c ='Accept'];
    
        return oppList;
    }