• shankar sudalaimani
  • NEWBIE
  • 20 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 10
    Replies
In Lightning:
i have 3 pick lists in my page , i have to fetch from custom object with where condition like
1st pick list loads with employee names where from country UK, 2nd pick list loads with employee name where from country USA, like 3rd one also same with different country.
Please, give a suggestion for writing the test class for trigger below,i Wrote a test class and it's covered 60% and i don't know covered this trigger because they hardcored the group,profile and user id in the below trigger.
Trigger:
trigger onApprovedDeleteAcct  on B_Account__c (before delete) {
{

for (Integer i = 0; i < Trigger.old.size(); i++)
        {
        B_Account__c newObj = Trigger.old[i];
        if(newObj.KYC__c != null)
        {
              Case  KYCCase = [select OwnerId from Case where Id = :newObj.KYC__c];
              String ownerId = KYCCase.OwnerId;
                if(ownerId.indexOf('00G30000000qjKF')!=-1 /* Approved KYC (Queue)*/ &&
                  (UserInfo.getProfileId().indexOf('00e30000000hdt5') == -1) /* AML Bus Risk */ &&
                  (UserInfo.getProfileId().indexOf('00e30000000fWgj') == -1)/* AML Compliance */  )
                {
                       newObj.addError('An approved KYC may not be changed !');
                } else if((ownerId.indexOf('00G30000000qjAe')!=-1)/* AML & Bus Risk (Queue)*/
                       || (ownerId.indexOf('00G30000000qjAj')!=-1))/* Compliance KYC (Queue)*/
                           if  ((UserInfo.getProfileId().indexOf('00e30000000hdt5') == -1) /* AML Bus Risk */ &&
                                (UserInfo.getProfileId().indexOf('00e30000000fWgj') == -1)/* AML Compliance */  )
                           {
                                 newObj.addError('You may not change a KYC which is with ABR & Compliance for review.');
                           }
        }
        }
        }                     
}
Test Class what i write:
@isTest
public class Test_CommonRelatedFunctionalities {
 
