• Nishad Basha
  • NEWBIE
  • 64 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 55
    Questions
  • 68
    Replies
User-added image

How i change the -24 (negative value will be changed to positive ) how to solve the above scenario please give some ideas.
global class ScheduledApexOnCase implements Schedulable {    
 
    global void execute(SchedulableContext sc) {
     
    Date today = system.today();
    Decimal caseAge;
    List<case> newCaseList = new List<case>();
     
    BusinessHours stdBusinessHours = [select id from businesshours where isDefault = true];
    newCaseList = [Select id, CreatedDate, Status, CaseAge__c from Case]; //CaseAge__c is a Text field
    for(Case eachCase: newCaseList) {        
        if(eachCase.Status != 'Closed') 
            caseAge = BusinessHours.diff(stdBusinessHours.id, eachCase.CreatedDate, today) / 1000 / 3600; 
        else
            caseAge = BusinessHours.diff(stdBusinessHours.id, eachCase.CreatedDate, eachCase.ClosedDate) / 1000 / 3600;
        eachCase.CaseAge__c = String.valueOf(caseAge) + ' hours';        
    }
    update newCaseList;
    }    
}

Here iam getting  Compile Error: Illegal assignment from String to Decimal at line 16 column 9, How to solve the above scenario please give me some ideas
How to write the test class for multiple users.please give me the example of above scenario.
our Requirement is some reoprts in my organization when iam click reports it will show Report related  records.How to solve the above scenario please give me some ideas.
can you plase give me the example of above scenario please give some ideas.
can you please give me the example of above scenario.please give some ideas.
iam using this example so far: http://www.sandeeparora.org/2014/10/example-serialize-objects-into-json-strings-in-apex/
iam getting error like: AccountJSON Compile Error: line breaks not allowed in string literals at line 16 column -1
How to solve the above solution please give me some ideas.
when iam enter the Account Name like a 'balu'  and click the get Account that time display the that account id not showing. please give some ideas .User-added image
how to concatenating Account of contacts using formulas in salesforce. how to solve above scenario please give some ideas.
@RestResource(urlMapping='/MyAccount12/*')
global with sharing class MyAccountRest {

    @HttpDelete
    global static void doDelete() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        Account account = [SELECT Id FROM Account WHERE Id = :accountId];
        delete account;
    }
  
    @HttpGet
    global static Account doGet() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE Id = :accountId];
        return result;
    }
  
  @HttpPost
    global static String doPost(String name,
        String phone, String website) {
        Account account = new Account();
        account.Name = name;
        account.phone = phone;
        account.website = website;
        insert account;
        return account.Id;
    }
}

above code how to write the test class so far.please give some ideas.
can you please give me the examples of above scenario.
give me the example of above scenario please give some ideas.
How to integrating above scenario please give some ideas.
How to write the restricted user test cases i nsalesforce .please give me the example of above scenario.
my requirement is display the employee Name,designation,salaryscale, increment,grade using Batch apex how to solve the above scenario please give some ideas
can you plase give me the example of above scenario please give some ideas.
@RestResource(urlMapping='/MyAccount12/*')
global with sharing class MyAccountRest {

    @HttpDelete
    global static void doDelete() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        Account account = [SELECT Id FROM Account WHERE Id = :accountId];
        delete account;
    }
  
    @HttpGet
    global static Account doGet() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE Id = :accountId];
        return result;
    }
  
  @HttpPost
    global static String doPost(String name,
        String phone, String website) {
        Account account = new Account();
        account.Name = name;
        account.phone = phone;
        account.website = website;
        insert account;
        return account.Id;
    }
}

