• salesforce instance
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 4
    Replies
global class SEMailSender {
    
         webservice static string CaseMergefields(String Emailbody,Case C){
            
              String textEmailbody=Emailbody;
              
                if(textEmailbody.Contains(SEConstants.CASENUMBERMERGE))
                    textEmailbody = textEmailbody.replace(SEConstants.CASENUMBERMERGE ,C.CaseNumber);
                    
                if(textEmailbody.Contains('{!Case.Subject}')){
                if(C.Subject!=null) 
                    textEmailbody = textEmailbody.replace('{!Case.Subject}' ,C.Subject);
                else
                    textEmailbody = textEmailbody.replace('{!Case.Subject}' ,SEConstants.BLANK);
                    
                }
                if(textEmailbody.Contains('{!Case.Description}')){
                    if(C.Description!=null)
                        textEmailbody = textEmailbody.replace('{!Case.Description}' ,C.Description);
                    else
                        textEmailbody = textEmailbody.replace('{!Case.Description}' ,SEConstants.BLANK);
                }
                    
                if(textEmailbody.Contains('{!Case.Solution_Description__c}')){
                    if(C.Solution_Description__c!=null)
                        textEmailbody = textEmailbody.replace('{!Case.Solution_Description__c}' ,C.Solution_Description__c);
                    else
                        textEmailbody = textEmailbody.replace('{!Case.Solution_Description__c}' ,SEConstants.BLANK);
                }
                    
                    
                if(textEmailbody.Contains('{!Case.External_Info_Long__c}')){
                    if(C.External_Info_Long__c!=null)
                        textEmailbody = textEmailbody.replace('{!Case.External_Info_Long__c}' ,C.External_Info_Long__c);
                    else
                        textEmailbody = textEmailbody.replace('{!Case.External_Info_Long__c}' ,SEConstants.BLANK);
                }
                if(textEmailbody.Contains('{!Case.Partner_Case_Ref__c}')){
                    if(C.Partner_Case_Ref__c!=null)
                        textEmailbody = textEmailbody.replace('{!Case.Partner_Case_Ref__c}' ,C.Partner_Case_Ref__c);
                   else
                        textEmailbody = textEmailbody.replace('{!Case.Partner_Case_Ref__c}' ,SEConstants.BLANK);
                }
                   
                if(textEmailbody.Contains('{!Case.Customer_Case_Ref__c}')){
                    if(C.Customer_Case_Ref__c!=null)
                        textEmailbody = textEmailbody.replace('{!Case.Customer_Case_Ref__c}' ,C.Customer_Case_Ref__c);
                    else
                        textEmailbody = textEmailbody.replace('{!Case.Customer_Case_Ref__c}' ,SEConstants.BLANK);   
                }
                if(textEmailbody.Contains('{!Case.SurveyLink__c}') && C.SurveyLink__c!=null)
                    textEmailbody = textEmailbody.replace('{!Case.SurveyLink__c}' ,C.SurveyLink__c);
            return textEmailbody;
        }

}
if(Trigger.isBefore && Trigger.isInsert) 
                       {
                            for(Case c : lscase)
                                {
                                 acntsIds.add(c.AccountID);
                                }
                             List<Contact> ls = new List<Contact>([SELECT id, Name, Email from Contact where AccountId IN : acntsIds]);
                             for(Contact c : ls)
                                       {
                                       conIds.add(c.Id);
                                       }   
                              for (case CaseX: lscase)
                                  {   
                                   if(!conIds.contains(CaseX.ContactID))
                                       {
                                           CaseX.addError('Please select valid Contact using Lookup Search Icon');  
                                       }
                                   
                                  }         
                                       
                       }
                       
                     if(Trigger.isAfter && Trigger.isInsert) 
                       {
                         List<Case> CasesToInsert = new List<Case>();
    
                       for (case CaseX: trigger.New)
                              {
                               Case NewCase  = new Case(Id = CaseX.Id); 
                               
                               List<User> usrList = new List<User>([SELECT id, Formula_Profiel_name__c from user where        Id = :UserInfo.getuserId() LIMIT 1]);
                               List<User> CntList = new List<user>([SELECT id, Name, Email, UserName   from User where ContactId = :CaseX.ContactID LIMIT 1]);
                         
                               for (User usr : usrList)
                               {
                                   if(Usr.Formula_Profiel_name__c == System.Label.U4_PS_Consultant) {           
                                    
                                      NewCase.PS_Owner__c = UserInfo.getuserId(); 
                                      Update NewCase; 
Trigger
___________
Trigger RecordPSOwnerAndMainContact on Case (before insert,after Insert) 
{
public  List<Case> lscase=Trigger.New;
     public  List<ID> acntsIds=new List<ID>();
     public Set<ID> conIds=new Set<ID>();
        
       Profile CurrentUserprofile = [select Name from Profile where Id = :UserInfo.getProfileId() LIMIT 1 ];
          if(CurrentUserprofile.Name ==System.Label.U4_PS_Consultant)
                 {    
                    if(Trigger.isBefore && Trigger.isInsert) 
                       {
                            for(Case c : lscase)
                                {
                                 acntsIds.add(c.AccountID);
                                }
                             List<Contact> ls = new List<Contact>([SELECT id, Name, Email from Contact where AccountId IN : acntsIds]);
                             for(Contact c : ls)
                                       {
                                       conIds.add(c.Id);
                                       }   
                              for (case CaseX: lscase)
                                  {   
                                   if(!conIds.contains(CaseX.ContactID))
                                       {
                                           CaseX.addError('Please select valid Contact using Lookup Search Icon');  
                                       }
                                   
                                  }         
                                       
                       }
                       
                     if(Trigger.isAfter && Trigger.isInsert) 
                       {
                         List<Case> CasesToInsert = new List<Case>();
    
                       for (case CaseX: trigger.New)
                              {
                               Case NewCase  = new Case(Id = CaseX.Id); 
                               
                               List<User> usrList = new List<User>([SELECT id, Formula_Profiel_name__c from user where        Id = :UserInfo.getuserId() LIMIT 1]);
                               List<User> CntList = new List<user>([SELECT id, Name, Email, UserName   from User where ContactId = :CaseX.ContactID LIMIT 1]);
                         
                               for (User usr : usrList)
                               {
                                   if(Usr.Formula_Profiel_name__c == System.Label.U4_PS_Consultant) {           
                                    
                                      NewCase.PS_Owner__c = UserInfo.getuserId(); 
                                      Update NewCase; 
                          
                                      List<CaseTeam__c> CaseTeamMember = new List<CaseTeam__c>();
                                      CaseTeam__c CaseTeam = new CaseTeam__c (); 
                                     
                                      CaseTeam.case__c = CaseX.id;                                                  
                                      CaseTeam.Type_of_User__c = 'PS User';                                        
                                      CaseTeam.MemberRole__c = 'Unit4 PS Consultant';                                    
                                      CaseTeam.User__c = UserInfo.getuserId();                                 
                                      CaseTeamMember.add(CaseTeam); 
                                      insert CaseTeamMember; 
                                     
                                      For (User Cntxt : CntList)
                                      {
                                        List<CaseTeam__c> CaseContactTeamMember = new List<CaseTeam__c>();
                                        CaseTeam__c ContactMember = new CaseTeam__c (); //** New member
                                     
                                        ContactMember.case__c = CaseX.id;
                                        ContactMember.Type_of_User__c = 'Customer User';
                                        ContactMember.MemberRole__c = 'Main Contact';
                                        ContactMember.Contact__C = CaseX.ContactID;
                                        ContactMember.User__c = Cntxt.id;
                                        CaseContactTeamMember .add(ContactMember); 
                                        insert CaseContactTeamMember; 
                                      }
                                          
                                   }
                                   Else
                                   {   
                                      For (User Cntxt : CntList)
                                      {
                                        List<CaseTeam__c> CaseContactTeamMember = new List<CaseTeam__c>();
                                        CaseTeam__c ContactMember = new CaseTeam__c ();  //** New member
                                       
                                        ContactMember.case__c = CaseX.id;
                                        ContactMember.Type_of_User__c = 'Customer User';
                                        ContactMember.MemberRole__c = 'Main Contact';
                                        ContactMember.Contact__C = CaseX.ContactID;
                                        ContactMember.User__c = Cntxt.id;
                                        CaseContactTeamMember .add(ContactMember); 
                                        insert CaseContactTeamMember; 
                                      }
                                      NewCase.PS_Owner__c = NULL; 
                                      Update NewCase;
                                      
                                   }
                               }
                           }
                       }
                 }
}

test class
-------------------------------------

private static testMethod void SECaseTriggerHandlerTest1(){
   
     Case objCase1 = [select id from Case where Status ='New'];
 
     test.startTest();
     
        SEConstants.Case_Beforeupdate= true;
        objCase1.OwnerId = UserInfo.getUserId();
        update objCase1;
        
        System.assertEquals(UserInfo.getUserId(),objCase1.OwnerId);
            
        SEConstants.Case_Beforeupdate= true;
        SEConstants.Case_Afterupdate= true;
        objCase1.Status = SEConstants.CASE_STATUS_OWNED;
        DateTime currentDate = System.now();
        DateTime newDate = currentDate.addMinutes(-20); 
        objCase1.DeadLine__c = newDate;
        update objCase1;
        
        System.assertEquals(newDate,objCase1.DeadLine__c);
               
        Notification_Table__c objNotificationTable =  [select id from Notification_Table__c where Notification_Status__c = 'Scheduled' ];
        objNotificationTable.Case__c = objCase1.id;
        update objNotificationTable;  
        
        System.assertEquals(objCase1.id,objNotificationTable.Case__c);        
                
        SEConstants.Case_Beforeupdate= true;
        SEConstants.Case_Afterupdate= true;
        
        objCase1.Status = SEConstants.CASE_STATUS_PENDING_EXTERNAL_INFO;
        update objCase1;
                        
        System.assertEquals(SEConstants.CASE_STATUS_PENDING_EXTERNAL_INFO,objCase1.Status);
                  
        SEConstants.Case_Afterupdate= true;
        SEConstants.Case_Beforeupdate= true;
        objCase1.Status = SEConstants.CASE_INPROGRESS;       
        update objCase1;
            
        System.assertEquals( SEConstants.CASE_INPROGRESS, objCase1.Status);
      
        Notification_Master__c objNotificationMaster2 = [select id from Notification_Master__c where No_of_Days__c = 6];        
        objNotificationMaster2.Case_Status__c = 'Completed';
        update objNotificationMaster2;
       
    test.stopTest(); 
}

private static testMethod void RecordPsmaincontacttest(){
   
    test.startTest();
    
        Case objCase1 = [select id from Case where Status ='New'];
          
        SEConstants.Case_Beforeupdate= true;
        objCase1.OwnerId = UserInfo.getUserId();
        update objCase1;
        
        System.assertEquals(UserInfo.getUserId(),objCase1.OwnerId);
             
        SEConstants.Case_Afterupdate= true;
        SEConstants.Case_Beforeupdate= true;
        objCase1.Status = SEConstants.CASE_STATUS_OWNED;
        objCase1.isNewPublicComment__c = true;
        update objCase1;
        
        System.assertEquals( true, objCase1.isNewPublicComment__c);
          
        SEConstants.Case_Afterupdate= true;
        SEConstants.Case_Beforeupdate= true;
        objCase1.Status = SEConstants.CASE_INPROGRESS;
        objCase1.isNeweMailadded__c = true;
        objCase1.isNewPublicComment__c = false;
        update objCase1;
        
        System.assertEquals( SEConstants.CASE_INPROGRESS, objCase1.Status);
          
        SEConstants.Case_Beforeupdate= true;
        SEConstants.Case_Afterupdate= true;
        objCase1.Status = 'Closed';
        objCase1.CloseCase__c=true;
        update objCase1;
        
        System.assertEquals('Closed', objCase1.Status);

    test.stopTest();
}
public static testMethod void SECaseTriggerHandlerTest3() {
    
    Contact SampleContact = [select id from Contact where Lastname = 'testContact1'];

    Profile objProfile = TestUtility.getProfileByProfileName(SEConstants.PROFILE_PRIMARY_SUPPORT_CONTACT);

    User objUser = TestUtility.createUser(objProfile , SampleContact.id);
    objUser = (User)TestUtility.createAndValidateSObject(objUser);
    
    CaseTeam__c objCaseTeam = [select id,MemberRole__c,User__c,Case__c from CaseTeam__c where MemberRole__c =: SEConstants.MAIN_CONTACT];
    objCaseTeam.User__c = objUser.id;
    objCaseTeam.Contact__c= SampleContact.id ;
    update objCaseTeam;
    
    CaseTeam__c objCaseTeamTest = [select id,User__c from CaseTeam__c where User__c =: objUser.id];
    
    System.assertEquals(objUser.id , objCaseTeamTest.User__c);
    
    System.runAs(objUser){
       
        test.startTest();
            caseTeamEditController objCaseTeamEditController = new caseTeamEditController(new ApexPages.StandardController(objCaseTeam));
            objCaseTeamEditController.init();
            
            List<SelectOption> ListOfOptions =  objCaseTeamEditController.getSelectedoptions();
            
            System.assertEquals(4,ListOfOptions.size());
            
            objCaseTeamEditController.save();
            objCaseTeamEditController.cancel();  
        test.stopTest();
    }
}
}
Hello

I have one workflow in which i have updated the formula as
IF( TEXT( SBQQ__SubscriptionPricing__c ) = "" , Net_Unit_Price_Monthly_WFR__c * SBQQ__Quote__r.Exchange_Rate_to_EUR_WFR__c * 
IF(TEXT( SBQQ__PricingMethod__c) = 'Block',1,SBQQ__Quantity__c) , Net_Unit_Price_Monthly_WFR__c * SBQQ__Quote__r.Exchange_Rate_to_EUR_WFR__c * 12 * IF(TEXT( SBQQ__PricingMethod__c) = 'Block',1,SBQQ__Quantity__c))
it is working now but i want to populate this formula field in below trigger.

trigger QuoteLineupdate on SBQQ__QuoteLine__c (before insert, before update) {
   for (SBQQ__QuoteLine__c QL: Trigger.new) {

    if (false && trigger.oldMap !=  null && trigger.newMap != null){  // debugging aid Wim van Beek 
        List<String> Flds = new List<String>();
        For (Schema.SObjectField FieldInfo : Schema.getGlobalDescribe().get('SBQQ__QuoteLine__c').getDescribe().fields.getMap().values()){
             String FieldName = string.valueOf(FieldInfo.getDescribe().getName());
             Flds.add(FieldName);
        }
        SBQQ__QuoteLine__c OldQ = trigger.oldMap.get(QL.id);
        SBQQ__QuoteLine__c NewQ = trigger.newMap.get(QL.id);
        for (String Fld: Flds){
            if (OldQ.get(Fld)  != NewQ.get(Fld)){
                system.debug('------ Fld Line '+ Fld + ' : ' + OldQ.get(Fld) + ' ==> '+NewQ.get(Fld));
            }
        }
    }
            
            QL.Sales_Price_Term_translation_for_ACV__c=QL.Sales_Price_Term_for_ACV__c;
            QL.Sales_Price_Term_translation_for_MCV__c=QL.Sales_Price_Term__c;
            QL.Sales_Price_Term_translation_for_TCV__c=QL.Sales_Price_Term_for_TCV__c;
            QL.sbFamily_Grouping_in_Template__c = QL.Quote_Line_Grouping_in_Template__c; 
            system.debug('QL.SBQQ__Quote__r.SBQQ__CustomerDiscount__c'+QL.SBQQ__Quote__r.SBQQ__CustomerDiscount__c);
          //  QL.Sales_Price_with_header_discount__c = String.valueOf(QL.Sales_Price__c * (1 - QL.SBQQ__Quote__r.SBQQ__CustomerDiscount__c/100));
             }
  }


Could anyone help on this.
Trigger RecordPSOwnerAndMainContact on Case (after Insert) 
{
 
  Profile CurrentUserprofile = [select Name from Profile where Id = :UserInfo.getProfileId() LIMIT 1 ];
  if(CurrentUserprofile.Name ==System.Label.U4_PS_Consultant)
     {     
   List<Case> CasesToInsert = new List<Case>();

   for (case CaseX: trigger.New){ //** Only for new created cases.
  
       Case NewCase  = new Case(Id = CaseX.Id);  //** Store unique Case ID
       
       //** Build list with details of current user (PS or not .. could by any user) ..... and list of main contact selected on case (x)
       List<User> usrList = new List<User>([SELECT id, Formula_Profiel_name__c from user where        Id = :UserInfo.getuserId() LIMIT 1]);
       List<User> CntList = new List<user>([SELECT id, Name, Email, UserName   from User where ContactId = :CaseX.ContactID LIMIT 1]);
 
       for (User usr : usrList){
           if(Usr.Formula_Profiel_name__c == System.Label.U4_PS_Consultant) { // ** Check Profile name with actual profile.
          
              //** Is case created by PS Staff member
              NewCase.PS_Owner__c = UserInfo.getuserId(); //** PS Owner value on case get ID of current user
              Update NewCase; //** Write PS Owner to case
              
              //** Build list for Custom Case team PS Owner transaction
              List<CaseTeam__c> CaseTeamMember = new List<CaseTeam__c>();
              CaseTeam__c CaseTeam = new CaseTeam__c (); //** New Member
             
              //** Populate custom case team values
              CaseTeam.case__c = CaseX.id;                                                  // Case#
              CaseTeam.Type_of_User__c = 'PS User';                                        
              CaseTeam.MemberRole__c = 'Unit4 PS Consultant';                                      // Role
              CaseTeam.User__c = UserInfo.getuserId();                                  // User (PS)
              CaseTeamMember.add(CaseTeam); 
              insert CaseTeamMember; //** Write PS Case team member to Custom Case team
             
              // Now add contact
              For (User Cntxt : CntList){
                //** Build list for custom case team for Main contact transaction
                List<CaseTeam__c> CaseContactTeamMember = new List<CaseTeam__c>();
                CaseTeam__c ContactMember = new CaseTeam__c (); //** New member
             
                //** Populate custom case team values
                ContactMember.case__c = CaseX.id;
                ContactMember.Type_of_User__c = 'Customer User';
                ContactMember.MemberRole__c = 'Main Contact';
                ContactMember.Contact__C = CaseX.ContactID;
                ContactMember.User__c = Cntxt.id;
                CaseContactTeamMember .add(ContactMember); 
                insert CaseContactTeamMember; //** Write Main contact case team member to custom case team
              }
                  
           }
           Else{   //== Not Created by PS Staff member os make sure field is empty
          
              // Now as the case was not created by PS Consultant, main contact registration is done anyway to make
              //  case registration in general much better as this will save support consultants many time and efforts.
              For (User Cntxt : CntList){
                //** Build list for custom case team for Main contact transaction
                List<CaseTeam__c> CaseContactTeamMember = new List<CaseTeam__c>();
                CaseTeam__c ContactMember = new CaseTeam__c ();  //** New member
               
                //** Populate custom case team values   
                ContactMember.case__c = CaseX.id;
                ContactMember.Type_of_User__c = 'Customer User';
                ContactMember.MemberRole__c = 'Main Contact';
                ContactMember.Contact__C = CaseX.ContactID;
                ContactMember.User__c = Cntxt.id;
                CaseContactTeamMember .add(ContactMember); 
                insert CaseContactTeamMember; //** Write Main contact case team member to custom case team
              }
          
              NewCase.PS_Owner__c = NULL; //** No PS Owner (NULL)
              Update NewCase; //** Write empty value to PS Owner field to case
              
           }
       }
   }
}
}
 
public PageReference search()
       {
       
      if(keyword.length() > 0)
         {
          String temp= keyword + '%';
          result=[select id,name,Account.name, Email,Phone from Contact where id in: conids and (Name like : temp or Email like : temp) ];
          
          //result=(List<Contact>)[FIND : keyword in Name fields returning Contact(ID,Name,Account.Name,Email,Phone where id in : conids)][0];
     
             if(result.size() > 0)
             {
             consearchlist=result;
             showsearch =true;
             showwithoutsearch=false;
             }
             else
             { 
             showsearch =false;
             showwithoutsearch=false;      
             ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,System.Label.Contact_Search_Error));
             }
         }
       else
         {
             showsearch =false;
             showwithoutsearch=false;       
             ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,System.Label.Enter_at_least_one_character));
         }  
         
     return null;
     }
}
Apex class:
public class ContactSelectionLookupController
{
   public List<Contact> contactList{get;set;}
    public boolean showsearch {get;set;}
    public boolean showwithoutsearch {get;set;}
    public String assetId{get;set;}
    public List<EntitlementContact> entcon;
    public Set<ID> conids;
    public String keyword{get;set;}
    public String message{get;set;}
    public List<Contact> result{get;set;}
    public List<Contact> displaycontactlist {get;set;}
    public List<Contact> consearchlist {get;set;}
    //public String errormessage{get;set;}
  
  
    public ContactSelectionLookupController()
    {
        consearchlist= new List<Contact>();
        entcon =new List<EntitlementContact>();
        showsearch =false;
        showwithoutsearch=true;
        conids=new Set<ID>();
        
       assetId=ApexPages.CurrentPage().getParameters().get('assetIdField');
       entcon =[SELECT ContactId,EntitlementId,Entitlement.AssetId,Id,Name FROM EntitlementContact where Entitlement.AssetId =:assetId];
       
        for(EntitlementContact ec : entcon  )
            {
              conids.add(ec.ContactId);
            }
        
        entcon =[SELECT ContactId,EntitlementId,Entitlement.AssetId,Id,Name FROM EntitlementContact where Entitlement.AssetId =:assetId];
          
        for(EntitlementContact ec : entcon  )
            {
              conids.add(ec.ContactId);
            }
      
        contactList= new List<Contact>([Select id,Name,Account.Name,Email,Phone from Contact where Id IN : conids]);
        
            If(contactList.size()>0)
            {
            displaycontactlist = contactList;
            }
            else
            {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Enter Valid Account and Asset'));
            }
    }
    
