• MOHAMMED BABA
  • NEWBIE
  • 10 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 4
    Replies
  1. Create a new field (Commission) on Opportunity object and it should automatically calculate the commission based on the below conditions:
  • If Lead Source is Web and Amount is greater than 1,000 then the commission is 2% of the Amount.
Apex class ----
public without sharing class AnnouncementController    {
    @AuraEnabled(cacheable=true)
    public static List<Object_A> getNews(){
        List<user> user=  [Select Id,c_User_Country__c,ContactId,  isPortalEnabled from User where id= :UserInfo.getUserId()];
        System.debug('user->'+user);
        List<Object_A> newsRecords = new List<Object_A>();
        List<Object_A> nonDashboardRecords = new List<Object_A>();
        String userCountry =user[0].c_User_Country__c;
        String custType;
        Contact cont = getContact(UserInfo.getUserId());
        if (cont!=null){
            custType= cont.Account.Sub_Type__c;
            for(Object_A jc: [SELECT id,name,Title__c,Youtube_Video_Id__c, Image_URL__c, CreatedDate ,CreatedBy.Name,Is_Dashboard_Content__c  from Object_A where                           
                                    ((Start_Date__c <= TODAY AND End_Date__c >= TODAY) OR (Start_Date__c = null AND End_Date__c = null))
                                    AND (Country__c = :userCountry OR Country__c = 'Global') AND Customer_Type__c INCLUDES (:custType) AND Type__C='News' ORDER BY Sequence__c,CreatedDate ASC]){
                                        if(jc.Is_Dashboard_Content__c){
                                            newsRecords.add(jc);   
                                        }else{
                                            nonDashboardRecords.add(jc);  
                                        }    }
                                   
            newsRecords.addAll(nonDashboardRecords);
        }
        if (newsRecords==null || newsRecords.size()==0){
            userCountry = 'Other';
            if (cont==null){
                for(Object_A jc: [SELECT id,name,Title__c,Youtube_Video_Id__c, Image_URL__c, CreatedDate ,CreatedBy.Name,Is_Dashboard_Content__c  from Object_A where
                                        ((Start_Date__c <= TODAY AND End_Date__c >= TODAY) OR (Start_Date__c = null AND End_Date__c = null) )
                                        AND (Country__c = :userCountry OR Country__c = 'Global') AND Type__C='News' ORDER BY Sequence__c,CreatedDate ASC]){
                                            if(jc.Is_Dashboard_Content__c){
                                                newsRecords.add(jc);   
                                            }else{
                                                nonDashboardRecords.add(jc);  
                                            }     
                                        }
                newsRecords.addAll(nonDashboardRecords);
            }else{
                for(Object_A jc: [SELECT id,name,Title__c,Youtube_Video_Id__c, Image_URL__c, CreatedDate ,CreatedBy.Name,Is_Dashboard_Content__c  from Object_A where
                                        ((Start_Date__c <= TODAY AND End_Date__c >= TODAY) OR (Start_Date__c = null AND End_Date__c = null))
                                        AND (Country__c = :userCountry OR Country__c = 'Global') AND Customer_Type__c INCLUDES (:custType) AND Type__C='News' ORDER BY Sequence__c,CreatedDate ASC]){
                                            if(jc.Is_Dashboard_Content__c){
                                                newsRecords.add(jc);   
                                            }else{
                                                nonDashboardRecords.add(jc);  
                                            }     
                                        }
                newsRecords.addAll(nonDashboardRecords);
            }
        }
        system.debug('newsRecords :::'+ newsRecords);
        return newsRecords;
    }

 

Apex class
global class ModelLevel{
global static String getfunction(){
      String fpmsg;
      User usr = [select Id,Name,accountid,c_User_Country__c From User where Id = :UserInfo.getUserId() LIMIT 1];
 List<ObjectA__c> rcmsg = new List<ObjectA__c>();
      rcmsg  =[SELECT body__c from ObjectA__c where Type__C='homemessage' AND Country__c=:usr.c_User_Country__c  LIMIT 1];
           if(rcmsg!=null && !rcmsg.isEmpty() ){
               if(rcmsg[0].body__c!=null && rcmsg[0].body__c!=''){
                   fpmsg =rcmsg[0].body__c;
                    }
               else{
                   rcmsg =[SELECT id,name,Title__c,body__c from ObjectA__c where Type__C='homemessage' AND Country__c ='Global' LIMIT 1];
                                                fpmsg= rcmsg[0].body__c;
     }
          }
               else{
               rcmsg =[SELECT id,name,Title__c,body__c from ObjectA__c where Type__C='homemessage' AND Country__c ='Global' LIMIT 1];
                              fpmsg= rcmsg[0].body__c;
      }
      return fpmsg.unescapeHtml4();  
    }
########################################################
Test class

@isTest
Global class Modelleveltest
{

 private static testMethod void test_getfunction (){
        Account acc = CreateTestDataUtility.createAccount();
        Contact con = CreateTestDataUtility.createContact(acc);
        Contact con1 = CreateTestDataUtility.createContact(acc);
                Profile p = [SELECT Id FROM Profile WHERE Name = 'Sales User' LIMIT 1];
                 User localUser= new User
                profileId = p.id,
                username = 'Test33@test.com.test',
                email = 'Test33@test.com.test',
                emailencodingkey = 'UTF-8',
                localesidkey = 'en_US',
                languagelocalekey = 'en_US',
                timezonesidkey='America/Los_Angeles',
                alias='test22',
                lastname='Testing22',
                contactId=con.id,
                country =  'Turkey',
                Geographic_Region__c='Europe',                  
                c_User_Country__c = 'Turkey',
                User_Region__c = 'Turkey'
            );
        insert localUser;
       
        User TestUser= new User(
                          
                profileId = p.id,
                username = '23@test.com.test',
                email = '23@test.com.test',
                emailencodingkey = 'UTF-8',
                localesidkey = 'en_US',
                languagelocalekey = 'en_US',
                timezonesidkey='America/Los_Angeles',
                alias='newtest3',
                lastname='Testing3',
                contactId=con1.id,
                country = 'France',
                Geographic_Region__c='Europe',                   
                c_User_Country__c = 'France',
                User_Region__c = 'France'
            );
               insert TestUser;
List< ObjectA__c > Newval = new List< ObjectA__c >();
ObjectA__c usr1 = new ObjectA__c (Name='Content11',Country__c='Turkey',Customer_Type__c='Distributor',Title__c='Test Content',Body__c='Testconentnew',Type__c=' homemessage ');
Newval.add(usr1);
ObjectA__c usr2 = new ObjectA__c (Name='Content22',Country__c='Global',Customer_Type__c='Distributor',Title__c='Test Content test',Body__c='TestContentnewmsg',Type__c=' homemessage ');
Newval.add(usr2);
insert Newval;
        Test.StartTest();
        System.runAs(localUser){
  ModelLevel. getfunction ();
        }
                System.runAs(TestUser){
  ModelLevel. getfunction ();
                }
            Test.StopTest();
        }
}




      
 
  1. Create a new field (Commission) on Opportunity object and it should automatically calculate the commission based on the below conditions:
  • If Lead Source is Web and Amount is greater than 1,000 then the commission is 2% of the Amount.

Apex class
global class ModelLevel{
global static String getfunction(){
      String fpmsg;
      User usr = [select Id,Name,accountid,c_User_Country__c From User where Id = :UserInfo.getUserId() LIMIT 1];
 List<ObjectA__c> rcmsg = new List<ObjectA__c>();
      rcmsg  =[SELECT body__c from ObjectA__c where Type__C='homemessage' AND Country__c=:usr.c_User_Country__c  LIMIT 1];
           if(rcmsg!=null && !rcmsg.isEmpty() ){
               if(rcmsg[0].body__c!=null && rcmsg[0].body__c!=''){
                   fpmsg =rcmsg[0].body__c;
                    }
               else{
                   rcmsg =[SELECT id,name,Title__c,body__c from ObjectA__c where Type__C='homemessage' AND Country__c ='Global' LIMIT 1];
                                                fpmsg= rcmsg[0].body__c;
     }
          }
               else{
               rcmsg =[SELECT id,name,Title__c,body__c from ObjectA__c where Type__C='homemessage' AND Country__c ='Global' LIMIT 1];
                              fpmsg= rcmsg[0].body__c;
      }
      return fpmsg.unescapeHtml4();  
    }
########################################################
Test class

@isTest
Global class Modelleveltest
{

 private static testMethod void test_getfunction (){
        Account acc = CreateTestDataUtility.createAccount();
        Contact con = CreateTestDataUtility.createContact(acc);
        Contact con1 = CreateTestDataUtility.createContact(acc);
                Profile p = [SELECT Id FROM Profile WHERE Name = 'Sales User' LIMIT 1];
                 User localUser= new User
                profileId = p.id,
                username = 'Test33@test.com.test',
                email = 'Test33@test.com.test',
                emailencodingkey = 'UTF-8',
                localesidkey = 'en_US',
                languagelocalekey = 'en_US',
                timezonesidkey='America/Los_Angeles',
                alias='test22',
                lastname='Testing22',
                contactId=con.id,
                country =  'Turkey',
                Geographic_Region__c='Europe',                  
                c_User_Country__c = 'Turkey',
                User_Region__c = 'Turkey'
            );
        insert localUser;
       
        User TestUser= new User(
                          
                profileId = p.id,
                username = '23@test.com.test',
                email = '23@test.com.test',
                emailencodingkey = 'UTF-8',
                localesidkey = 'en_US',
                languagelocalekey = 'en_US',
                timezonesidkey='America/Los_Angeles',
                alias='newtest3',
                lastname='Testing3',
                contactId=con1.id,
                country = 'France',
                Geographic_Region__c='Europe',                   
                c_User_Country__c = 'France',
                User_Region__c = 'France'
            );
               insert TestUser;
List< ObjectA__c > Newval = new List< ObjectA__c >();
ObjectA__c usr1 = new ObjectA__c (Name='Content11',Country__c='Turkey',Customer_Type__c='Distributor',Title__c='Test Content',Body__c='Testconentnew',Type__c=' homemessage ');
Newval.add(usr1);
ObjectA__c usr2 = new ObjectA__c (Name='Content22',Country__c='Global',Customer_Type__c='Distributor',Title__c='Test Content test',Body__c='TestContentnewmsg',Type__c=' homemessage ');
Newval.add(usr2);
insert Newval;
        Test.StartTest();
        System.runAs(localUser){
  ModelLevel. getfunction ();
        }
                System.runAs(TestUser){
  ModelLevel. getfunction ();
                }
            Test.StopTest();
        }
}