above code how to write the test class so far.please give some ideas.
my requirement is display the employee Name,designation,salaryscale, increment,grade using Batch apex how to solve the above scenario please give some ideas
can you give me the examples above scenario.plase give some ideas.
how write the Test class for batch apex we need for our requirement.ple
global class bchrankupdate implements database.batchable<sObject>{

 List<Batchrank__c> newbatchmark = new List<Batchrank__c>();
 
  global database.querylocator start(database.BatchableContext BC){
   String Query = 'SELECT name, Percents__c, TestRanks__c, Rank__c FROM Batchrank__c';
   return Database.getQueryLocator(query);
  }
  
  global void execute(database.BatchableContext BC, List<Batchrank__c> s){
  system.debug('batch size:'+s.size());
   for(Batchrank__c br : s){
   system.debug('record:'+br);
   
   if(br.Percents__c >= 90 && br.Percents__c <= 100){
    if(br.TestRanks__c=='First')   
   {
    br.Rank__c = '1';
     newbatchmark.add(br);
     
   }else{
     br.Rank__c = 'Empty';
     newbatchmark.add(br);
     }
          
   }else if(br.Percents__c >= 80 && br.Percents__c <= 89){
     if(br.TestRanks__c=='Second'){
     br.Rank__c = '2';
     newbatchmark.add(br);
     
   }else{
     br.Rank__c = ' ';
     newbatchmark.add(br);
     }
        
   }else if(br.Percents__c >= 70 && br.Percents__c <= 79){
     if(br.TestRanks__c=='Third'){
      br.Rank__c = '3';
      newbatchmark.add(br);
     
   }else{
     br.Rank__c = ' ';
     newbatchmark.add(br);
     }
            
   }else if(br.Percents__c >= 60 && br.Percents__c <= 69){
     if(br.TestRanks__c=='Fourth'){
     br.Rank__c = '4';
     newbatchmark.add(br);
     
   }else{
     br.Rank__c = ' ';
     newbatchmark.add(br);
     }
   }else if(br.Percents__c >= 40 && br.Percents__c <= 59){
     if(br.TestRanks__c=='Fifth'){
     br.Rank__c = '5';
     newbatchmark.add(br);
     
   }else{
     br.Rank__c = ' ';
     newbatchmark.add(br);
     }
   }
      
      update newbatchmark;
      
   }
  } 
  
  global void finish(database.batchablecontext BC){
  
  
  }
}

ase give some ideas.
I'm working in sandbox and I want to deploy this to my production but I currently have 0% coverage. Any help is appreciated! 

public class tenPageSizeExt { public tenPageSizeExt(ApexPages.StandardSetController controller) { controller.setPageSize(10); } }
I have a trigger that I can't get code coverage on an if statment. What am i doing wrong. 
I can't get code coverage on line 33 "if (a.AccountTeamMembers == Null || a.AccountTeamMembers.isEmpty()

Here's the trigger:
trigger trgAsset on Asset (after insert, after update, after delete) {
	if (trigger.isInsert || trigger.isUpdate){
		/*If the Asset has VersaDoc and the account doesn't have a VersaDoc Project Account Team Member, 
		  it will assign the next VersaDoc Project manager from the assignment groups to the Account Team*/

        Set<id> accountTeamAccountIds = new Set<id>(); // set of accountIDs that have VersaDoc in the asset
	    for (Asset a : Trigger.new){  
	    	if (a.HasVersadoc__c == 1 || a.HasVersadocStudio__c == 1 ) {
        		accountTeamAccountIds.add(a.AccountId); 
       	 	} 	
	    }
        
		list<Assignment_Group_Name__c> asgnGroupNameIDs = [SELECT Id FROM Assignment_Group_Name__c WHERE Name = 'Support - VersaDoc Project Managers' limit 1];
		system.debug('asgnGroupnameIDs is ' + asgnGroupNameIDs);
	
		Assignment_Groups__c[] asgnGroups = new List<Assignment_Groups__c>([SELECT Group_Name__c, User__c, Last_Assignment__c, Millisecond__c 
                                   FROM Assignment_Groups__c 
                                   WHERE Group_Name__c in :asgnGroupNameIds
                                   AND Active__c = 'True' AND User_Active__c = 'True'
                                   ORDER BY Last_Assignment__c, Millisecond__c] );                                    
	
		Integer groupCount = asgnGroups.size();
	
    	System.debug('>>>>>asgnGroups: '+asgnGroups);   
   		if (asgnGroups.isEmpty()) return;                      

		//loop through list of accounts and get the accounts w/o VersaDoc Project Manager
		AccountTeamMember[] NewMembers = new AccountTeamMember[]{};  //list of new team members to add
	    AccountShare[] newShare = new AccountShare[]{};  //list of new shares to add
		Map<id, Account> acctsToUpdate = new Map<id, Account>([Select a.Id, (Select Id, AccountId From AccountTeamMembers WHERE TeamMemberRole = 'VersaDoc Project Manager' limit 1) From Account a Where a.Id in :accountTeamAccountIds]);
		Integer cnt = 0;
	    for (Account a : acctsToUpdate.values()){
	    	if (a.AccountTeamMembers == null || a.AccountTeamMembers.isEmpty()) {
	    		AccountTeamMember TeamMemberAd=new AccountTeamMember();
		        TeamMemberAd.AccountId=a.id;
		        TeamMemberAd.UserId=asgnGroups[cnt].User__c;
		       	TeamMemberAd.TeamMemberRole = 'VersaDoc Project Manager';
		        NewMembers.add(TeamMemberAd);	
		        datetime now = datetime.now();
		        asgnGroups.get(cnt).Last_Assignment__c=now;
		        asgnGroups.get(cnt).Millisecond__c = now.millisecondGMT(); 
	    		cnt ++;
	    		if (cnt == groupCount){ cnt = 0;}    	
	    	}
	    } 

		//insert any valid members then add their share entry if they were successfully added
	    Database.SaveResult[] lsr = Database.insert(NewMembers,false);
		Integer newcnt=0;
	    for(Database.SaveResult sr:lsr){
			if(!sr.isSuccess()){
				Database.Error emsg = sr.getErrors()[0];
				system.debug('\n\nERROR ADDING TEAM MEMBER:'+emsg);
			}else{
				newShare.add(new AccountShare(UserOrGroupId=NewMembers[newcnt].UserId, AccountId=NewMembers[newcnt].Accountid, AccountAccessLevel='Edit',OpportunityAccessLevel='Edit'));
			}
				newcnt++;			
	    }
	    //insert the new shares
	    Database.SaveResult[] lsr0 =Database.insert(newShare,false); 
	    Integer newcnt0=0;
	    for(Database.SaveResult sr0:lsr0){
			if(!sr0.isSuccess()){
				Database.Error emsg0=sr0.getErrors()[0];
			    system.debug('\n\nERROR ADDING SHARING:'+newShare[newcnt0]+'::'+emsg0);
			}
				newcnt0++;
	    } 
	    // update assignment groups with their LastAssignmentDate
	    update asgnGroups; 	  
    }
}
Heres' the test class
@isTest(SeeAllData=false)
private class testTrgAssetVersaDocTeamAssignment {
    static testMethod void myUnitTest() {
        // create user to run the test a
        User u =  TestDataFactory.createTestRunAsUser('Standard User', 'Sales Assistant');  
        
        System.runAs(u) {  
            // Switch to the runtime 
             Test.StartTest();
            	// TestDataFactory.createProduct('PrinterPresence Gold Level', 'VersaDoc');
                list<Account> printAccts = TestDataFactory.createTestAccounts(2, 'Printers', 'Client');
                system.debug('***** printAccts is ' + printAccts);
                performCreateAssignmentGroups(u.Id);   
                checkVersaDocAccountTeam(printAccts);
                performCreateVersaDocAssets(u.Id, printAccts);  
            Test.StopTest();   
         }
    }
    