      public PageReference search()
       {
       
      if(keyword.length() > 0)
         {
         String temp= keyword + '%';
         result=[select id,name,Account.name, Email,Phone from Contact where id in: conids and (Name like : temp or Email like : temp) ];
         //result=(List<Contact>)[FIND : keyword in All fields returning Contact(ID,Name,Account.Name,Email,Phone where id in : conids)][0];
     
             if(result.size() > 0)
             {
             consearchlist=result;
             showsearch =true;
             showwithoutsearch=false;
             }
             else
             { 
             showsearch =false;
             showwithoutsearch=false;      
             ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'No Contact Found'));
             }
         }
       else
         {
             showsearch =false;
             showwithoutsearch=false;       
             ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'At least one char is required to search'));
         }  
         
     return null;
     }
}

Test class:
@isTest
public class ContactSelectionLookupControllerTest
{
 public static testMethod void ContactSelectionLookupController(){
 Product2 ObjProduct = new Product2(
        Name = 'UNIT4 Business World',
        IsActive = true,
        Service__c = true,
        Family = 'Others');
    ObjProduct = (Product2) TestUtility.createAndValidateSObject(ObjProduct);
    
    SCMC__Currency_Master__c SCM =new SCMC__Currency_Master__c();
        SCM.Name='EUR';
        SCM.SCMC__Number_of_decimals__c=2;
    SCM = (SCMC__Currency_Master__c)TestUtility.createAndValidateSObject(SCM);
         
    Account objAccount = new Account(
        name = 'abc',
        type = 'UNIT4 Company');
        
    objAccount = (Account)TestUtility.createAndValidateSObject(objAccount);
 
    Contact ObjContact = new contact(
        AccountId = objAccount.id,
        Lastname = 'tesContact',
        Email = 'Test@test.com');
    ObjContact = (Contact)TestUtility.createAndValidateSObject(ObjContact);
 
    Asset objAsset = new Asset(
        Name = 'abc',
        AccountId = objAccount.id,
        ContactId = ObjContact.id,
        Status = 'Purchased',
        Product2Id = ObjProduct.id);
    objAsset = (Asset)TestUtility.createAndValidateSObject(objAsset);
 
    category__c objFunctionalArea = new category__c(
        Name = TestUtility.LABEL_TEST ,
        Product__c = ObjProduct.id);
    objFunctionalArea = (category__c)TestUtility.createAndValidateSObject(objFunctionalArea);
 
    Sub_Module__c ObjSubModule = new Sub_Module__c(
        Name ='Reporting',
        Sub_Module__c = objFunctionalArea.id);
    ObjSubModule = (Sub_Module__c)TestUtility.createAndValidateSObject(ObjSubModule);
 
    Entitlement objEntitlement = new Entitlement(
        AssetId = objAsset.id,
        Name ='Entitlement For UNIT4 HRM Portal',
        AccountId = objAccount.id);
    objEntitlement = (Entitlement)TestUtility.createAndValidateSObject(objEntitlement);
 
    ProductVersion__c objProductVersion = new ProductVersion__c(
        Name = 'sdasd',
        Product__c = ObjProduct.id);
    objProductVersion = (ProductVersion__c)TestUtility.createAndValidateSObject(objProductVersion);
 
    ProductUpdate__c objProductUpdate = new ProductUpdate__c(
        Name = TestUtility.LABEL_TEST ,
        ProductVersion__c = objProductVersion.id);
    objProductUpdate = (ProductUpdate__c)TestUtility.createAndValidateSObject(objProductUpdate);
 
    Environment__c objEnvironment = new Environment__c(
        DB__c = 'ORACLE 11',
        OS__c = 'Windows 7',
        Product__c = ObjProduct.id,
        Type__c = 'Live',
        Active__c = true,
        Asset__c = objAsset.id,
        ProductVersion__c = objProductVersion.id,
        Update__c = objProductUpdate.id);
    objEnvironment = (Environment__c)TestUtility.createAndValidateSObject(objEnvironment);
 
  ContactSelectionLookupController con=new ContactSelectionLookupController();
  
 }
 }