	static testMethod void spgCustomersAndLeads() {
Profile prof = [SELECT Id FROM Profile WHERE Name = 'DB_Standard User_sales'];
  User user = new User(FederationIdentifier = '12313',Alias = 'standt1',Country='India',Email='demo13@db.com',EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',LocaleSidKey='en_US',ProfileId = prof.Id,TimeZoneSidKey='America/Los_Angeles', UserName='EVENTUSER13@db.com');
		insert user;
  Account firstacc=new Account(Name = 'Interactive Ties', Website = 'http://www.interactiveties.com/',OwnerId = user.Id,RecordTypeId= rec1.Id);
        insert firstacc;

       case ca=new case();
       ca.OwnerId=user.Id;
       ca.Type='Customer Call';
       ca.Case_Subject__c='Bill Payment';
       ca.Status='New';
       ca.ContactId=contacts[0].id;
       insert ca;
       
       B_Account__c dbAcc=new B_Account__c();
       dbAcc.Name='IntestOrg';
       dbAcc.KYC__c=ca.Id;
       insert dbAcc;
       delete dbAcc;
}
}

Thanks in Advance
Shankar S
 
I need to write the test class for below @future method and i already tried it's covered 61% and tried a lot but i can't make it please help me with this am a newbie
Class:
global class UpdateFAPShare{

@future
public static void UdpateFAPSharesfromAccountshares()
{
Map<Id,List<AccountShare>> AccSharesUdpatedMap = new Map<ID,List<AccountShare>>();
Map<Id,List<Foreign_Account_Approval__share>> FAPSharesMap = new Map<ID,List<Foreign_Account_Approval__share>>();

Map<Id,List<Id>> FAPUserSharestoAdd = new Map<ID,List<Id>>();
Map<Id,List<Id>> FAPActiveUserSharestoAdd = new Map<ID,List<Id>>();

Set<Id> AccRelated = new Set<Id>();
Set<Id> FAPSRelated = new Set<Id>();

List<Foreign_Account_Approval__c> FAPs =[Select Id,Customer__c from Foreign_Account_Approval__c];

List<Foreign_Account_Approval__share> FAPShares4add = new List<Foreign_Account_Approval__share>();
List<Foreign_Account_Approval__share> FAPShares4Del = new List<Foreign_Account_Approval__share>();
for (Foreign_Account_Approval__c FAP : FAPs)
{
   AccRelated.add(FAP.Customer__c);
 
}
list<Foreign_Account_Approval__share> FAPShares =[Select Id, UserOrGroupId,AccessLevel,RowCause,ParentId from Foreign_Account_Approval__share where RowCause=: Schema.Foreign_Account_Approval__Share.RowCause.Derived_From_Customer__c];

for (AccountShare[] AccShare : [Select Id, UserOrGroupId, AccountAccessLevel, RowCause, AccountId From AccountShare where AccountId =:AccRelated and RowCause <> 'ImplicitParent']){
  System.debug('Account Shares:'+accshare);
  for(AccountShare acs :AccShare){

     If(AccSharesUdpatedMap.containskey(Acs.accountid))
      {
        AccSharesUdpatedMap.get(Acs.accountid).add(acs);
      }
     else
        AccSharesUdpatedMap.put(acs.accountid,new AccountShare[]{acs});
  }
}
System.debug('AccSharesYpdateMap'+  AccSharesUdpatedMap);
for(Foreign_Account_Approval__share fs : FAPShares)
{
   FAPSRelated.add(fs.Id);
   If(FAPSharesMap.containskey(fs.parentId))
      {
        FAPSharesMap.get(fs.parentId).add(fs);
        
      }
     else
        FAPSharesMap.put(fs.parentId,new Foreign_Account_Approval__share[]{fs});
 } 
for(Foreign_Account_Approval__c FAP : FAPs)
{
 for(AccountShare acs : AccSharesUdpatedMap.get(FAP.customer__c))
  {
      boolean exists =false;  
    if(FAPSharesMap.containskey(FAP.id))  
    {
      for(Foreign_Account_Approval__share fs : FAPSharesMap.get(FAP.id))
     {
      if(fs.UserOrGroupId == acs.UserOrGroupId)
             
             {
                exists = true;
                FAPSRelated.remove(fs.Id);  
             }
     }
    }
  if(!exists) 
      {    String UsrOrGroupId  = acs.UserOrGroupId;
           if(!UsrOrGroupId.startswith('005'))
           {
           Foreign_Account_Approval__Share fs = new Foreign_Account_Approval__Share();
           fs.ParentId = FAP.Id;
           fs.UserOrGroupId = acs.UserOrGroupId;
           fs.Rowcause = Schema.Foreign_Account_Approval__Share.RowCause.Derived_From_Customer__c;
           fs.AccessLevel ='Read';
           FAPShares4add.add(fS);
           }
            else
           {
            If(FAPUserSharestoAdd.containskey(acs.UserOrGroupId))
            {
              FAPUserSharestoAdd.get(acs.UserOrGroupId).add(FAP.Id);
        
            }
            else
              FAPUserSharestoAdd.put(acs.UserOrGroupId,new Id []{FAP.Id});         
           }

           
      }  

}
} 
if(FAPUSerSharestoAdd.keyset().size()>0)
{
for(User u :[Select Id,isActive from User where id =:FAPUSerSharestoAdd.keyset()])
{
if(u.isActive)
{
 for(Id FAPID : FAPUSerSharestoAdd.get(u.ID))
 {
           Foreign_Account_Approval__Share fs = new Foreign_Account_Approval__Share();
           fs.ParentId = FAPId;
           fs.UserOrGroupId = u.Id;
           fs.Rowcause = Schema.Foreign_Account_Approval__Share.RowCause.Derived_From_Customer__c;
           fs.AccessLevel ='Read';
           FAPShares4add.add(fS);

 }
}
}
}

If(FAPShares4add.size()>0)
insert FAPShares4add;
if(FAPSRelated.size()>0)
{
FAPShares4Del =[Select Id from Foreign_Account_Approval__share where id =: FAPSRelated ];
delete FAPShares4Del;
}
}
}

My Test CLass:
@isTest(SeeAllData=true)
public class Test_UpdateFAPShare {
    static testMethod void TestMethodUpdateFAPShare(){
       // Select users for the test.
      List<User> users = [SELECT Id FROM User WHERE IsActive = true LIMIT 2];
      Id User1Id = users[0].Id;
      Id User2Id = users[1].Id;
      Profile p = [SELECT Id,Name FROM Profile WHERE Name = 'DB_Standard User_sales'];
      User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
        System.runAs (thisUser) 
        {  
      Account acc = new Account(Name='TestAcc');
      insert Acc;
        //Create Parent Group
        Group grp = new Group();
        grp.name = Acc.Name;
        grp.Type = 'Regular';
        grp.DoesIncludeBosses=false;
        Insert grp; 
 
        //Create Group Member
        GroupMember grpMem1 = new GroupMember();
        grpMem1.UserOrGroupId = UserInfo.getUserId();
        grpMem1.GroupId = grp.Id;
        Insert grpMem1;
 
       
      
   //   Account acc2 = new Account(Name='TestAcc2',OwnerId=grpMem1.UserOrGroupId);
     // insert Acc2;
     Case c = new Case(OwnerId = grp.Id,Reason='Record Deletion',Status='Done',subject='Test');
      insert c;
      Foreign_Account_Approval__c FAP = new Foreign_Account_Approval__c();
      FAP.Customer__c=Acc.id;
     // FAP.Name=thisuser.Name;
      FAP.OwnerId = thisUser.Id;
      FAP.CA_Name__c=thisUser.Id;
      FAP.Status__c='Pending BSO Approval';
      insert FAP;
      FAP = [select Id, Name,Customer__c from Foreign_Account_Approval__c where id = : FAP.id];
            
        //Create Sub group
        Group subGrp  = new Group();
        subGrp.name = FAP.Name;
        subGrp.Type = 'Regular'; 
        Insert subGrp; 
 
        //Assign Role To Parent Group
        GroupMember grpMem2 = new GroupMember();
        grpMem2.UserOrGroupId = subGrp.Id;
        grpMem2.GroupId = grp.Id;
        Insert grpMem2;   
         // Create new sharing Account for the Account object Account.
      AccountShare accShr  = new AccountShare();
   
      // Set the ID of record being shared.
      accShr.AccountId = FAP.Customer__c;
        
      // Set the ID of user or group being granted access.
      accShr.UserOrGroupId = grpMem1.UserOrGroupId;
        
      // Set the access level.
      accShr.AccountAccessLevel = 'Read';
        
      // Set rowCause to 'manual' for manual sharing.
      // This line can be omitted as 'manual' is the default value for sharing objects.
      accShr.RowCause = Schema.AccountShare.RowCause.Manual;
      
        // Create new sharing object for the custom object Job.
      Foreign_Account_Approval__share fapShr  = new Foreign_Account_Approval__share();
   
      // Set the ID of record being shared.
      fapShr.ParentId = FAP.Id;
        
      // Set the ID of user or group being granted access.
      fapShr.UserOrGroupId = grpMem2.UserOrGroupId;
        
      // Set the access level.
      fapShr.AccessLevel = 'Read';
       
      // Set rowCause to 'manual' for manual sharing.
      // This line can be omitted as 'manual' is the default value for sharing objects.
      fapShr.RowCause = Schema.Foreign_Account_Approval__share.RowCause.Manual;
      UpdateFAPShare.UdpateFAPSharesfromAccountshares();
        }
        UpdateFAPShare.UdpateFAPSharesfromAccountshares();
     }
}

 
Hi all,
I stucked in writing test class for trigger please help me am newbie

MyTrigger:
trigger onCustomerUpdate on Account (after update) {
	try
	{
		// Get all Lead Sharing records
		SPG_Approval_request__c[] SPGRecords = [Select Id, Customer_Name__c from SPG_Approval_request__c where Customer_Name__c in :trigger.newMap.keySet()];
		
		Set<Id> SPGIds = new Set<Id>();
		for(SPG_Approval_request__c SPG : SPGRecords)
			SPGIds.add(SPG.Id);
		/*	
		// Get the existing sharing rules for the lead sharings and delete them
		for(SPG_Approval_request__Share[] SPGRecordShares : [Select Id from SPG_Approval_request__Share where parentId in :SPGIds and RowCause = 'Derived_From_Customer__c'])
			delete SPGRecordShares;
		*/
		System.debug('DML Rows Processed : ' + Limits.getDMLRows());
		// Insert the new sharing rules 
		inheritSharingForSPG.inheritSharingFromCustomer(SPGIds);		
	}
	catch(Exception e)
	{
		trigger.new[0].addError('Following Exception Occurred: ' + e.getMessage() + '\n. Please contact the system administrator with the error message.');
	}	
}

MyTestClass for above Trigger:
@isTest
public class onCustomerUpdateTest {
    static testMethod void TestMethodonCustomerUpdate(){
        Account a=new account();
        a.name='Test Account';
        insert a;
        SPG_Approval_request__c  s=new SPG_Approval_request__c();
        s.Customer_Name__c=a.Id;
        s.Document_Name__c='DB';
        insert s;
        a.name='change';
        update a;

         }
}

 
Hi Am new to salesforce please help to write the test class for controller
public with sharing class CaseHistoriesComponentController {
	
	public Id caseId {get; set;}
	public cHistories[] histories; 
	
	public List<cHistories> getHistories()
	{
		list<cHistories> histories = new list<cHistories>();
		String prevDate = '';
		for(CaseHistory cHistory : [Select CreatedDate, CreatedBy.Name, CreatedBy.Id, Field, NewValue, OldValue from CaseHistory where CaseId = :caseId order by CreatedDate desc])
		{
			if((cHistory.newValue == null && cHistory.oldValue == null) 
					|| (cHistory.newValue != null && !(string.valueOf(cHistory.newValue).startsWith('005') || string.valueOf(cHistory.newValue).startsWith('00G')))
					|| (cHistory.oldValue != null && !(string.valueOf(cHistory.oldValue).startsWith('005') || string.valueOf(cHistory.oldValue).startsWith('00G'))))
			{
				cHistories tempHistory = new cHistories();
				// Set the Date and who performed the action
				if(String.valueOf(cHistory.CreatedDate) != prevDate)
				{
					tempHistory.theDate = String.valueOf(cHistory.CreatedDate);
					tempHistory.who = cHistory.CreatedBy.Name;
					tempHistory.userId = cHistory.CreatedBy.Id;
				}
				else
				{
					tempHistory.theDate = '';
					tempHistory.who = '';
					tempHistory.userId = cHistory.CreatedBy.Id;
				}
				prevDate = String.valueOf(cHistory.CreatedDate);
				
				// Get the field label
				String fieldLabel = TeasTicketGlobalFunction.returnFieldLabel(String.valueOf(cHistory.Field));
				
				// Set the Action value
	       		if (String.valueOf(cHistory.Field) == 'created') {    // on Creation
	       			tempHistory.action = 'Created.';
	      		}
	      		else if(cHistory.OldValue != null && cHistory.NewValue == null){ // when deleting a value from a field
	      			// Format the Date and if there's an error, catch it and re
	      			try {
	         			tempHistory.action = 'Deleted ' + Date.valueOf(cHistory.OldValue).format() + ' in <b>' + fieldLabel + '</b>.';
	        		} catch (Exception e){
	         			tempHistory.action = 'Deleted ' + String.valueOf(cHistory.OldValue) + ' in <b>' + fieldLabel + '</b>.';
	        		}
	      		}
	      		else{  // all other scenarios
	      			String fromText = '';
	        		if (cHistory.OldValue != null) {
		         		try {
		          			fromText = ' from ' + Date.valueOf(cHistory.OldValue).format();
		         		} catch (Exception e) {
		          			fromText = ' from ' + String.valueOf(cHistory.OldValue);
		         		}
	        		}
	        		
	        		String toText = '';
	        		if (cHistory.OldValue != null) {
		        		try {
				         	toText = Date.valueOf(cHistory.NewValue).format();
				        } catch (Exception e) {
				         	toText = String.valueOf(cHistory.NewValue);
				        }
	        		}
	        		if(toText != '')
	        			tempHistory.action = 'Changed <b>' + fieldLabel + '</b>' + fromText + ' to <b>' + toText + '</b>.';
	        		else
	        			tempHistory.action = 'Changed <b>' + fieldLabel;
	       		}
	       		
	       		// Add to the list
	       		histories.add(tempHistory);
			}
	 	}
	 	
	 	return histories;
	}	
	
	// Inner Class to store the detail of the case histories	
	public class cHistories {

		public String theDate {get; set;}
	    public String who {get; set;}
	    public Id userId {get; set;} 
	    public String action {get; set;}
	}
}

Thanks in Advance
 
Am new to salesforce ,Please help to write test classes,it shows some error
Error is: System.ListException: List index out of bounds: 0
Stack Trace: Class.Accept_and_open.testAcceptCase: line 109, column 1
line 109 is:  String caseId = c[0].id;
global class Accept_and_open 
{
    WebService static String AcceptOpenCase(string id)
    {
        Id currentUserId = UserInfo.getUserId();
        Case c=[SELECT Id, CaseNumber, OwnerId FROM Case WHERE Id=:Id];
        
        GroupMember[] queueUserId = [Select Id, UserOrGroupId FROM GroupMember WHERE GroupId = :c.OwnerId AND UserOrGroupId = :currentUserId];
        if(queueUserId.size() > 0) 
        {
            return 'true';
        }       
        else
        {
            return 'false';
        } 
    }
    
    WebService static String AcceptCase(String[] Ids)
    {
        String Success = '';
        String Failure = '';
        Id currentUserId = UserInfo.getUserId();
        List<Case> cases=[SELECT Id, CaseNumber, OwnerId FROM Case WHERE Id IN :Ids];
        
        Set<Id> caseOwnerIds = new Set<Id>();       
        Map<Id,GroupMember> groupMemberMap = new Map<Id,GroupMember>();
        List<Case> updateCases = new List<Case>();
        
        for(Case acceptCase:cases)
        {
            caseOwnerIds.add(acceptCase.OwnerId);
        }
                
        if(caseOwnerIds.size() > 0)
        {   
              List<GroupMember> queueUsers = [Select Id, UserOrGroupId, GroupId FROM GroupMember WHERE GroupId IN :caseOwnerIds AND UserOrGroupId = :currentUserId];
              for(GroupMember gm:queueUsers)
              {
                  groupMemberMap.put(gm.GroupId,gm);
              }
        }
        
        for(Case c:cases)
        {
            if(groupMemberMap.get(c.OwnerId) != null)
            {
                c.OwnerId=currentUserId;
                updateCases.add(c);
                
                Success = Success+c.CaseNumber+' ';
            }
            else
            {
                 Failure = Failure+c.CaseNumber+' ';
            } 
        }
                
        //Updating the Case with Onwer id
        if(updateCases.size() > 0)
        update updateCases;
        
        String Message = '';
        if(Success != '' && Failure != '')
        {
            Message = 'These Cases are accepted successfully: '+Success+ 'and' +'These Cases are not accepted becuase you are not part of the Queues for Cases :' + Failure;  
        }
        else if(Success != '' && Failure == '')
        {
            Message = 'These Cases are accepted successfully: '+Success;
        } 
        else if(Success == '' && Failure != '')
        {
            Message = 'These Cases are not accepted becuase you are not part of the Queues for Cases: ' + Failure;  
        }
        else
        {
           Message = '';
        }  

        return Message; 
    }

    public static testMethod void testAcceptCase() 
    {               
            QueueSobject q = [Select Id, QueueId From QueueSobject Where Queue.Name = 'BSO' AND SobjectType='Case']; 
            List<GroupMember> queueUsers = [Select Id, UserOrGroupId FROM GroupMember WHERE GroupId=:q.QueueId];  
            Case[] c = [Select Id,OwnerId From Case where OwnerId=:q.QueueId AND TEAS_S_Control_ID__c != null Limit 10];
                  
            Set<Id> userIds=new Set<Id>();
            for(GroupMember gm:queueUsers)
            {
                userIds.add(gm.UserOrGroupId);
            }                                            
           
            List<User> u = [Select Id from User where Id IN :userIds AND IsActive=true Limit 5];
        if (u.size()>0)
        {
            System.runAs(u[0]) 
            {
                String caseId = c[0].id;
                AcceptOpenCase(caseId);                
                                             
                List<String> caseIDs= new List<String>();
                for(Case caseList:c)
                {
                     caseIDs.add(caseList.Id);
                }
                AcceptCase(caseIDs);
            }
        }
            
            List<User> u1 = [Select Id from User where Id NOT IN :userIds AND IsActive=true Limit 5];
        if (u1.size()>0)
        {
            System.runAs(u1[0]) 
            {
                String caseId = c[0].id;
                AcceptOpenCase(caseId);
                
                List<String> caseIDs= new List<String>();
                for(Case caseList:c)
                {
                     caseIDs.add(caseList.Id);                     
                }
                AcceptCase(caseIDs);
            }
        }
    }
}

 
Hi guys,
I am new to salesforce i don't know how to write the test class for trigger.Please,help me
This is my trigger:
trigger trigger_name on Task (after insert, after update) {


    List<Messaging.SingleEmailMessage> Smail = new List<Messaging.SingleEmailMessage>();
   
    /* EmailTemplate ETemplate = [Select id from EmailTemplate where DeveloperName=:'Call_Notes']; */

        List<Id> taskAccountId = new List<Id>();
    Task ttask = Trigger.New[0];
   
    for(Task tsk : Trigger.New){
     if(tsk.AccountId != null && tsk.Send_Email_to_Customer_Team__c == 'Yes')
           taskAccountId.add(tsk.AccountID);
      }   
   
    String S1 =  'CALL NOTES \n =========== \n Call Reason: ' + ttask.Call_Reason__c  + '\n Contact Date:' +  ttask.Contact_Date__c  + '\n Type:' + ttask.Type;   
    String S2 =  '\n Attendees: ' + ttask.Attendees__c   + '\n ISG Rep1: ' + ttask.ISG_Rep1__c   + '\n ISG Rep2: ' + ttask.ISG_Rep2__c   + '\n Product Officer1: ' + ttask.Product_Officer1__c   + '\n Product Officer2: ' + ttask.Product_Officer2__c   + '\n Other1: ' + ttask.Other1__c;
    String S3 =  '\n Other2: ' + ttask.Other2__c   + '\n Comments:' + ttask.Description;
    String Txt_Body = S1 + S2 + S3;
   
  
    for(AccountTeamMember acctMem : [Select UserId, Account.Name, TeamMemberRole from AccountTeamMember Where AccountId IN:taskAccountId]){
      Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();  
      mail.setTargetObjectId(acctMem.UserId);
      mail.subject = 'Call Notes Notification - ' + acctMem.Account.Name + '(Account Team)' ;
      mail.setUseSignature(true);
      mail.setBccSender(false);
      mail.setSaveAsActivity(false);
      mail.setSenderDisplayName(' Call Notes Notification');
      //mail.setTemplateId(ETemplate.Id);
      mail.setPlainTextBody(Txt_Body);
     
           
      Smail.add(mail);
    }  
    Messaging.sendEmail(Smail);
}

Thanks in Advance
I need to write the test class for below @future method and i already tried it's covered 61% and tried a lot but i can't make it please help me with this am a newbie
Class:
global class UpdateFAPShare{

@future
public static void UdpateFAPSharesfromAccountshares()
{
Map<Id,List<AccountShare>> AccSharesUdpatedMap = new Map<ID,List<AccountShare>>();
Map<Id,List<Foreign_Account_Approval__share>> FAPSharesMap = new Map<ID,List<Foreign_Account_Approval__share>>();

Map<Id,List<Id>> FAPUserSharestoAdd = new Map<ID,List<Id>>();
Map<Id,List<Id>> FAPActiveUserSharestoAdd = new Map<ID,List<Id>>();

Set<Id> AccRelated = new Set<Id>();
Set<Id> FAPSRelated = new Set<Id>();

List<Foreign_Account_Approval__c> FAPs =[Select Id,Customer__c from Foreign_Account_Approval__c];

List<Foreign_Account_Approval__share> FAPShares4add = new List<Foreign_Account_Approval__share>();
List<Foreign_Account_Approval__share> FAPShares4Del = new List<Foreign_Account_Approval__share>();
for (Foreign_Account_Approval__c FAP : FAPs)
{
   AccRelated.add(FAP.Customer__c);
 
}
list<Foreign_Account_Approval__share> FAPShares =[Select Id, UserOrGroupId,AccessLevel,RowCause,ParentId from Foreign_Account_Approval__share where RowCause=: Schema.Foreign_Account_Approval__Share.RowCause.Derived_From_Customer__c];

for (AccountShare[] AccShare : [Select Id, UserOrGroupId, AccountAccessLevel, RowCause, AccountId From AccountShare where AccountId =:AccRelated and RowCause <> 'ImplicitParent']){
  System.debug('Account Shares:'+accshare);
  for(AccountShare acs :AccShare){

     If(AccSharesUdpatedMap.containskey(Acs.accountid))
      {
        AccSharesUdpatedMap.get(Acs.accountid).add(acs);
      }
     else
        AccSharesUdpatedMap.put(acs.accountid,new AccountShare[]{acs});
  }
}
System.debug('AccSharesYpdateMap'+  AccSharesUdpatedMap);
for(Foreign_Account_Approval__share fs : FAPShares)
{
   FAPSRelated.add(fs.Id);
   If(FAPSharesMap.containskey(fs.parentId))
      {
        FAPSharesMap.get(fs.parentId).add(fs);
        
      }
     else
        FAPSharesMap.put(fs.parentId,new Foreign_Account_Approval__share[]{fs});
 } 
for(Foreign_Account_Approval__c FAP : FAPs)
{
 for(AccountShare acs : AccSharesUdpatedMap.get(FAP.customer__c))
  {
      boolean exists =false;  
    if(FAPSharesMap.containskey(FAP.id))  
    {
      for(Foreign_Account_Approval__share fs : FAPSharesMap.get(FAP.id))
     {
      if(fs.UserOrGroupId == acs.UserOrGroupId)
             
             {
                exists = true;
                FAPSRelated.remove(fs.Id);  
             }
     }
    }
  if(!exists) 
      {    String UsrOrGroupId  = acs.UserOrGroupId;
           if(!UsrOrGroupId.startswith('005'))
           {
           Foreign_Account_Approval__Share fs = new Foreign_Account_Approval__Share();
           fs.ParentId = FAP.Id;
           fs.UserOrGroupId = acs.UserOrGroupId;
           fs.Rowcause = Schema.Foreign_Account_Approval__Share.RowCause.Derived_From_Customer__c;
           fs.AccessLevel ='Read';
           FAPShares4add.add(fS);
           }
            else
           {
            If(FAPUserSharestoAdd.containskey(acs.UserOrGroupId))
            {
              FAPUserSharestoAdd.get(acs.UserOrGroupId).add(FAP.Id);
        
            }
            else
              FAPUserSharestoAdd.put(acs.UserOrGroupId,new Id []{FAP.Id});         
           }

           
      }  

}
} 
if(FAPUSerSharestoAdd.keyset().size()>0)
{
for(User u :[Select Id,isActive from User where id =:FAPUSerSharestoAdd.keyset()])
{
if(u.isActive)
{
 for(Id FAPID : FAPUSerSharestoAdd.get(u.ID))
 {
           Foreign_Account_Approval__Share fs = new Foreign_Account_Approval__Share();
           fs.ParentId = FAPId;
           fs.UserOrGroupId = u.Id;
           fs.Rowcause = Schema.Foreign_Account_Approval__Share.RowCause.Derived_From_Customer__c;
           fs.AccessLevel ='Read';
           FAPShares4add.add(fS);

 }
}
}
}

If(FAPShares4add.size()>0)
insert FAPShares4add;
if(FAPSRelated.size()>0)
{
FAPShares4Del =[Select Id from Foreign_Account_Approval__share where id =: FAPSRelated ];
delete FAPShares4Del;
}
}
}

My Test CLass:
@isTest(SeeAllData=true)
public class Test_UpdateFAPShare {
    static testMethod void TestMethodUpdateFAPShare(){
       // Select users for the test.
      List<User> users = [SELECT Id FROM User WHERE IsActive = true LIMIT 2];
      Id User1Id = users[0].Id;
      Id User2Id = users[1].Id;
      Profile p = [SELECT Id,Name FROM Profile WHERE Name = 'DB_Standard User_sales'];
      User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
        System.runAs (thisUser) 
        {  
      Account acc = new Account(Name='TestAcc');
      insert Acc;
        //Create Parent Group
        Group grp = new Group();
        grp.name = Acc.Name;
        grp.Type = 'Regular';
        grp.DoesIncludeBosses=false;
        Insert grp; 
 
        //Create Group Member
        GroupMember grpMem1 = new GroupMember();
        grpMem1.UserOrGroupId = UserInfo.getUserId();
        grpMem1.GroupId = grp.Id;
        Insert grpMem1;
 
       
      
   //   Account acc2 = new Account(Name='TestAcc2',OwnerId=grpMem1.UserOrGroupId);
     // insert Acc2;
     Case c = new Case(OwnerId = grp.Id,Reason='Record Deletion',Status='Done',subject='Test');
      insert c;
      Foreign_Account_Approval__c FAP = new Foreign_Account_Approval__c();
      FAP.Customer__c=Acc.id;
     // FAP.Name=thisuser.Name;
      FAP.OwnerId = thisUser.Id;
      FAP.CA_Name__c=thisUser.Id;
      FAP.Status__c='Pending BSO Approval';
      insert FAP;
      FAP = [select Id, Name,Customer__c from Foreign_Account_Approval__c where id = : FAP.id];
            
        //Create Sub group
        Group subGrp  = new Group();
        subGrp.name = FAP.Name;
        subGrp.Type = 'Regular'; 
        Insert subGrp; 
 
        //Assign Role To Parent Group
        GroupMember grpMem2 = new GroupMember();
        grpMem2.UserOrGroupId = subGrp.Id;
        grpMem2.GroupId = grp.Id;
        Insert grpMem2;   
         // Create new sharing Account for the Account object Account.
      AccountShare accShr  = new AccountShare();
   
      // Set the ID of record being shared.
      accShr.AccountId = FAP.Customer__c;
        
      // Set the ID of user or group being granted access.
      accShr.UserOrGroupId = grpMem1.UserOrGroupId;
        
      // Set the access level.
      accShr.AccountAccessLevel = 'Read';
        
      // Set rowCause to 'manual' for manual sharing.
      // This line can be omitted as 'manual' is the default value for sharing objects.
      accShr.RowCause = Schema.AccountShare.RowCause.Manual;
      
        // Create new sharing object for the custom object Job.
      Foreign_Account_Approval__share fapShr  = new Foreign_Account_Approval__share();
   
      // Set the ID of record being shared.
      fapShr.ParentId = FAP.Id;
        
      // Set the ID of user or group being granted access.
      fapShr.UserOrGroupId = grpMem2.UserOrGroupId;
        
      // Set the access level.
      fapShr.AccessLevel = 'Read';
       
      // Set rowCause to 'manual' for manual sharing.
      // This line can be omitted as 'manual' is the default value for sharing objects.
      fapShr.RowCause = Schema.Foreign_Account_Approval__share.RowCause.Manual;
      UpdateFAPShare.UdpateFAPSharesfromAccountshares();
        }
        UpdateFAPShare.UdpateFAPSharesfromAccountshares();
     }
}

 
I need to write the test class for below @future method and i already tried it's covered 61% and tried a lot but i can't make it please help me with this am a newbie
Class:
global class UpdateFAPShare{

@future
public static void UdpateFAPSharesfromAccountshares()
{
Map<Id,List<AccountShare>> AccSharesUdpatedMap = new Map<ID,List<AccountShare>>();
Map<Id,List<Foreign_Account_Approval__share>> FAPSharesMap = new Map<ID,List<Foreign_Account_Approval__share>>();

Map<Id,List<Id>> FAPUserSharestoAdd = new Map<ID,List<Id>>();
Map<Id,List<Id>> FAPActiveUserSharestoAdd = new Map<ID,List<Id>>();

Set<Id> AccRelated = new Set<Id>();
Set<Id> FAPSRelated = new Set<Id>();

List<Foreign_Account_Approval__c> FAPs =[Select Id,Customer__c from Foreign_Account_Approval__c];

List<Foreign_Account_Approval__share> FAPShares4add = new List<Foreign_Account_Approval__share>();
List<Foreign_Account_Approval__share> FAPShares4Del = new List<Foreign_Account_Approval__share>();
for (Foreign_Account_Approval__c FAP : FAPs)
{
   AccRelated.add(FAP.Customer__c);
 
}
list<Foreign_Account_Approval__share> FAPShares =[Select Id, UserOrGroupId,AccessLevel,RowCause,ParentId from Foreign_Account_Approval__share where RowCause=: Schema.Foreign_Account_Approval__Share.RowCause.Derived_From_Customer__c];

for (AccountShare[] AccShare : [Select Id, UserOrGroupId, AccountAccessLevel, RowCause, AccountId From AccountShare where AccountId =:AccRelated and RowCause <> 'ImplicitParent']){
  System.debug('Account Shares:'+accshare);
  for(AccountShare acs :AccShare){

     If(AccSharesUdpatedMap.containskey(Acs.accountid))
      {
        AccSharesUdpatedMap.get(Acs.accountid).add(acs);
      }
     else
        AccSharesUdpatedMap.put(acs.accountid,new AccountShare[]{acs});
  }
}
System.debug('AccSharesYpdateMap'+  AccSharesUdpatedMap);
for(Foreign_Account_Approval__share fs : FAPShares)
{
   FAPSRelated.add(fs.Id);
   If(FAPSharesMap.containskey(fs.parentId))
      {
        FAPSharesMap.get(fs.parentId).add(fs);
        
      }
     else
        FAPSharesMap.put(fs.parentId,new Foreign_Account_Approval__share[]{fs});
 } 
for(Foreign_Account_Approval__c FAP : FAPs)
{
 for(AccountShare acs : AccSharesUdpatedMap.get(FAP.customer__c))
  {
      boolean exists =false;  
    if(FAPSharesMap.containskey(FAP.id))  
    {
      for(Foreign_Account_Approval__share fs : FAPSharesMap.get(FAP.id))
     {
      if(fs.UserOrGroupId == acs.UserOrGroupId)
             
             {
                exists = true;
                FAPSRelated.remove(fs.Id);  
             }
     }
    }
  if(!exists) 
      {    String UsrOrGroupId  = acs.UserOrGroupId;
           if(!UsrOrGroupId.startswith('005'))
           {
           Foreign_Account_Approval__Share fs = new Foreign_Account_Approval__Share();
           fs.ParentId = FAP.Id;
           fs.UserOrGroupId = acs.UserOrGroupId;
           fs.Rowcause = Schema.Foreign_Account_Approval__Share.RowCause.Derived_From_Customer__c;
           fs.AccessLevel ='Read';
           FAPShares4add.add(fS);
           }
            else
           {
            If(FAPUserSharestoAdd.containskey(acs.UserOrGroupId))
            {
              FAPUserSharestoAdd.get(acs.UserOrGroupId).add(FAP.Id);
        
            }
            else
              FAPUserSharestoAdd.put(acs.UserOrGroupId,new Id []{FAP.Id});         
           }

           
      }  

}
} 
if(FAPUSerSharestoAdd.keyset().size()>0)
{
for(User u :[Select Id,isActive from User where id =:FAPUSerSharestoAdd.keyset()])
{
if(u.isActive)
{
 for(Id FAPID : FAPUSerSharestoAdd.get(u.ID))
 {
           Foreign_Account_Approval__Share fs = new Foreign_Account_Approval__Share();
           fs.ParentId = FAPId;
           fs.UserOrGroupId = u.Id;
           fs.Rowcause = Schema.Foreign_Account_Approval__Share.RowCause.Derived_From_Customer__c;
           fs.AccessLevel ='Read';
           FAPShares4add.add(fS);

 }
}
}
}

If(FAPShares4add.size()>0)
insert FAPShares4add;
if(FAPSRelated.size()>0)
{
FAPShares4Del =[Select Id from Foreign_Account_Approval__share where id =: FAPSRelated ];
delete FAPShares4Del;
}
}
}

My Test CLass:
@isTest(SeeAllData=true)
public class Test_UpdateFAPShare {
    static testMethod void TestMethodUpdateFAPShare(){
       // Select users for the test.
      List<User> users = [SELECT Id FROM User WHERE IsActive = true LIMIT 2];
      Id User1Id = users[0].Id;
      Id User2Id = users[1].Id;
      Profile p = [SELECT Id,Name FROM Profile WHERE Name = 'DB_Standard User_sales'];
      User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
        System.runAs (thisUser) 
        {  
      Account acc = new Account(Name='TestAcc');
      insert Acc;
        //Create Parent Group
        Group grp = new Group();
        grp.name = Acc.Name;
        grp.Type = 'Regular';
        grp.DoesIncludeBosses=false;
        Insert grp; 
 
        //Create Group Member
        GroupMember grpMem1 = new GroupMember();
        grpMem1.UserOrGroupId = UserInfo.getUserId();
        grpMem1.GroupId = grp.Id;
        Insert grpMem1;
 
       
      
   //   Account acc2 = new Account(Name='TestAcc2',OwnerId=grpMem1.UserOrGroupId);
     // insert Acc2;
     Case c = new Case(OwnerId = grp.Id,Reason='Record Deletion',Status='Done',subject='Test');
      insert c;
      Foreign_Account_Approval__c FAP = new Foreign_Account_Approval__c();
      FAP.Customer__c=Acc.id;
     // FAP.Name=thisuser.Name;
      FAP.OwnerId = thisUser.Id;
      FAP.CA_Name__c=thisUser.Id;
      FAP.Status__c='Pending BSO Approval';
      insert FAP;
      FAP = [select Id, Name,Customer__c from Foreign_Account_Approval__c where id = : FAP.id];
            
        //Create Sub group
        Group subGrp  = new Group();
        subGrp.name = FAP.Name;
        subGrp.Type = 'Regular'; 
        Insert subGrp; 
 
        //Assign Role To Parent Group
        GroupMember grpMem2 = new GroupMember();
        grpMem2.UserOrGroupId = subGrp.Id;
        grpMem2.GroupId = grp.Id;
        Insert grpMem2;   
         // Create new sharing Account for the Account object Account.
      AccountShare accShr  = new AccountShare();
   
      // Set the ID of record being shared.
      accShr.AccountId = FAP.Customer__c;
        
      // Set the ID of user or group being granted access.
      accShr.UserOrGroupId = grpMem1.UserOrGroupId;
        
      // Set the access level.
      accShr.AccountAccessLevel = 'Read';
        
      // Set rowCause to 'manual' for manual sharing.
      // This line can be omitted as 'manual' is the default value for sharing objects.
      accShr.RowCause = Schema.AccountShare.RowCause.Manual;
      
        // Create new sharing object for the custom object Job.
      Foreign_Account_Approval__share fapShr  = new Foreign_Account_Approval__share();
   
      // Set the ID of record being shared.
      fapShr.ParentId = FAP.Id;
        
      // Set the ID of user or group being granted access.
      fapShr.UserOrGroupId = grpMem2.UserOrGroupId;
        
      // Set the access level.
      fapShr.AccessLevel = 'Read';
       
      // Set rowCause to 'manual' for manual sharing.
      // This line can be omitted as 'manual' is the default value for sharing objects.
      fapShr.RowCause = Schema.Foreign_Account_Approval__share.RowCause.Manual;
      UpdateFAPShare.UdpateFAPSharesfromAccountshares();
        }
        UpdateFAPShare.UdpateFAPSharesfromAccountshares();
     }
}

 
Hi all,
I stucked in writing test class for trigger please help me am newbie

MyTrigger:
trigger onCustomerUpdate on Account (after update) {
	try
	{
		// Get all Lead Sharing records
		SPG_Approval_request__c[] SPGRecords = [Select Id, Customer_Name__c from SPG_Approval_request__c where Customer_Name__c in :trigger.newMap.keySet()];
		
		Set<Id> SPGIds = new Set<Id>();
		for(SPG_Approval_request__c SPG : SPGRecords)
			SPGIds.add(SPG.Id);
		/*	
		// Get the existing sharing rules for the lead sharings and delete them
		for(SPG_Approval_request__Share[] SPGRecordShares : [Select Id from SPG_Approval_request__Share where parentId in :SPGIds and RowCause = 'Derived_From_Customer__c'])
			delete SPGRecordShares;
		*/
		System.debug('DML Rows Processed : ' + Limits.getDMLRows());
		// Insert the new sharing rules 
		inheritSharingForSPG.inheritSharingFromCustomer(SPGIds);		
	}
	catch(Exception e)
	{
		trigger.new[0].addError('Following Exception Occurred: ' + e.getMessage() + '\n. Please contact the system administrator with the error message.');
	}	
}

MyTestClass for above Trigger:
@isTest
public class onCustomerUpdateTest {
    static testMethod void TestMethodonCustomerUpdate(){
        Account a=new account();
        a.name='Test Account';
        insert a;
        SPG_Approval_request__c  s=new SPG_Approval_request__c();
        s.Customer_Name__c=a.Id;
        s.Document_Name__c='DB';
        insert s;
        a.name='change';
        update a;

         }
}

 
Am new to salesforce ,Please help to write test classes,it shows some error
Error is: System.ListException: List index out of bounds: 0
Stack Trace: Class.Accept_and_open.testAcceptCase: line 109, column 1
line 109 is:  String caseId = c[0].id;
global class Accept_and_open 
{
    WebService static String AcceptOpenCase(string id)
    {
        Id currentUserId = UserInfo.getUserId();
        Case c=[SELECT Id, CaseNumber, OwnerId FROM Case WHERE Id=:Id];
        
        GroupMember[] queueUserId = [Select Id, UserOrGroupId FROM GroupMember WHERE GroupId = :c.OwnerId AND UserOrGroupId = :currentUserId];
        if(queueUserId.size() > 0) 
        {
            return 'true';
        }       
        else
        {
            return 'false';
        } 
    }
    
    WebService static String AcceptCase(String[] Ids)
    {
        String Success = '';
        String Failure = '';
        Id currentUserId = UserInfo.getUserId();
        List<Case> cases=[SELECT Id, CaseNumber, OwnerId FROM Case WHERE Id IN :Ids];
        
        Set<Id> caseOwnerIds = new Set<Id>();       
        Map<Id,GroupMember> groupMemberMap = new Map<Id,GroupMember>();
        List<Case> updateCases = new List<Case>();
        
        for(Case acceptCase:cases)
        {
            caseOwnerIds.add(acceptCase.OwnerId);
        }
                
        if(caseOwnerIds.size() > 0)
        {   
              List<GroupMember> queueUsers = [Select Id, UserOrGroupId, GroupId FROM GroupMember WHERE GroupId IN :caseOwnerIds AND UserOrGroupId = :currentUserId];
              for(GroupMember gm:queueUsers)
              {
                  groupMemberMap.put(gm.GroupId,gm);
              }
        }
        
        for(Case c:cases)
        {
            if(groupMemberMap.get(c.OwnerId) != null)
            {
                c.OwnerId=currentUserId;
                updateCases.add(c);
                
                Success = Success+c.CaseNumber+' ';
            }
            else
            {
                 Failure = Failure+c.CaseNumber+' ';
            } 
        }
                
        //Updating the Case with Onwer id
        if(updateCases.size() > 0)
        update updateCases;
        
        String Message = '';
        if(Success != '' && Failure != '')
        {
            Message = 'These Cases are accepted successfully: '+Success+ 'and' +'These Cases are not accepted becuase you are not part of the Queues for Cases :' + Failure;  
        }
        else if(Success != '' && Failure == '')
        {
            Message = 'These Cases are accepted successfully: '+Success;
        } 
        else if(Success == '' && Failure != '')
        {
            Message = 'These Cases are not accepted becuase you are not part of the Queues for Cases: ' + Failure;  
        }
        else
        {
           Message = '';
        }  

        return Message; 
    }

    public static testMethod void testAcceptCase() 
    {               
            QueueSobject q = [Select Id, QueueId From QueueSobject Where Queue.Name = 'BSO' AND SobjectType='Case']; 
            List<GroupMember> queueUsers = [Select Id, UserOrGroupId FROM GroupMember WHERE GroupId=:q.QueueId];  
            Case[] c = [Select Id,OwnerId From Case where OwnerId=:q.QueueId AND TEAS_S_Control_ID__c != null Limit 10];
                  
            Set<Id> userIds=new Set<Id>();
            for(GroupMember gm:queueUsers)
            {
                userIds.add(gm.UserOrGroupId);
            }                                            
           
            List<User> u = [Select Id from User where Id IN :userIds AND IsActive=true Limit 5];
        if (u.size()>0)
        {
            System.runAs(u[0]) 
            {
                String caseId = c[0].id;
                AcceptOpenCase(caseId);                
                                             
                List<String> caseIDs= new List<String>();
                for(Case caseList:c)
                {
                     caseIDs.add(caseList.Id);
                }
                AcceptCase(caseIDs);
            }
        }
            
            List<User> u1 = [Select Id from User where Id NOT IN :userIds AND IsActive=true Limit 5];
        if (u1.size()>0)
        {
            System.runAs(u1[0]) 
            {
                String caseId = c[0].id;
                AcceptOpenCase(caseId);
                
                List<String> caseIDs= new List<String>();
                for(Case caseList:c)
                {
                     caseIDs.add(caseList.Id);                     
                }
                AcceptCase(caseIDs);
            }
        }
    }
}

 
Hi 
I'm new to apex.
can anyone help in writing TEST CLASSES of these 3 apex classes.
 
global class tridentUpdateCFormsWebService
{    
    webservice static SFAResponse updateCForms(CForms_element[] cfrmRec) {   
        SFAResponse objResponse = new SFAResponse();
        Exceptions__c excep = new Exceptions__c();                              // to capture web service failure exceptions.      
        List<C_Forms__c> cformList = new List<C_Forms__c>();
        List<string> sapCustList = new List<string>();
        for(CForms_element cfrmCust : cfrmRec)
        {
            if(cfrmCust.SAP_CustomerId != null && cfrmCust.SAP_CustomerId != '')
            sapCustList.add(cfrmCust.SAP_CustomerId);
        }
        Map<string,string> mapCust = new Map<string,string>();
        for(account cust : [select id, Cust_SAP_No__c from Account where Cust_SAP_No__c in : sapCustList])
        {mapCust.put(cust.Cust_SAP_No__c,cust.Id);}
        if(cfrmRec[0].SAP_Message == null || cfrmRec[0].SAP_Message == '')
        {
            for(CForms_element cfrm_Rec : cfrmRec)
            {
                C_Forms__c cform_Rec = new C_Forms__c();
                                
                cform_Rec.Excise_Invoice_No_vbeln_new__c = cfrm_Rec.Excise_Invoice_No_vbeln_new;
                cform_Rec.Customer_SAP_Code__c = cfrm_Rec.SAP_CustomerId;
                
                if(mapCust.get(cfrm_Rec.SAP_CustomerId) != null)
                cform_Rec.Account__c = mapCust.get(cfrm_Rec.SAP_CustomerId);
                cform_Rec.Customer_Name_name1_new__c = cfrm_Rec.Customer_Name_name1_new;              
                cform_Rec.Region_regio_new__c = cfrm_Rec.Region_regio_new;                
                cform_Rec.VAT_Amount_zvat_amt_new__c = cfrm_Rec.VAT_Amount_zvat_amt_new;
                cform_Rec.Diff_Liability_zdiff_amt_new__c = cfrm_Rec.Diff_Liability_zdiff_amt_new;
                cform_Rec.Accounting_Document_Number_belnr_new__c = cfrm_Rec.Accounting_Document_Number_belnr_new;              
                cform_Rec.Company_Code_bukrs_new__c = cfrm_Rec.Company_Code_bukrs_new;     
                cform_Rec.Fiscal_Year_gjahr_new__c = cfrm_Rec.Fiscal_Year_gjahr_new;
                cform_Rec.Quarter_zquarter_new__c = cfrm_Rec.Quarter_zquarter_new;
                cform_Rec.Invoice_Value_zinv_value_new__c = cfrm_Rec.Invoice_Value_zinv_value_new;
                cform_Rec.Tax_on_sales_and_Purchases_cod_mwskz_new__c = cfrm_Rec.Tax_on_sales_and_Purchases_cod_mwskz_new;
                                    
                cformList.add(cform_Rec);
            }
            try{
                upsert cformList;
                                                
                objResponse.SFDC_Rec_No = cfrmRec[0].Excise_Invoice_No_vbeln_new;
                objResponse.Status = true;
                return objResponse;
            }
            catch(exception e){
                excep.Record_Id__c = cfrmRec[0].Excise_Invoice_No_vbeln_new;
                //excep.Order__c = cfrmRec[0].cformsId;
                excep.error__c = e.getmessage();
                insert excep;
                
                objResponse.SFDC_Rec_No = cfrmRec[0].Excise_Invoice_No_vbeln_new;
                objResponse.Status = false;
                objResponse.Description = e.getmessage();
                return objResponse;// this will return result.
            }
        }
        else
        {
            list<Exceptions__c> lstexcep = new list<Exceptions__c>();
            for(integer i=0; i < cfrmRec.size(); i++)
            {
                Exceptions__c exp = new Exceptions__c();
                exp.Name = 'E';             
                
                lstexcep.add(exp);
            }
            insert lstexcep;
                       
            objResponse.SFDC_Rec_No = cfrmRec[0].Excise_Invoice_No_vbeln_new;
            objResponse.Status = false;
            return objResponse;// this will return result.
        }                            
    }
    global class CForms_element
    {
        webservice string SAP_CustomerId;        
        webservice string Customer_Name_name1_new;
        webservice string Excise_Invoice_No_vbeln_new;
        webservice string Region_regio_new;
        webservice string VAT_Amount_zvat_amt_new;
        webservice string Diff_Liability_zdiff_amt_new;
        webservice string Accounting_Document_Number_belnr_new;
        webservice string Company_Code_bukrs_new;
        webservice string Fiscal_Year_gjahr_new;
        webservice string Quarter_zquarter_new;
        webservice string Invoice_Value_zinv_value_new;
        webservice string Tax_on_sales_and_Purchases_cod_mwskz_new;
        webservice string SAP_Message;
    } 
    global class SFAResponse
    {
        webservice String SFDC_Rec_No;       
        webservice Boolean Status; 
        webservice String Description;
    }
 }
 
global class tridentUpdateStockWebService
{
    Webservice static SFAResponse updateStock(Stock_element[] StockRec) 
    {
        SFAResponse objResponse = new SFAResponse();
        list <Stock_Report__c> StockLst = new list <Stock_Report__c>{};
        Exceptions__c excep = new Exceptions__c();                              // to capture web service failure exceptions.
        
        
        Set<string> sapCustList = new Set<string>();
        for(Stock_element customerR : StockRec)
        {
            if(customerR.CustNo != null && customerR.CustNo != '')
            sapCustList.add(customerR.CustNo);
        }
        Map<string,string> mapCust = new Map<string,string>();
        for(account cust : [select id, Cust_SAP_No__c from Account where Cust_SAP_No__c in : sapCustList])
        {mapCust.put(cust.Cust_SAP_No__c,cust.Id);}
        
        
        for (Integer i=0; i< StockRec.size(); i++)
        {
            Stock_Report__c StockVr = new Stock_Report__c();
            StockVr.Customer_Name_name1_new__c= StockRec[i].Customer_Name_name1_new;
            
            if(mapCust.get(StockRec[i].CustNo) != null)
            StockVr.Customer__c = mapCust.get(StockRec[i].CustNo);
            
            StockVr.Customer_Number__c= StockRec[i].CustNo;   
            StockVr.Special_Stock_No_SONUM_new__c= StockRec[i].Special_Stock_No_SONUM_new;
            StockVr.Total_Stock_Gesme_new__c= StockRec[i].Total_Stock_Gesme_new;
            StockVr.Material_Code_Matnr_new__c= StockRec[i].Material_Code_Matnr_new;
            StockVr.Material_Description_MAktx_new__c= StockRec[i].Material_Description_MAktx_new;
            StockVr.Batch_Charg_new__c= StockRec[i].Batch_Charg_new;
            StockVr.Product_Type_Lv_type_new__c= StockRec[i].Product_Type_Lv_type_new;
            StockVr.Plant_Werks_new__c= StockRec[i].Plant_Werks_new;
            
            StockLst.add(StockVr);
            system.debug('Values taken'); 
        }
        if (StockLst.size()>0)
     {
        try
        { 
                upsert StockLst;                
                objResponse.Status = true;
                objResponse.Description = 'Record Updated';
                return objResponse;     // this will return result.
        }    
       catch(exception e)
        {
                excep.Record_Id__c = StockLst[0].Customer_Name_name1_new__c;
                excep.error__c = e.getmessage();
                insert excep;
                objResponse.SFDCId = StockLst[0].Customer_Name_name1_new__c;
                objResponse.Status = false;
                objResponse.Description = e.getmessage();
        }
     }
        return objResponse;     //this will return result.               
    }           
    
    global class stock_element
    {
        Webservice string CustNo;
        Webservice string Customer_Name_name1_new;
        Webservice string Special_Stock_No_SONUM_new;
        Webservice string Total_Stock_Gesme_new;
        Webservice string Material_Code_Matnr_new;
        Webservice string Material_Description_MAktx_new;
        Webservice string Batch_Charg_new;
        Webservice string Product_Type_Lv_type_new;
        Webservice string Plant_Werks_new;
        
    }
    
    global class SFAResponse
    {
        webservice String SFDCId;       
        webservice Boolean Status; 
        webservice String Description;
    }

}
 
global class tridentUpdateOverduePGLWebService
{    
    webservice static SFAResponse updateOverdue(Overdue_element[] OverdueRec) 
    {       
        //HttpRequest req = new HttpRequest();   
        //req.setHeader('Content-Type','application/x-www-form-urlencoded');
        SFAResponse objResponse = new SFAResponse();
        Exceptions__c excep = new Exceptions__c();                          // to capture web service failure exceptions.
        list<OverDue_PGL__c> OverdueLst = new list<OverDue_PGL__c>{};
        
    for (Integer i=0; i<OverdueRec.size();i++)
    {
        OverDue_PGL__c OverDueObj= new OverDue_PGL__c();
        
        OverDueObj.CustomerName_name1_new__c= OverdueRec[i].CustomerName_name1_new;
        OverDueObj.Total_Outstanding_INR_DMBTR_new__c = OverdueRec[i].Total_Outstanding_INR_DMBTR_new;
        OverDueObj.Payment_Term_Zterm_new__c = OverdueRec[i].Payment_Term_Zterm_new;
        OverDueObj.Overdue_Amount_INR_ovr_amt_new__c = OverdueRec[i].Overdue_Amount_INR_ovr_amt_new;
        OverDueObj.Ageing_Days_days_new__c = OverdueRec[i].Ageing_Days_days_new;      
        OverDueObj.Excise_Invoice_exnum_new__c = OverdueRec[i].Excise_Invoice_exnum_new;      
        OverDueObj.Item_Text_sgtxt_new__c = OverdueRec[i].Item_Text_sgtxt_new;
                              
        OverdueLst.add(OverDueObj);
        system.debug('Values taken');
  }

    if (Overduelst.size()>0)
    {                     
        try
            {
                insert OverdueLst;                
                objResponse.Status = true;
                objResponse.Description = 'Record Updated';
                system.debug('Record Updated');     
            }    
       catch(exception e)
            {
                system.debug('Error');
                excep.Record_Id__c = OverdueLst[0].CustomerName_name1_new__c;
                excep.error__c = e.getmessage();
                insert excep;
                
              //objResponse.SFDCId = OverdueLst.CustName;
                objResponse.Status = false;
                objResponse.Description = e.getmessage();
            }
     }
     else
     {        
      objResponse.Status = false;
      objResponse.Description ='No Item found to update';
      system.debug('Record not Updated');
     }
   return objResponse;                                                  // this will return result.
   }
        global class Overdue_element
      {
        webservice string CustomerName_name1_new;
        webservice string Total_Outstanding_INR_DMBTR_new;
        webservice string Payment_Term_Zterm_new;
        webservice string Overdue_Amount_INR_ovr_amt_new;
        webservice string Ageing_Days_days_new;
        webservice string Excise_Invoice_exnum_new;
        webservice string Item_Text_sgtxt_new;
    }
     global class SFAResponse
    {
      //webservice Id SFDCId;       
        webservice Boolean Status; 
        webservice String Description;
    }
}

 
Hi guys,
I am new to salesforce i don't know how to write the test class for trigger.Please,help me
This is my trigger:
trigger trigger_name on Task (after insert, after update) {


    List<Messaging.SingleEmailMessage> Smail = new List<Messaging.SingleEmailMessage>();
   
    /* EmailTemplate ETemplate = [Select id from EmailTemplate where DeveloperName=:'Call_Notes']; */

        List<Id> taskAccountId = new List<Id>();
    Task ttask = Trigger.New[0];
   
    for(Task tsk : Trigger.New){
     if(tsk.AccountId != null && tsk.Send_Email_to_Customer_Team__c == 'Yes')
           taskAccountId.add(tsk.AccountID);
      }   
   
    String S1 =  'CALL NOTES \n =========== \n Call Reason: ' + ttask.Call_Reason__c  + '\n Contact Date:' +  ttask.Contact_Date__c  + '\n Type:' + ttask.Type;   
    String S2 =  '\n Attendees: ' + ttask.Attendees__c   + '\n ISG Rep1: ' + ttask.ISG_Rep1__c   + '\n ISG Rep2: ' + ttask.ISG_Rep2__c   + '\n Product Officer1: ' + ttask.Product_Officer1__c   + '\n Product Officer2: ' + ttask.Product_Officer2__c   + '\n Other1: ' + ttask.Other1__c;
    String S3 =  '\n Other2: ' + ttask.Other2__c   + '\n Comments:' + ttask.Description;
    String Txt_Body = S1 + S2 + S3;
   
  
    for(AccountTeamMember acctMem : [Select UserId, Account.Name, TeamMemberRole from AccountTeamMember Where AccountId IN:taskAccountId]){
      Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();  
      mail.setTargetObjectId(acctMem.UserId);
      mail.subject = 'Call Notes Notification - ' + acctMem.Account.Name + '(Account Team)' ;
      mail.setUseSignature(true);
      mail.setBccSender(false);
      mail.setSaveAsActivity(false);
      mail.setSenderDisplayName(' Call Notes Notification');
      //mail.setTemplateId(ETemplate.Id);
      mail.setPlainTextBody(Txt_Body);
     
           
      Smail.add(mail);
    }  
    Messaging.sendEmail(Smail);
}

Thanks in Advance
Hi all, 
I need inputfield capability to get given input even after it is rerendered(hidden or shown) onchange of picklist value.

like if option 'a' is selected in picklist, the apex:inputfield with type textarea is shown and user enters data, and selecting 'b' hides rerenders and hides the field, and again if 'a' is selected i need field shown with previously given data in the field.
Thanks in advance.
Hello,

Is it possible to limit the number of characters of a text area ?

I want to limit the number of columns too..like for example
123456
123456
13455
133555

Max only 6 characters are allowed on vertically
  • February 24, 2017
  • Like
  • 0