    public static void performCreateAssignmentGroups(id createdby){
        Assignment_Group_Name__c agn = TestDataFactory.createAssignmentGroup('Support - VersaDoc Project Managers', 'Account');
        list<User> u = TestDataFactory.createMulitpleUsers(2, 'Standard User-Support VersaDoc', 'Product Support Rep');     
        system.debug('**** user list is' + u);
        TestDataFactory.addUsersToAssigmentGroup(u, agn);
    }   
    
    public static void checkVersaDocAccountTeam(list <Account> accts){
        Map<id, Account> acctsToCheck = new Map<id, Account>([Select a.Id, (Select Id, AccountId From AccountTeamMembers WHERE TeamMemberRole = 'VersaDoc Project Manager' limit 1) From Account a Where a.Id in :accts]);
        List<Id> acct = new list<Id>();
        System.debug('**** acctsToCheck is ' + acctsToCheck);
        for (Account a: acctsToCheck.values()){
            if (a.AccountTeamMembers == null || a.AccountTeamMembers.isEmpty()) {
				system.debug('**** in if statement if for loop ' + acctsToCheck.values());
                acct.add(a.Id);
        	}
        }
        system.assert(acct.size()>0);
    }
    
    public static void performCreateVersaDocAssets(id createdby, List <Account> accts){
        // add PrinterPresence Gold level Asset (Has VersaDoc)
        date now = date.today(); 
        list<Account> acct = [Select Id from Account where id =: accts];
        list<Asset> assts = new list<Asset>();        
        assts = TestDataFactory.createAssets(accts, now, 'PrinterPresence Gold Level', 'Purchased', 310.00, 7500.00);
        system.debug('***** assts is ' + assts);
        
        Map<id, Account> acctTeams = new map<id, Account>([Select a.Id, (Select Id, AccountId, TeamMemberRole From AccountTeamMembers WHERE TeamMemberRole = 'VersaDoc Project Manager' limit 1) From Account a Where a.Id  =:accts]);
        system.debug('**** acctTeams after adding assets is ' + acctTeams);
        for (Account a : acctTeams.values()){
        	if (a.AccountTeamMembers != null && a.AccountTeamMembers.IsEmpty()==false) {   
            System.assertNotEquals(a.AccountTeamMembers, Null);
            }
        } 
        System.assert(acct.size()>0);
    }
}