Please help on this

Hi all

i am trying to align my command link in center but its not working i have used all the css properties like align and float in my command link but still its not working

 

<apex:page standardController="Opportunity" extensions="oppcontrolleraugust">

 <apex:form >
  
  <apex:pageBlock title="Opportunity details"  id="pbb">
  <apex:pageblockButtons location="bottom">
  <apex:commandbutton value="Save & Addproduct" action="{!save}" />
 <!--<apex:commandbutton value="AddProduct" action="{!Product}" />-->
   </apex:pageblockButtons>
   <apex:pageblockSection title="Opportunity" columns="1">
    
  
<!----<apex:selectList id="locationLookupPicklist" value="{!accountid}" size="1" rendered="true" >  
<apex:selectOptions value="{!locationOptions}"/>  
</apex:selectList>---->    
      
     <apex:pageBlockSectionItem >   
      Account Name 
                <apex:actionRegion >
                <apex:inputText value="{!name1}" size="10" title="Keyword" >
                    <apex:actionSupport event="onkeyup"  action="{!search}" reRender="pnid"/>
                </apex:inputText>
                &nbsp;&nbsp;
                <apex:inputField value="{!opp.Accountid}" id="look" >
                 <apex:actionSupport event="onchange" reRender=""/>
                  </apex:inputField>
                
            <apex:outputPanel id="pnid">
            <apex:pageBlockTable value="{!allAccs}" var="a"  rendered="{!showtable}">
                <apex:column >
                    <apex:commandLink value="{!a.Name}" action="{!selectAcc}" reRender="pbb" >
                        <apex:param value="{!a.id}" name="{!a.Name}" assignTo="{!accId}"/>
                    </apex:commandLink>
                </apex:column>
            </apex:pageBlockTable>
            </apex:outputPanel>
            </apex:actionRegion>
            
   </apex:pageBlockSectionItem> 
 <apex:commandlink style="float:centre" value="Create New Account" action="{!acc}" />
 <apex:inputfield label="Contact" value="{!opp.Quotation_Contact__c}"/>
      
      <apex:inputfield value="{!opp.Name}"/>
      <!--<apex:inputfield value="{!opp.CurrencyIsoCode}"/>-->
      
   <!---   <apex:inputfield value="{!opp.Accountid}"/>  ---->
      
      <!--<apex:inputfield value="{!opp.Type}"/>-->
      <!--<apex:inputField value="{!opp.StageName}"/>-->
      </apex:pageblockSection><br/><br/><br/>
      </apex:pageblock>
      </apex:form>
      </apex:page>

