• kirankumarreddy punuru
  • NEWBIE
  • 45 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 22
    Questions
  • 21
    Replies
Hi ,
I am having one trigger and i have created a test class for this trigger to achieve code coverage but some part of code is not covering can some one tell the root cause why the part of code is not covering:
My trigger is:
 if (trigger.isInsert)
    {
        oppTeamMembers = new List<Opportunity>([Select Name, Id,
                (SELECT Id, UserId, TeamMemberRole
                 FROM   OpportunityTeamMembers where EngTeamCreated__c= false) FROM Opportunity 
                                          WHERE Name IN :engagementName AND Type = 'New Business']);
        
    }
    else
    {
        oppTeamMembers = new List<Opportunity>([Select Name, Id,Related_Engagement__c,
                (SELECT Id, UserId, TeamMemberRole
                 FROM   OpportunityTeamMembers where EngTeamCreated__c= false) FROM Opportunity 
                                          WHERE Related_Engagement__c IN :engagementId AND Type != 'New Business']);
                                         
    }
        // from here the code is not covering in the test class
     for(Opportunity opp : oppTeamMembers )
    {
        String EngId;
        String EngCurrencyCode;
        Date EngStartDate;
        Date EngEndDate;
        
        if(trigger.isInsert)
        {
            EngId = EngMap.get(opp.Name).Id;
            EngCurrencyCode = EngMap.get(opp.Name).CurrencyIsoCode;
            EngStartDate = EngMap.get(opp.Name).Billing_Start_Date__c;
            EngEndDate = EngMap.get(opp.Name).Billing_End_Date__c;
        }
        else
        {
            EngId = EngagementMap.get(opp.Related_Engagement__c).Id;
            EngCurrencyCode = EngagementMap.get(opp.Related_Engagement__c).CurrencyIsoCode;
            EngStartDate = EngagementMap.get(opp.Related_Engagement__c).Billing_Start_Date__c;
            EngEndDate = EngagementMap.get(opp.Related_Engagement__c).Billing_End_Date__c; 
        }
        List<OpportunityTeamMember> oppTeam = new List<OpportunityTeamMember>(opp.OpportunityTeamMembers);
        //Creatig new record for engagament team and assigning values to relative fields  
        for (integer i = 0; i < oppTeam.size(); i++) 
        {
            Engagement_Team__c engTeam = new Engagement_Team__c();
            engTeam.CurrencyIsoCode   = EngCurrencyCode;
            engTeam.Engagement__c     = EngId;
            engTeam.Start_Date__c     = EngStartDate;
            engTeam.End_Date__c       = EngEndDate;
            engTeam.Team_Member__c    = oppTeam[i].UserId;
            engTeam.Team_Role__c      = oppTeam[i].TeamMemberRole;
            engTeamList.add(engTeam);
            oppTeam[i].EngTeamCreated__c = true;
            oppTeamToBeUpdated.add(oppTeam[i]);
        } 

My test class is:
@isTest
public with sharing class CreateEngTeamTest{
       public static testMethod void engagementTest(){
          RecordDatabase.objectWrapper objWrap = new RecordDatabase.objectWrapper();
        Boolean isApplicable = true;
        //Insert Account
        Map<String, String> accountValMap = new Map<String, String>{'Name' => 'Credit Suisse', 'CurrencyIsoCode' => 'USD', 'Industry' => 'Software',  
                                                'Type' => 'Customer', 'Region__c' => 'EMEA', 'Segment_dell__c' => 'LE', 'Client_Tier__c' => 'Growth'};
        List<Account> lstAccount = RecordDatabase.CreateAccount(1, accountValMap);
        insert lstAccount;
        
        objWrap.account = [Select Id from Account LIMIT 1];
        
        // Insert Product
        Map<String, String> productValMap = new Map<String, String>{'Name' => 'Specialist Onshore (3-12 months)', 'Description' => 'DEF', 'productCode' => 'prod',  
                                                'isActive' => 'true'};
        List<Product2> lstProduct = RecordDatabase.CreateProduct(1, productValMap);
        system.debug('@@@:- '+lstProduct);
        insert lstProduct;
        Product2 prod = [Select Id from Product2 LIMIT 1];
        
        // By default test can't access org data but using following method you can get standard pricebookId of org
        Id pricebookId = Test.getStandardPricebookId();
        
        // Insert a RecordType
        objWrap.rType = [SELECT Id FROM RecordType where Name='FS LTP'AND IsActive = TRUE limit 1];
        
        // Insert pricebookEntry
        Map<String, String> pbEntryValMap = new Map<String, String>{'Product2ID' => prod.Id, 'Pricebook2ID' => pricebookId, 'UnitPrice' => '21321.1',  
                                                'isActive' => 'true'};
        List<PricebookEntry> lstPricebookEntry = RecordDatabase.CreatePricebookEntry(1, pbEntryValMap);
        system.debug('@@@:- '+lstPricebookEntry);
        insert lstPricebookEntry;
        PricebookEntry pbEntry = [Select Id from PricebookEntry LIMIT 1];
        
        Trigger_Controller__c cs = new Trigger_Controller__c();
        cs.Name = 'ShouldCalculate';
        insert cs;
        
        Engagement__c updEngagement = new Engagement__c();
        updEngagement.Name = 'Tester Tesing Engage';
        updEngagement.Billing_Start_Date__c = date.today();
        updEngagement.Billing_end_Date__c = date.today().addDays(20);
        updEngagement.Account__c = lstAccount[0].Id;
        insert updEngagement;
        
        
        Engagement__c e = [select Id,Name from Engagement__c LIMIT 1];
        //Insert Opportunity
        Map<String, String> opptyValMap = new Map<String, String>{'Name' => 'Test Opp1', 'CurrencyIsoCode' => 'USD', 'AccountId' => objWrap.account.Id, 'StageName' => 'Opportunity Identified',   
                                                'Type' => 'Net New', 'Region__c' => 'EMEA', 'Create_Engagement__c' => 'No', 'Service_Areas__c' => 'Consulting', 'Reason_Won_lost__c' => '--None--',
                                                'Service_Class__c' => 'Pricing Ops Support', 'Probability' => '10', 'Cluster__c' => 'ABACUS', 'Pricebook2Id' => pricebookId};
        List<Opportunity> lstOppty = RecordDatabase.CreateOpportunity(1, opptyValMap, objWrap);
        system.debug('@@@ Oppty:- '+lstOppty);
        insert lstOppty;
        Opportunity oppty = [Select Id,Name,OwnerId, Create_Engagement__c, Final_Status__c, Type from Opportunity LIMIT 1];
        List<RecordType> lstRecType = [Select Id, SobjectType, Name, DeveloperName, Description From RecordType where Name =: 'DMS Read Only'];
     
        oppty.Create_Engagement__c = 'Yes';
        oppty.Type = 'New Business';
        oppty.Final_Status__c = 'Closed';
        oppty.Go_Live_Month__c = date.today();
        oppty.Related_Engagement__c = e.Id;
        OpportunityHalperClass.shouldRunTrigger = false; 
        update oppty;
        // inserting opportunity team member
        OpportunityTeamMember otm = new OpportunityTeamMember();
        otm.TeamMemberRole ='Sales Manager';
        otm.UserId = oppty.OwnerId;
        otm.OpportunityId = oppty.Id;
        otm.EngTeamCreated__c = false;
        insert otm;
        
        // list of engagement names
        List<String> engagementName = new List<String>();
        engagementName .add(oppty.Name);
        List<Opportunity> oppTeamMembers1 = new List<Opportunity>([Select Name, Id,
                (SELECT Id, UserId, TeamMemberRole
                 FROM   OpportunityTeamMembers where EngTeamCreated__c= false) FROM Opportunity 
                                          WHERE Name IN :engagementName AND Type = 'New Business']);
        
        system.debug('### List of opportunities:-'+oppTeamMembers1[0].Name);
       } 
        public static testMethod void engagementTest1(){
          RecordDatabase.objectWrapper objWrap = new RecordDatabase.objectWrapper();
        Boolean isApplicable = true;
        //Insert Account
        Map<String, String> accountValMap = new Map<String, String>{'Name' => 'Credit Suisse', 'CurrencyIsoCode' => 'USD', 'Industry' => 'Software',  
                                                'Type' => 'Customer', 'Region__c' => 'EMEA', 'Segment_dell__c' => 'LE', 'Client_Tier__c' => 'Growth'};
        List<Account> lstAccount = RecordDatabase.CreateAccount(1, accountValMap);
        insert lstAccount;
        
        objWrap.account = [Select Id from Account LIMIT 1];
        
        // Insert Product
        Map<String, String> productValMap = new Map<String, String>{'Name' => 'Specialist Onshore (3-12 months)', 'Description' => 'DEF', 'productCode' => 'prod',  
                                                'isActive' => 'true'};
        List<Product2> lstProduct = RecordDatabase.CreateProduct(1, productValMap);
        system.debug('@@@:- '+lstProduct);
        insert lstProduct;
        Product2 prod = [Select Id from Product2 LIMIT 1];
        
        // By default test can't access org data but using following method you can get standard pricebookId of org
        Id pricebookId = Test.getStandardPricebookId();
        
        // Insert a RecordType
        objWrap.rType = [SELECT Id FROM RecordType where Name='FS LTP'AND IsActive = TRUE limit 1];
        
        // Insert pricebookEntry
        Map<String, String> pbEntryValMap = new Map<String, String>{'Product2ID' => prod.Id, 'Pricebook2ID' => pricebookId, 'UnitPrice' => '21321.1',  
                                                'isActive' => 'true'};
        List<PricebookEntry> lstPricebookEntry = RecordDatabase.CreatePricebookEntry(1, pbEntryValMap);
        system.debug('@@@:- '+lstPricebookEntry);
        insert lstPricebookEntry;
        PricebookEntry pbEntry = [Select Id from PricebookEntry LIMIT 1];
        
        Trigger_Controller__c cs = new Trigger_Controller__c();
        cs.Name = 'ShouldCalculate';
        insert cs;
        
        Engagement__c updEngagement = new Engagement__c();
        updEngagement.Name = 'Tester Tesing Engage';
        updEngagement.Billing_Start_Date__c = date.today();
        updEngagement.CurrencyIsoCode = 'SGD';
        updEngagement.Billing_end_Date__c = date.today().addDays(20);
        updEngagement.Account__c = lstAccount[0].Id;
        insert updEngagement;
        IF( updEngagement.Billing_Start_Date__c == date.today()){
            updEngagement.Billing_Start_Date__c = date.today().addDays(10);
            update updEngagement;
            }
        
        Engagement__c e = [select Id,Name from Engagement__c LIMIT 1];
        //Insert Opportunity
        Map<String, String> opptyValMap = new Map<String, String>{'Name' => 'Test Opp', 'CurrencyIsoCode' => 'SGD', 'AccountId' => objWrap.account.Id, 'StageName' => 'Opportunity Identified',   
                                                'Type' => 'Net New', 'Region__c' => 'EMEA', 'Create_Engagement__c' => 'No', 'Service_Areas__c' => 'Consulting', 'Reason_Won_lost__c' => '--None--',
                                                'Service_Class__c' => 'Pricing Ops Support', 'Probability' => '10', 'Cluster__c' => 'ABACUS', 'Pricebook2Id' => pricebookId};
        List<Opportunity> lstOppty = RecordDatabase.CreateOpportunity(1, opptyValMap, objWrap);
        system.debug('@@@ Oppty:- '+lstOppty);
        insert lstOppty;
        Opportunity oppty = [Select Id,OwnerId, Create_Engagement__c, Final_Status__c, Type from Opportunity LIMIT 1];
        List<RecordType> lstRecType = [Select Id, SobjectType, Name, DeveloperName, Description From RecordType where Name =: 'DMS Read Only'];
     
        oppty.Create_Engagement__c = 'Yes';
        oppty.Type = 'Change';
        oppty.Final_Status__c = 'Closed';
        oppty.Go_Live_Month__c = date.today();
        oppty.Related_Engagement__c = e.Id;
        OpportunityHalperClass.shouldRunTrigger = false; 
        update oppty;
        // inserting opportunity team member
        OpportunityTeamMember otm = new OpportunityTeamMember();
        otm.TeamMemberRole ='Sales Manager';
        otm.UserId = oppty.OwnerId;
        otm.OpportunityId = oppty.Id;
        otm.EngTeamCreated__c = false;
        insert otm;
        
        // list of engagement ids
        List<Id> engagementId = new List<Id>();
        engagementId .add(e.Id);
        
        List<Opportunity> oppTeamMembers = new List<Opportunity>([Select Name, Id,Related_Engagement__c,
                (SELECT Id, UserId, TeamMemberRole
                 FROM   OpportunityTeamMembers where EngTeamCreated__c= false) FROM Opportunity 
                                          WHERE Related_Engagement__c IN :engagementId AND Type != 'New Business']);
        
        System.debug('@@@ Opportunities :-'+oppTeamMembers[0].Name);
       } 
     }
Hi ,
I got a email from ApexApplication [mailto:info@salesforce.com] saying that:: Developer script exception from eClerx : OLITrigger : OLITrigger: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Class.OLIHelper.annualEmergingClientCalculator: line 78, column 1 Class.OLIHelper
Apex script unhandled trigger exception by user/organization

OLITrigger: execution of AfterUpdate
 
caused by: System.NullPointerException: Attempt to de-reference a null object
 
Class.OLIHelper.annualEmergingClientCalculator: line 78, column 1
Class.OLIHelper.callFormulae: line 128, column 1
Class.OLIHelper.ProductSalesPriceUpdator: line 1178, column 1
Trigger.OLITrigger: line 87, column 

We have checked the code and added the null checks but still it sending this email can some one tell me the root cause for this error.

Thanks,
Kiran Kumar
Hi,
can some one tell me about this exception and  where to add null check:
my errors are:classname.methodname1: line 78,column 1
                    classname.methodname2: line 78,column 1 
                    classname.methodname3: line 78,column 1
                    Trigger:TriggerNAme:line no,column no

where i need to add null check in the class methods or in trigger.
Can some one tell me why this particular workflow error happening:
The following error occurred:
            Action Field Update Error
            A workflow or approval field update caused an error when saving this record. Contact your administrator to resolve it.
common.exception.SfdcSqlException: ORA-20067: OPPORTUNITY.PRICEBOOK2_ID
ORA-06512: at "DOC.SOPPORTUNITY", line 2481
ORA-06512: at line 1
 
{call sOpportunity.update_opportunities(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}
 
{call sOpportunity.update_opportunities(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}
 
Details:
Object Type: Opportunity
My trigger contains the following code :
  Map<String,Contact> cntMap=new Map<String,Contact>();
 list<contact> cnt=[select id,Email from contact where Email!=null AND Email IN: setEmailId];

and these are two conditions which are not covering :
1: if(cnt.size()>0)
    {
        for(integer i=0;i<cnt.size();i++)
        {
            cntMap.put(cnt[i].Email,cnt[i]);
        }
    }

2: if(cntMap.containsKey(contact.Email))
           {
                Contact oldCnt = cntMap.get(contact.Email);
                string Id;
                Id=oldCnt.Id;
                   if(contact.Id!=Id)   
                    contact.Email.addError('Duplicate Contact Email ID found  and the link for record is : ' + curUrl + '/' +Id);
           }


can any one tell me how to cover these lines in test class

Thanks,
Kiran
Hi ,
I have created a contact in test class and i need to update the contact owner for that inserted contact is it possible?
Regards,
Kiran
Hi ,
I am having one condtion in trigger like :
if(trigger.isUpdate && trigger.isAfter)
{
code;
}
 how to satisfy the above if condition to cover the code inside if condition .

Regards,
Kiran
 
if(tasksToUpdate.size() > 0 && calledFrom == 'batch')
            database.update(tasksToUpdate);

tasksToupdate is the list and remaining part i did not understood help me 
Hi ,
I am using a validation rule which displays an error when billing start date greater than or equal to billling end date .
My validation rule is :AND(Billing_start_date__c >= Billing_end_Date__c)
But this validation rule is displaying error even when the billing start date less than end date.
The validation rule is working fine in the case of edit but when we are insering a new record then it is showing an error.
I am sharing the screenshot can some one help me on this.User-added image
Regards,
Kiran 
Hi i need to check the currency for an object and have to set the currency of a field  to usd based on condition like this

if(opp.CurrencyIsoCode !='USD')
{
here i need to convert other currency to usd for a field called as salesprice__c

}
 
Hi,
    Iam having some validation rules on some  field let us say that field is discount in the apex class iam having the condition like
 
if(obj.discount >100)
{
 some code
}
   
now to cover this condition in the test class it is not allowing and showing an exception like this
; first error: FIELD_INTEGRITY_EXCEPTION, The Discount Percent must be between 0 and 100: [Discount]
how to overcome this exception any ideas
Hi,
can someone tell me how to solve this exception:
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Invalid permission set ID: {0}.: []
My test class is:
@istest
global class OpportunityTest{
static testMethod PermissionSetAssignment getPermissionA(){
         Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
        User u = new User(Alias = 'dardt', Email='normaluser@testorg.com', 
        EmailEncodingKey='UTF-8', LastName='Testuser', LanguageLocaleKey='en_US', 
        LocaleSidKey='en_US', ProfileId = p.Id, 
        TimeZoneSidKey='America/Los_Angeles', UserName='normaluser@testorg.com');
        insert u;  
        
        
        // creating one permissionsetassignment
      
        PermissionSetAssignment psg = new PermissionSetAssignment();
        psg.AssigneeId =u.Id;
        insert psg;
        return psg;
        }
here is my test class:
@isTest(SeeAllData = true)
Public with sharing class ChatterPostTriggerTest{
    // Positive test class for ChatterPostTrigger.trigger
    public static testMethod void PosTestForSinglePost(){
     
       Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
       User u = new User(Alias = 'dardt', Email='normaluser@testorg.com', 
            EmailEncodingKey='UTF-8', LastName='Testuser', LanguageLocaleKey='en_US', 
            LocaleSidKey='en_US', ProfileId = p.Id, 
            TimeZoneSidKey='America/Los_Angeles', UserName='normaluser@testorg.com', DMS_FS_CTS__c = 'FS');
            insert u;

        
     
        FeedItem feed = new FeedItem();
        feed.Body = 'This is test class';
        feed.ParentId = Userinfo.getUserId(); 
        feed.ContentDescription = 'this is test class for feed item';
        feed.Type = 'QuestionPost'; // added this because of the above line
        feed.Title ='test class';
        feed.Revision =2;
        // this is required if revision > 1
        feed.LastEditById = Userinfo.getUserId();
        // this is reired if revision > 1  
        feed.LastEditDate = date.today();   
        insert feed; 
    }
}

In the below trigger BOLDED 3 lines are not covered can someone tell me

This is my trigger:
trigger ChatterPostTrigger on FeedItem (before insert, after update) {
  IF(trigger.isInsert){
    // create set off all the user who posted on chatter
    // Create a map of UserId against FeedItem/post
    Map<ID, FeedItem> userFeedMap = new Map<ID, FeedItem>();
    for(FeedItem feed : trigger.New){
      userFeedMap.put(feed.ParentId, feed);
    }
    
    //get Id of chatterGroup
    CollaborationGroup chatterGroup = [Select Id, Name from CollaborationGroup where Name =: 'FS Onsites_FS' LIMIT 1];
    
    // get the chatterGroup name
    if(chatterGroup.Id != null){
      //Map of FS Onsite_FS against userID
      Map<ID, Boolean> groupMemberMap = new Map<ID, Boolean>(); 
      for(CollaborationGroupMember groupMember : [Select Id, CollaborationGroupId, memberId from CollaborationGroupMember where CollaborationGroupId =: chatterGroup.Id]){
        groupMemberMap.put(groupMember.memberId, True);
      }
      
      // filter the FS users only and create a list of FeedItems or Posts of FS USERS
      Set<ID> fsUserIds = new Set<ID>(); 
      for(User user : [Select Id, DMS_FS_CTS__c from User where Id IN : userFeedMap.KeySet() and DMS_FS_CTS__c =: 'FS']){
        fsUserIds.add(user.Id);
      }
      
      for(FeedItem feed : Trigger.New){
        for(ID userId : fsUserIds){
            if(feed.parentId == userId && groupMemberMap.get(userId) == true)
              feed.parentId = chatterGroup.Id
;
        } 
      }
    }
    
    
    //get Id of chatterGroup 'DMS Onsites & Sr. Ops_DMS'
    CollaborationGroup chatterGroup2 = [Select Id, Name from CollaborationGroup where Name =: 'DMS Onsites & Sr. Ops_DMS' LIMIT 1];
    
    // get the chatterGroup name
    if(chatterGroup2.Id != null){
      //Map of FS Onsite_FS against userID
      Map<ID, Boolean> groupMemberMap = new Map<ID, Boolean>(); 
      for(CollaborationGroupMember groupMember : [Select Id, CollaborationGroupId, memberId from CollaborationGroupMember where CollaborationGroupId =: chatterGroup2.Id]){
        groupMemberMap.put(groupMember.memberId, True);
      }
      
      // filter the FS users only and create a list of FeedItems or Posts of FS USERS
      Set<ID> fsUserIds = new Set<ID>(); 
      for(User user : [Select Id, DMS_FS_CTS__c from User where Id IN : userFeedMap.KeySet() and DMS_FS_CTS__c =: 'DMS']){
        fsUserIds.add(user.Id);
      }
      
      for(FeedItem feed : Trigger.New){
        for(ID userId : fsUserIds){
            if(feed.parentId == userId && groupMemberMap.get(userId) == true)
              feed.parentId = chatterGroup2.Id;
        } 
      }
    } 
  }
}
System.DmlException: Insert failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, U#22e.bff (LastEditBy), cannot be null when revision is greater than 1: [LastEditById]

my test class for trigger is:
@isTest(SeeAllData = true)
Public with sharing class ChatterPostTriggerTest{
    // Positive test class for ChatterPostTrigger.trigger
    public static testMethod void PosTestForSinglePost(){
        
        // Insert the feeditem
        FeedItem feed = new FeedItem();
        feed.Body = 'This is test class';
        //feed.ParentId = u.Id;
        feed.ContentDescription = 'this is test class for feed item';
        feed.Title ='test class';
        feed.Type = 'PollPost';
        feed.Revision =2;
        insert feed; 
    }
}
 
I am writing a test class feed item trigger ,iam getting this error can anyone help me
my trigger is
error:System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ChatterPostTrigger: execution of BeforeInsert

caused by: System.QueryException: List has no rows for assignment to SObject

Trigger.ChatterPostTrigger: line 11, column 1: []


@isTest
Public with sharing class ChatterPostTriggerTest {
 static testmethod void testChatterPostTrigger(){ 
Profile pr = [Select Id from Profile where Name='Standard User'];
User u = new User();
        u.Username  ='kiranp@test.com';
        u.LastName  ='John jane';      
        u.Alias     = 'jjhan';
        u.CommunityNickname = 'jhane';    
        u.Email ='kumarp@test.com';
        u.EmailEncodingKey = 'UTF-8';
        u.LanguageLocaleKey = 'en_US';
        u.LocaleSidKey = 'en_US';
        u.TimeZoneSidKey = 'America/Los_Angeles';
        u.ProfileId = pr.Id;
        insert u;
        
        // Inserting  feedItems list
        List<FeedItem> feedItems = new List<FeedItem>();
        FeedItem f = new FeedItem();
        f.Body = 'This is test class';
        f.ParentId = u.Id;
        f.ContentDescription = 'this is test class for feed item';
        f.ContentFileName ='test file';
        f.Title ='test class';
        f.Type = 'PollPost';
        feedItems.add(f);
        insert feedItems;
        
        //Collabaration Group Insertion
        List<CollaborationGroup> collabarationgroup = new List<CollaborationGroup>();
         CollaborationGroup   CG = new CollaborationGroup();
         CG.Description = 'This is Collabarationgroup' ;
         CG.Name ='MYGroup';
         
         collabarationgroup.add(CG);
         insert collabarationgroup;
         
         // Collabaration Group Member Insertion
          List<CollaborationGroupMember> cgm = new  List<CollaborationGroupMember>();
          CollaborationGroupMember CGMember = new CollaborationGroupMember();
          //CGMember.CollaborationGroupId = CollaborationGroup.Id;
         // CGMember.MemberId = CollaborationGroup.Id;
         CGMember.CollaborationRole ='Standard';
          cgm.add(CGMember);
          insert cgm;  
         
        }
        }
Can Someone give the reference links for writing test class for standard controllers .
Hi,
I am writing a test class for standard controller ,in that class iam calling another method but it is showing 
Method does not exist or incorrect signature: [ApexPages.StandardController].saveOpp() at line 38 column 19


my test class is :
/https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods

@isTest
public  class OLIEditAllControllerTestClass {
public static  testMethod void testOLIEditAllController() {
PageReference pageRef = Page.OLIeditAll;
Test.setCurrentPage(pageRef);

Opportunity opp =  new Opportunity();
opp.Name = 'Test Opp';
opp.StageName = 'client intrest';
opp.CloseDate = System.now().date();
insert opp;
 OpportunityLineItem oli = new OpportunityLineItem();
 oli.Quantity__c = 2;
 oli.OpportunityId =opp.Id;
 oli.Quantity =5;
 oli.UnitPrice =100;
 oli.Days__c =3;
 oli.Weeks__c =5;
 oli.Buffer__c =0.04;
 insert oli;
//List<OpportunityLineItem> listoli = new List<OpportunityLineItem>();
//listoli.add(oli);
List<OpportunityLineItem> listoli1 = [SELECT  Id,Unitprice,Quantity from OpportunityLineItem ];
ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(listoli1);
//OLIEditAllController controller = new OLIEditAllController(ssc);
ApexPages.StandardController controller = new ApexPages.StandardController(oli);

String IdString ='test string'; 
String OpptyName ='test opportunity';
List<OpportunityLineItem> myList = new List<OpportunityLineItem>();
myList.add(oli);
 
//List<OpportunityLineItem> listoli1 = [SELECT  Id,Unitprice,Quantity from OpportunityLineItem ];
 
String nextPage = controller.saveOpp().getUrl();
String nextPage1 = controller.redirectToOpp().getUrl();
String nextPage2 = controller.cancelOpp().getUrl();

System.assertEquals('/apex/failure?error=noParam', nextPage);
System.assertEquals('/apex/failure?error=noParam', nextPage1);
System.assertEquals('/apex/failure?error=noParam', nextPage2);

ApexPages.currentPage().getParameters().put(' test string');
ApexPages.currentPage().getParameters().put('OpptyName');
ApexPages.currentPage().getParameters().put('myList');


controller = new OLIEditAllController();

controller.setOpptyName ('OpptyName ');
controller.setIdString  ('IdString');
controller.setlstLineItem (listoli1);

nextPage = controller.saveOpp().getUrl();
nextPage1 = controller.redirectToOpp().getUrl();
nextPage2 = controller.cancelOpp().getUrl();

System.assertEquals('/apex/success', nextPage);
System.assertEquals('/apex/success', nextPage1);
System.assertEquals('/apex/success', nextPage2);
}
}
Hi ,
    Iam validating a text field and displaying error message when the condition fails , right now it is showing error at top of page i need to show next to field how can i acheive this my condition is like this..

if(oli.Discount > 100){
             ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, 'Discount should be in between 0 to 100.'));
             PageReference pa = new PageReference('/apex/OLIeditAll?ids='+ IdString);
             return pa;
Hi ,
 I need to write a trigger which checks all the leads and if any lead had duplicate lastname then in that i have to mark checkbox via trigger,for that i have written a trigger but it is not working can anyone help me..
my trigger is:
trigger LeadDuplicatePreventer on Lead (before insert ,after update) 
{
List<Lead> lead1 = new List<Lead>();
List<Lead> lead2 = new List<Lead>();
for (Lead L1 :trigger.new)
{
  for(Lead L2:trigger.new)
  {
   if(L1.LastName == L2.LastName)
   
    L1.Duplicate_Lastname1__c = true;
    exit();
   }
   
 } 
}
 
but is showing an error method does not exist exit();
Hi,
   I have a requirement to prevent saving the task record if the  contact is no longer with the firm , using the trigger.
   Can anyone helpme  how to write .

Thanks,
kiran.
Hi ,
I am having one trigger and i have created a test class for this trigger to achieve code coverage but some part of code is not covering can some one tell the root cause why the part of code is not covering:
My trigger is:
 if (trigger.isInsert)
    {
        oppTeamMembers = new List<Opportunity>([Select Name, Id,
                (SELECT Id, UserId, TeamMemberRole
                 FROM   OpportunityTeamMembers where EngTeamCreated__c= false) FROM Opportunity 
                                          WHERE Name IN :engagementName AND Type = 'New Business']);
        
    }
    else
    {
        oppTeamMembers = new List<Opportunity>([Select Name, Id,Related_Engagement__c,
                (SELECT Id, UserId, TeamMemberRole
                 FROM   OpportunityTeamMembers where EngTeamCreated__c= false) FROM Opportunity 
                                          WHERE Related_Engagement__c IN :engagementId AND Type != 'New Business']);
                                         
    }
        // from here the code is not covering in the test class
     for(Opportunity opp : oppTeamMembers )
    {
        String EngId;
        String EngCurrencyCode;
        Date EngStartDate;
        Date EngEndDate;
        
        if(trigger.isInsert)
        {
            EngId = EngMap.get(opp.Name).Id;
            EngCurrencyCode = EngMap.get(opp.Name).CurrencyIsoCode;
            EngStartDate = EngMap.get(opp.Name).Billing_Start_Date__c;
            EngEndDate = EngMap.get(opp.Name).Billing_End_Date__c;
        }
        else
        {
            EngId = EngagementMap.get(opp.Related_Engagement__c).Id;
            EngCurrencyCode = EngagementMap.get(opp.Related_Engagement__c).CurrencyIsoCode;
            EngStartDate = EngagementMap.get(opp.Related_Engagement__c).Billing_Start_Date__c;
            EngEndDate = EngagementMap.get(opp.Related_Engagement__c).Billing_End_Date__c; 
        }
        List<OpportunityTeamMember> oppTeam = new List<OpportunityTeamMember>(opp.OpportunityTeamMembers);
        //Creatig new record for engagament team and assigning values to relative fields  
        for (integer i = 0; i < oppTeam.size(); i++) 
        {
            Engagement_Team__c engTeam = new Engagement_Team__c();
            engTeam.CurrencyIsoCode   = EngCurrencyCode;
            engTeam.Engagement__c     = EngId;
            engTeam.Start_Date__c     = EngStartDate;
            engTeam.End_Date__c       = EngEndDate;
            engTeam.Team_Member__c    = oppTeam[i].UserId;
            engTeam.Team_Role__c      = oppTeam[i].TeamMemberRole;
            engTeamList.add(engTeam);
            oppTeam[i].EngTeamCreated__c = true;
            oppTeamToBeUpdated.add(oppTeam[i]);
        } 

My test class is:
@isTest
public with sharing class CreateEngTeamTest{
       public static testMethod void engagementTest(){
          RecordDatabase.objectWrapper objWrap = new RecordDatabase.objectWrapper();
        Boolean isApplicable = true;
        //Insert Account
        Map<String, String> accountValMap = new Map<String, String>{'Name' => 'Credit Suisse', 'CurrencyIsoCode' => 'USD', 'Industry' => 'Software',  
                                                'Type' => 'Customer', 'Region__c' => 'EMEA', 'Segment_dell__c' => 'LE', 'Client_Tier__c' => 'Growth'};
        List<Account> lstAccount = RecordDatabase.CreateAccount(1, accountValMap);
        insert lstAccount;
        
        objWrap.account = [Select Id from Account LIMIT 1];
        
        // Insert Product
        Map<String, String> productValMap = new Map<String, String>{'Name' => 'Specialist Onshore (3-12 months)', 'Description' => 'DEF', 'productCode' => 'prod',  
                                                'isActive' => 'true'};
        List<Product2> lstProduct = RecordDatabase.CreateProduct(1, productValMap);
        system.debug('@@@:- '+lstProduct);
        insert lstProduct;
        Product2 prod = [Select Id from Product2 LIMIT 1];
        
        // By default test can't access org data but using following method you can get standard pricebookId of org
        Id pricebookId = Test.getStandardPricebookId();
        
        // Insert a RecordType
        objWrap.rType = [SELECT Id FROM RecordType where Name='FS LTP'AND IsActive = TRUE limit 1];
        
        // Insert pricebookEntry
        Map<String, String> pbEntryValMap = new Map<String, String>{'Product2ID' => prod.Id, 'Pricebook2ID' => pricebookId, 'UnitPrice' => '21321.1',  
                                                'isActive' => 'true'};
        List<PricebookEntry> lstPricebookEntry = RecordDatabase.CreatePricebookEntry(1, pbEntryValMap);
        system.debug('@@@:- '+lstPricebookEntry);
        insert lstPricebookEntry;
        PricebookEntry pbEntry = [Select Id from PricebookEntry LIMIT 1];
        
        Trigger_Controller__c cs = new Trigger_Controller__c();
        cs.Name = 'ShouldCalculate';
        insert cs;
        
        Engagement__c updEngagement = new Engagement__c();
        updEngagement.Name = 'Tester Tesing Engage';
        updEngagement.Billing_Start_Date__c = date.today();
        updEngagement.Billing_end_Date__c = date.today().addDays(20);
        updEngagement.Account__c = lstAccount[0].Id;
        insert updEngagement;
        
        
        Engagement__c e = [select Id,Name from Engagement__c LIMIT 1];
        //Insert Opportunity
        Map<String, String> opptyValMap = new Map<String, String>{'Name' => 'Test Opp1', 'CurrencyIsoCode' => 'USD', 'AccountId' => objWrap.account.Id, 'StageName' => 'Opportunity Identified',   
                                                'Type' => 'Net New', 'Region__c' => 'EMEA', 'Create_Engagement__c' => 'No', 'Service_Areas__c' => 'Consulting', 'Reason_Won_lost__c' => '--None--',
                                                'Service_Class__c' => 'Pricing Ops Support', 'Probability' => '10', 'Cluster__c' => 'ABACUS', 'Pricebook2Id' => pricebookId};
        List<Opportunity> lstOppty = RecordDatabase.CreateOpportunity(1, opptyValMap, objWrap);
        system.debug('@@@ Oppty:- '+lstOppty);
        insert lstOppty;
        Opportunity oppty = [Select Id,Name,OwnerId, Create_Engagement__c, Final_Status__c, Type from Opportunity LIMIT 1];
        List<RecordType> lstRecType = [Select Id, SobjectType, Name, DeveloperName, Description From RecordType where Name =: 'DMS Read Only'];
     
        oppty.Create_Engagement__c = 'Yes';
        oppty.Type = 'New Business';
        oppty.Final_Status__c = 'Closed';
        oppty.Go_Live_Month__c = date.today();
        oppty.Related_Engagement__c = e.Id;
        OpportunityHalperClass.shouldRunTrigger = false; 
        update oppty;
        // inserting opportunity team member
        OpportunityTeamMember otm = new OpportunityTeamMember();
        otm.TeamMemberRole ='Sales Manager';
        otm.UserId = oppty.OwnerId;
        otm.OpportunityId = oppty.Id;
        otm.EngTeamCreated__c = false;
        insert otm;
        
        // list of engagement names
        List<String> engagementName = new List<String>();
        engagementName .add(oppty.Name);
        List<Opportunity> oppTeamMembers1 = new List<Opportunity>([Select Name, Id,
                (SELECT Id, UserId, TeamMemberRole
                 FROM   OpportunityTeamMembers where EngTeamCreated__c= false) FROM Opportunity 
                                          WHERE Name IN :engagementName AND Type = 'New Business']);
        
        system.debug('### List of opportunities:-'+oppTeamMembers1[0].Name);
       } 
        public static testMethod void engagementTest1(){
          RecordDatabase.objectWrapper objWrap = new RecordDatabase.objectWrapper();
        Boolean isApplicable = true;
        //Insert Account
        Map<String, String> accountValMap = new Map<String, String>{'Name' => 'Credit Suisse', 'CurrencyIsoCode' => 'USD', 'Industry' => 'Software',  
                                                'Type' => 'Customer', 'Region__c' => 'EMEA', 'Segment_dell__c' => 'LE', 'Client_Tier__c' => 'Growth'};
        List<Account> lstAccount = RecordDatabase.CreateAccount(1, accountValMap);
        insert lstAccount;
        
        objWrap.account = [Select Id from Account LIMIT 1];
        
        // Insert Product
        Map<String, String> productValMap = new Map<String, String>{'Name' => 'Specialist Onshore (3-12 months)', 'Description' => 'DEF', 'productCode' => 'prod',  
                                                'isActive' => 'true'};
        List<Product2> lstProduct = RecordDatabase.CreateProduct(1, productValMap);
        system.debug('@@@:- '+lstProduct);
        insert lstProduct;
        Product2 prod = [Select Id from Product2 LIMIT 1];
        
        // By default test can't access org data but using following method you can get standard pricebookId of org
        Id pricebookId = Test.getStandardPricebookId();
        
        // Insert a RecordType
        objWrap.rType = [SELECT Id FROM RecordType where Name='FS LTP'AND IsActive = TRUE limit 1];
        
        // Insert pricebookEntry
        Map<String, String> pbEntryValMap = new Map<String, String>{'Product2ID' => prod.Id, 'Pricebook2ID' => pricebookId, 'UnitPrice' => '21321.1',  
                                                'isActive' => 'true'};
        List<PricebookEntry> lstPricebookEntry = RecordDatabase.CreatePricebookEntry(1, pbEntryValMap);
        system.debug('@@@:- '+lstPricebookEntry);
        insert lstPricebookEntry;
        PricebookEntry pbEntry = [Select Id from PricebookEntry LIMIT 1];
        
        Trigger_Controller__c cs = new Trigger_Controller__c();
        cs.Name = 'ShouldCalculate';
        insert cs;
        
        Engagement__c updEngagement = new Engagement__c();
        updEngagement.Name = 'Tester Tesing Engage';
        updEngagement.Billing_Start_Date__c = date.today();
        updEngagement.CurrencyIsoCode = 'SGD';
        updEngagement.Billing_end_Date__c = date.today().addDays(20);
        updEngagement.Account__c = lstAccount[0].Id;
        insert updEngagement;
        IF( updEngagement.Billing_Start_Date__c == date.today()){
            updEngagement.Billing_Start_Date__c = date.today().addDays(10);
            update updEngagement;
            }
        
        Engagement__c e = [select Id,Name from Engagement__c LIMIT 1];
        //Insert Opportunity
        Map<String, String> opptyValMap = new Map<String, String>{'Name' => 'Test Opp', 'CurrencyIsoCode' => 'SGD', 'AccountId' => objWrap.account.Id, 'StageName' => 'Opportunity Identified',   
                                                'Type' => 'Net New', 'Region__c' => 'EMEA', 'Create_Engagement__c' => 'No', 'Service_Areas__c' => 'Consulting', 'Reason_Won_lost__c' => '--None--',
                                                'Service_Class__c' => 'Pricing Ops Support', 'Probability' => '10', 'Cluster__c' => 'ABACUS', 'Pricebook2Id' => pricebookId};
        List<Opportunity> lstOppty = RecordDatabase.CreateOpportunity(1, opptyValMap, objWrap);
        system.debug('@@@ Oppty:- '+lstOppty);
        insert lstOppty;
        Opportunity oppty = [Select Id,OwnerId, Create_Engagement__c, Final_Status__c, Type from Opportunity LIMIT 1];
        List<RecordType> lstRecType = [Select Id, SobjectType, Name, DeveloperName, Description From RecordType where Name =: 'DMS Read Only'];
     
        oppty.Create_Engagement__c = 'Yes';
        oppty.Type = 'Change';
        oppty.Final_Status__c = 'Closed';
        oppty.Go_Live_Month__c = date.today();
        oppty.Related_Engagement__c = e.Id;
        OpportunityHalperClass.shouldRunTrigger = false; 
        update oppty;
        // inserting opportunity team member
        OpportunityTeamMember otm = new OpportunityTeamMember();
        otm.TeamMemberRole ='Sales Manager';
        otm.UserId = oppty.OwnerId;
        otm.OpportunityId = oppty.Id;
        otm.EngTeamCreated__c = false;
        insert otm;
        
        // list of engagement ids
        List<Id> engagementId = new List<Id>();
        engagementId .add(e.Id);
        
        List<Opportunity> oppTeamMembers = new List<Opportunity>([Select Name, Id,Related_Engagement__c,
                (SELECT Id, UserId, TeamMemberRole
                 FROM   OpportunityTeamMembers where EngTeamCreated__c= false) FROM Opportunity 
                                          WHERE Related_Engagement__c IN :engagementId AND Type != 'New Business']);
        
        System.debug('@@@ Opportunities :-'+oppTeamMembers[0].Name);
       } 
     }
Hi ,
I have created a contact in test class and i need to update the contact owner for that inserted contact is it possible?
Regards,
Kiran
Hi ,
I am having one condtion in trigger like :
if(trigger.isUpdate && trigger.isAfter)
{
code;
}
 how to satisfy the above if condition to cover the code inside if condition .

Regards,
Kiran
 
if(tasksToUpdate.size() > 0 && calledFrom == 'batch')
            database.update(tasksToUpdate);

tasksToupdate is the list and remaining part i did not understood help me 
Hi ,
I am using a validation rule which displays an error when billing start date greater than or equal to billling end date .
My validation rule is :AND(Billing_start_date__c >= Billing_end_Date__c)
But this validation rule is displaying error even when the billing start date less than end date.
The validation rule is working fine in the case of edit but when we are insering a new record then it is showing an error.
I am sharing the screenshot can some one help me on this.User-added image
Regards,
Kiran 
Hi i need to check the currency for an object and have to set the currency of a field  to usd based on condition like this

if(opp.CurrencyIsoCode !='USD')
{
here i need to convert other currency to usd for a field called as salesprice__c

}
 
here is my test class:
@isTest(SeeAllData = true)
Public with sharing class ChatterPostTriggerTest{
    // Positive test class for ChatterPostTrigger.trigger
    public static testMethod void PosTestForSinglePost(){
     
       Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 
       User u = new User(Alias = 'dardt', Email='normaluser@testorg.com', 
            EmailEncodingKey='UTF-8', LastName='Testuser', LanguageLocaleKey='en_US', 
            LocaleSidKey='en_US', ProfileId = p.Id, 
            TimeZoneSidKey='America/Los_Angeles', UserName='normaluser@testorg.com', DMS_FS_CTS__c = 'FS');
            insert u;

        
     
        FeedItem feed = new FeedItem();
        feed.Body = 'This is test class';
        feed.ParentId = Userinfo.getUserId(); 
        feed.ContentDescription = 'this is test class for feed item';
        feed.Type = 'QuestionPost'; // added this because of the above line
        feed.Title ='test class';
        feed.Revision =2;
        // this is required if revision > 1
        feed.LastEditById = Userinfo.getUserId();
        // this is reired if revision > 1  
        feed.LastEditDate = date.today();   
        insert feed; 
    }
}

In the below trigger BOLDED 3 lines are not covered can someone tell me

This is my trigger:
trigger ChatterPostTrigger on FeedItem (before insert, after update) {
  IF(trigger.isInsert){
    // create set off all the user who posted on chatter
    // Create a map of UserId against FeedItem/post
    Map<ID, FeedItem> userFeedMap = new Map<ID, FeedItem>();
    for(FeedItem feed : trigger.New){
      userFeedMap.put(feed.ParentId, feed);
    }
    
    //get Id of chatterGroup
    CollaborationGroup chatterGroup = [Select Id, Name from CollaborationGroup where Name =: 'FS Onsites_FS' LIMIT 1];
    
    // get the chatterGroup name
    if(chatterGroup.Id != null){
      //Map of FS Onsite_FS against userID
      Map<ID, Boolean> groupMemberMap = new Map<ID, Boolean>(); 
      for(CollaborationGroupMember groupMember : [Select Id, CollaborationGroupId, memberId from CollaborationGroupMember where CollaborationGroupId =: chatterGroup.Id]){
        groupMemberMap.put(groupMember.memberId, True);
      }
      
      // filter the FS users only and create a list of FeedItems or Posts of FS USERS
      Set<ID> fsUserIds = new Set<ID>(); 
      for(User user : [Select Id, DMS_FS_CTS__c from User where Id IN : userFeedMap.KeySet() and DMS_FS_CTS__c =: 'FS']){
        fsUserIds.add(user.Id);
      }
      
      for(FeedItem feed : Trigger.New){
        for(ID userId : fsUserIds){
            if(feed.parentId == userId && groupMemberMap.get(userId) == true)
              feed.parentId = chatterGroup.Id
;
        } 
      }
    }
    
    
    //get Id of chatterGroup 'DMS Onsites & Sr. Ops_DMS'
    CollaborationGroup chatterGroup2 = [Select Id, Name from CollaborationGroup where Name =: 'DMS Onsites & Sr. Ops_DMS' LIMIT 1];
    
    // get the chatterGroup name
    if(chatterGroup2.Id != null){
      //Map of FS Onsite_FS against userID
      Map<ID, Boolean> groupMemberMap = new Map<ID, Boolean>(); 
      for(CollaborationGroupMember groupMember : [Select Id, CollaborationGroupId, memberId from CollaborationGroupMember where CollaborationGroupId =: chatterGroup2.Id]){
        groupMemberMap.put(groupMember.memberId, True);
      }
      
      // filter the FS users only and create a list of FeedItems or Posts of FS USERS
      Set<ID> fsUserIds = new Set<ID>(); 
      for(User user : [Select Id, DMS_FS_CTS__c from User where Id IN : userFeedMap.KeySet() and DMS_FS_CTS__c =: 'DMS']){
        fsUserIds.add(user.Id);
      }
      
      for(FeedItem feed : Trigger.New){
        for(ID userId : fsUserIds){
            if(feed.parentId == userId && groupMemberMap.get(userId) == true)
              feed.parentId = chatterGroup2.Id;
        } 
      }
    } 
  }
}
Hi,
I am writing a test class for standard controller ,in that class iam calling another method but it is showing 
Method does not exist or incorrect signature: [ApexPages.StandardController].saveOpp() at line 38 column 19


my test class is :
/https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods

@isTest
public  class OLIEditAllControllerTestClass {
public static  testMethod void testOLIEditAllController() {
PageReference pageRef = Page.OLIeditAll;
Test.setCurrentPage(pageRef);

Opportunity opp =  new Opportunity();
opp.Name = 'Test Opp';
opp.StageName = 'client intrest';
opp.CloseDate = System.now().date();
insert opp;
 OpportunityLineItem oli = new OpportunityLineItem();
 oli.Quantity__c = 2;
 oli.OpportunityId =opp.Id;
 oli.Quantity =5;
 oli.UnitPrice =100;
 oli.Days__c =3;
 oli.Weeks__c =5;
 oli.Buffer__c =0.04;
 insert oli;
//List<OpportunityLineItem> listoli = new List<OpportunityLineItem>();
//listoli.add(oli);
List<OpportunityLineItem> listoli1 = [SELECT  Id,Unitprice,Quantity from OpportunityLineItem ];
ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(listoli1);
//OLIEditAllController controller = new OLIEditAllController(ssc);
ApexPages.StandardController controller = new ApexPages.StandardController(oli);

String IdString ='test string'; 
String OpptyName ='test opportunity';
List<OpportunityLineItem> myList = new List<OpportunityLineItem>();
myList.add(oli);
 
//List<OpportunityLineItem> listoli1 = [SELECT  Id,Unitprice,Quantity from OpportunityLineItem ];
 
String nextPage = controller.saveOpp().getUrl();
String nextPage1 = controller.redirectToOpp().getUrl();
String nextPage2 = controller.cancelOpp().getUrl();

System.assertEquals('/apex/failure?error=noParam', nextPage);
System.assertEquals('/apex/failure?error=noParam', nextPage1);
System.assertEquals('/apex/failure?error=noParam', nextPage2);

ApexPages.currentPage().getParameters().put(' test string');
ApexPages.currentPage().getParameters().put('OpptyName');
ApexPages.currentPage().getParameters().put('myList');


controller = new OLIEditAllController();

controller.setOpptyName ('OpptyName ');
controller.setIdString  ('IdString');
controller.setlstLineItem (listoli1);

nextPage = controller.saveOpp().getUrl();
nextPage1 = controller.redirectToOpp().getUrl();
nextPage2 = controller.cancelOpp().getUrl();

System.assertEquals('/apex/success', nextPage);
System.assertEquals('/apex/success', nextPage1);
System.assertEquals('/apex/success', nextPage2);
}
}
Hi ,
    Iam validating a text field and displaying error message when the condition fails , right now it is showing error at top of page i need to show next to field how can i acheive this my condition is like this..

if(oli.Discount > 100){
             ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, 'Discount should be in between 0 to 100.'));
             PageReference pa = new PageReference('/apex/OLIeditAll?ids='+ IdString);
             return pa;
Hi ,
 I need to write a trigger which checks all the leads and if any lead had duplicate lastname then in that i have to mark checkbox via trigger,for that i have written a trigger but it is not working can anyone help me..
my trigger is:
trigger LeadDuplicatePreventer on Lead (before insert ,after update) 
{
List<Lead> lead1 = new List<Lead>();
List<Lead> lead2 = new List<Lead>();
for (Lead L1 :trigger.new)
{
  for(Lead L2:trigger.new)
  {
   if(L1.LastName == L2.LastName)
   
    L1.Duplicate_Lastname1__c = true;
    exit();
   }
   
 } 
}
 
but is showing an error method does not exist exit();
Hi,
   I have a requirement to prevent saving the task record if the  contact is no longer with the firm , using the trigger.
   Can anyone helpme  how to write .

Thanks,
kiran.
Hi,
  I have created two triggers on same object account.one trigger is for before update and another is for after update .when i am trying to update the same record it is showing runtime error like this.
Error:Apex trigger AccountTrigger2 caused an unexpected exception, contact your administrator: AccountTrigger2: execution of AfterUpdate caused by: System.FinalException: Record is read-only: Trigger.AccountTrigger2: line 6, column 1
 
Can anyone explain the reason and how  to avoid infinite looping .

Thanks,
kiran