Hi all,

I have a currecy field and needs to convert it into words without clicking any button.
Ex: Amount : Rs.1,10,521
 It should be converted into text as "1 lakh 10 thousand five hundred and twenty 1 Rupees only".

Plese suggest me
@RestResource (urlMapping='/LeadbyLivServ/*')
global with sharing class LeadbyLivServ {
    @HttpPost
    global static string createLead(){
        String response  = '';
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        Map<String,String> paramsGot = req.params;
        System.debug('PARAMS GOT :'+paramsGot);
        System.debug('BODY GOT :'+(req.requestBody).toString());
        String callJsonData = (req.requestBody).toString();
        System.debug('callJsonData---'+callJsonData);
        JSONParser parser = JSON.createParser(callJsonData);
        Map<String, Object> m = (Map<String, Object>)JSON.deserializeUntyped(callJsonData);
        Lead leadRecord = new Lead();
        leadRecord.FirstName = ''+m.get('first_name');
        leadRecord.LastName = ''+m.get('last_name');
        leadRecord.Email = ''+m.get('email');
        leadRecord.MobilePhone = ''+m.get('mobile');
        leadRecord.Phone = ''+m.get('mobile');
        leadRecord.Description = EncodingUtil.urlDecode(''+m.get('description'),'UTF-8');
        leadRecord.Date_Of_Enquiry__c = System.today();
        List<Lead> existingLead = new List<Lead>();
        JSONGenerator gen = JSON.createGenerator(true);
        gen.WriteStartObject();
        if(existingLead.size() > 0){
            gen.WriteStringField('success','failure');  
            gen.WriteFieldName('errors');
            gen.writeStartArray();
            System.debug('99999'+leadRecord.Email.equalsIgnoreCase(''+m.get('email')));
            if(existingLead[0].Email.equalsIgnoreCase(''+m.get('email'))){
                gen.writeStartObject();
                gen.writeStringField('email','Already exists');
                gen.writeEndObject();
            }
            System.debug('00000'+leadRecord.MobilePhone.equalsIgnoreCase(''+m.get('mobile')));
            if(existingLead[0].MobilePhone.equalsIgnoreCase(''+m.get('mobile'))){
                gen.writeStartObject();
                gen.writeStringField('mobile','Already exists');
                gen.writeEndObject();
            }
            gen.writeEndArray();
        }else{
        
            // to turn the Assignment Rules on
            Database.DMLOptions dmo = new Database.DMLOptions();
            //dmo.assignmentRuleHeader.useDefaultRule = true;
            dmo.assignmentRuleHeader.assignmentRuleId = '01Q10000000UHEi';
            leadRecord.setOptions(dmo);  
            insert leadRecord;
            gen.WriteStringField('success','success');
            gen.WriteStringField('errors','');
        }
        gen.writeEndObject();
        response = gen.getAsString();
        System.debug('RESPONSE IS :'+response);        
           
           return response;
    }
}
<apex:page sidebar="false" showHeader="false" applyBodyTag="false" applyHtmlTag="false" contentType="text/xml" standardStylesheets="false">
  <?xml version="1.0" encoding="UTF-8" ?>
   <response>
              <is_registered>yes</is_registered>
              <is_workinghour>yes</is_workinghour>
              <Lead>00Q9000000Kwe6IEAR</Lead>
              <CallID>04153c09-8018-4cba-b03e-cd98a80f30b0</CallID>
              <agent_number_count>3</agent_number_count>
              <agent_list>
              <agent id="1">
              <agent_number>2228241485</agent_number>
              <agent_code>0004</agent_code>
              </agent>
              <agent id="2">
              <agent_number>2228321017</agent_number>
              <agent_code>0003</agent_code>
              </agent>
              <agent id="3">
              <agent_number>9699850686</agent_number>
              <agent_code>0001</agent_code>
              </agent>
              </agent_list>
              </response>
</apex:page>
public class status{
public Candidates__c applicant;
public Blob resume {get; set;}
public String contentType {get; set;}
public String fileName {get; set;}

public status(ApexPages.StandardController stdController) {
this.applicant=(Candidates__c)stdController.getRecord();
}
public PageReference saveApplication() {

  try{
        insert(applicant);                                       
   }catch(System.DMLException e){
      ApexPages.addMessages(e);
       return null;
}

if(resume!=null){
      Attachment attach=new Attachment();
      attach.Body=resume;
      attach.Name=filename;
      attach.ContentType=contentType;
      attach.ParentID=applicant.id;
    try {
          insert(attach);
      } catch(System.DMLException e) {
          ApexPages.addMessages(e);
          return null;
      }
  }
  //PageReference p = new ApexPages.StandardController(applicant).view();
        PageReference p =Page.Resume_Parsing;
        p.setRedirect(true);
        return p;                    
}
}




Test Class:


@isTest
public class Teststatus {

public  static testMethod void teststatus(){    
              
             
            Candidates__c opp=new Candidates__c(First_Name__c='test12',Email__c='testfdc@gmail.com',Last_Name__c='fff',Phone__c='9999999999');
            insert opp;
           
            Attachment myAttach1 = new Attachment();
            myAttach1.ParentId =opp.id;
            myAttach1.name = 'Resume_Parsing.pdf';
        
            myAttach1.body = blob.valueof('test');
          
            insert myAttach1;
          
            status atc = new status(new ApexPages.StandardController(opp));
            system.debug('%%%%%'+atc);
            PageReference pageRef = Page.Resume_Parsing;
            pageRef.getParameters().put('id', String.valueOf(opp.Id));
            Test.setCurrentPage(pageRef);
            Blob b;

           ApexPages.currentPage().getParameters().put('id', opp.id);
          status atc1 = new status(new ApexPages.StandardController(myAttach1));
    

       
 
          
           atc.saveApplication();
           
           return;
       }

}


Error Message System.TypeException: Invalid conversion from runtime type SOBJECT:Attachment to SOBJECT:Candidates__c
Stack Trace Class.status.<init>: line 8, column 1
Class.Teststatus.teststatus: line 26, column 1

 
public PageReference search()
       {
       
      if(keyword.length() > 0)
         {
          String temp= keyword + '%';
          result=[select id,name,Account.name, Email,Phone from Contact where id in: conids and (Name like : temp or Email like : temp) ];
          
          //result=(List<Contact>)[FIND : keyword in Name fields returning Contact(ID,Name,Account.Name,Email,Phone where id in : conids)][0];
     
             if(result.size() > 0)
             {
             consearchlist=result;
             showsearch =true;
             showwithoutsearch=false;
             }
             else
             { 
             showsearch =false;
             showwithoutsearch=false;      
             ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,System.Label.Contact_Search_Error));
             }
         }
       else
         {
             showsearch =false;
             showwithoutsearch=false;       
             ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,System.Label.Enter_at_least_one_character));
         }  
         
     return null;
     }
}
Hi all,

I have a currecy field and needs to convert it into words without clicking any button.
Ex: Amount : Rs.1,10,521
 It should be converted into text as "1 lakh 10 thousand five hundred and twenty 1 Rupees only".

Plese suggest me
Hello,

This is the trailhead questions which I am trying to solve :

Create an Apex class that returns an array (or list) of formatted strings ('Test 0', 'Test 1', ...). The length of the array is determined by an integer parameter.The Apex class must be called 'StringArrayTest' and be in the public scope.
The Apex class must have a public static method called 'generateStringArray'.
The 'generateStringArray' method must return an array (or list) of strings. Each string must have a value in the format 'Test n' where n is the index of the current string in the array. The number of returned strings is specified by the integer parameter to the 'generateStringArray' method.


Here is my code :

public class StringArrayTest {
    public static List <String> generateStringArray (Integer n) {
       List<String> List1 = new List<String> ();
        for(Integer i=0;i<n;i++) {
          List1.add('\'Test'+ i+'\'' );
  }
        System.debug(List1);
        return List1;
    } 

}


I am getting following error :

Challenge not yet complete... here's what's wrong: 
Executing the 'generateStringArray' method failed. Either the method does not exist, is not static, or does not return the proper number of strings.


I tried it many times but I am not able to solve this problem. Please help. 



 
public class status{
public Candidates__c applicant;
public Blob resume {get; set;}
public String contentType {get; set;}
public String fileName {get; set;}

public status(ApexPages.StandardController stdController) {
this.applicant=(Candidates__c)stdController.getRecord();
}
public PageReference saveApplication() {

  try{
        insert(applicant);                                       
   }catch(System.DMLException e){
      ApexPages.addMessages(e);
       return null;
}

if(resume!=null){
      Attachment attach=new Attachment();
      attach.Body=resume;
      attach.Name=filename;
      attach.ContentType=contentType;
      attach.ParentID=applicant.id;
    try {
          insert(attach);
      } catch(System.DMLException e) {
          ApexPages.addMessages(e);
          return null;
      }
  }
  //PageReference p = new ApexPages.StandardController(applicant).view();
        PageReference p =Page.Resume_Parsing;
        p.setRedirect(true);
        return p;                    
}
}




Test Class:


@isTest
public class Teststatus {

public  static testMethod void teststatus(){    
              
             
            Candidates__c opp=new Candidates__c(First_Name__c='test12',Email__c='testfdc@gmail.com',Last_Name__c='fff',Phone__c='9999999999');
            insert opp;
           
            Attachment myAttach1 = new Attachment();
            myAttach1.ParentId =opp.id;
            myAttach1.name = 'Resume_Parsing.pdf';
        
            myAttach1.body = blob.valueof('test');
          
            insert myAttach1;
          
            status atc = new status(new ApexPages.StandardController(opp));
            system.debug('%%%%%'+atc);
            PageReference pageRef = Page.Resume_Parsing;
            pageRef.getParameters().put('id', String.valueOf(opp.Id));
            Test.setCurrentPage(pageRef);
            Blob b;

           ApexPages.currentPage().getParameters().put('id', opp.id);
          status atc1 = new status(new ApexPages.StandardController(myAttach1));
    

       
 
          
           atc.saveApplication();
           
           return;
       }

}


Error Message System.TypeException: Invalid conversion from runtime type SOBJECT:Attachment to SOBJECT:Candidates__c
Stack Trace Class.status.<init>: line 8, column 1
Class.Teststatus.teststatus: line 26, column 1