• Kyo
  • NEWBIE
  • 25 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 29
    Questions
  • 20
    Replies

it's not work 2 line 

hilight a line not work in the Trigger

 

setAccountNumber.add(myNewCon .Account_Number__c) ;

myNewCon.AccountID = Acc.id;

 

@isTest
private class TestUpdateAccountNameAndNumberinContact{
     
     static testMethod void myUnitPopContact() {
      Account Acc = new Account(Name = 'test',AccountNumber = '0000001');
         insert Acc;
      Account Acc2 = new Account(Name = 'test2',AccountNumber = '0000001');
         insert Acc2;
      
      Test.StartTest();   
      Contact Con = new Contact();
      ApexPages.currentPage().getParameters().put('id',con.id);
      Con.LastName = 'test2';
      Con.AccountID = Acc.id;
      Con.Account_Number__c = Acc.AccountNumber;
      insert con;
      try{
         update con;
         }catch(DMLException de){}
         
      Contact Dup = new Contact();
      Dup.LastName = 'test';
      Dup.AccountID = Acc2.id;
      Dup.Account_Number__c = Con.Account_Number__c ;
      insert Dup;
      try{
         update Dup;
         }catch(DMLException de){}                    
         Test.StopTest();        
     }
}

 

 

trigger UpdateAccountNameAndNumberinContact on Contact (before Update){
//List<Account> Acc = new List<Account>();
Set<String> setAccountNumber = new Set<String>();
Set<String> setAccount = new Set<String>();

    for(Contact  Con : Trigger.new){
        Map<Id,Contact> newConMap = Trigger.newMap;
        Map<Id,Contact> oldConMap = Trigger.oldMap;

        for(Id ConId:newConMap.keySet()){
        Contact myNewCon = newConMap.get(ConId);
        Contact myOldCon = oldConMap.get(ConId);
        
          if(myNewCon.AccountID == myOldCon.AccountID &&  myNewCon.Account_Number__c <> myOldCon.Account_Number__c && myNewCon.Account_Number__c != null){ 
                setAccountNumber.add(myNewCon .Account_Number__c) ;
            }
             else if(myNewCon.AccountID <> myOldCon.AccountID &&  myNewCon.Account_Number__c == myOldCon.Account_Number__c && myNewCon.AccountID != null){
                setAccount.add(myNewCon .AccountID ) ;
            }
         }
    }  
    Account Acc = new Account();
    
    List<Account> lstAcc = [Select id,AccountNumber from Account Where AccountNumber in :  setAccountNumber or id in : setAccount];
    if(lstAcc.size()>0) {
        Acc = lstAcc[0];
    }
    
    for(Contact Con : Trigger.new){
        Map<Id,Contact> newConMap = Trigger.newMap;
        Map<Id,Contact> oldConMap = Trigger.oldMap;

        for(Id ConId:newConMap.keySet()){
        Contact myNewCon = newConMap.get(ConId);
        Contact myOldCon = oldConMap.get(ConId);
        
                if(myNewCon.AccountID == myOldCon.AccountID &&  myNewCon.Account_Number__c <> myOldCon.Account_Number__c && myNewCon.Account_Number__c != null){                 
                    myNewCon.AccountID = Acc.id;
                }
                else if(myNewCon.AccountID <> myOldCon.AccountID &&  myNewCon.Account_Number__c == myOldCon.Account_Number__c && myNewCon.AccountID != null){
                    myNewCon.Account_Number__c  = Acc.AccountNumber;
                }
                /*else if(myNewCon.AccountID <> myOldCon.AccountID &&  myNewCon.Account_Number__c <> myOldCon.Account_Number__c && myNewCon.AccountID != null && myNewCon.Account_Number__c != null){
                    myNewCon.AccountID.AddError('Mismatch Account Name and Account Number');
                    myNewCon.Account_Number__c.AddError('Mismatch Account Name and Account Number');
                }*/
               
                
}
}
}

 

Thank you so much

  • July 29, 2011
  • Like
  • 0

Test Class is not full loop . it's problem 1 line in Testclass

Coverage is 85% now

 

trigger ChangeStatusinOBC on Out_Bound_Call_List__c (Before insert,Before Update) {
// You can change status equal Complete when RelatedList OB Contact status all Complete
set<ID> setOBLID = new set<ID>();

    

    for(Out_Bound_Call_List__c OBL : Trigger.new){
            setOBLID.Add(OBL.ID);      
    } // Add id for Query
    
    List<OutBound_Contact__c> lstOBC = [Select id from OutBound_Contact__c where  Out_Bound_Call_List__c in : setOBLID]; // Query OutBound Contact List
    System.debug('Error SOQL');
    
    for(Out_Bound_Call_List__c OBL : Trigger.new){
        if((lstOBC.size() != OBL.Count_Complete__c) && lstOBC.size() != 0 && OBL.Status__c == 'Completed'){
            Trigger.new[0].Status__c.AddError('Status in OutBound Contact all not equal to contacted');
        }// Set Error in Field Status 
    }

}

 

a problem line : 

if((lstOBC.size() != OBL.Count_Complete__c) && lstOBC.size() != 0 && OBL.Status__c == 'Completed'){

 

@isTest 
private class TestChangeStatusinOBC {
    static testMethod void myTest() {
    
        Out_Bound_Call_List__c OBL = new Out_Bound_Call_List__c();
        OBL.Name = 'Test';
        insert OBL;
        
        OutBound_Contact__c OBC = new OutBound_Contact__c();
        OBC.Out_Bound_Call_List__c = OBL.id;
        OBC.Status__c = 'Contacted';
        insert OBC;
        update OBC;
        
        Out_Bound_Call_List__c OBL1 = new Out_Bound_Call_List__c();
        OBL.Name = 'Test';
        OBL.Status__c = 'Completed';
        test.startTest();
        Try{
            insert OBL;
            update OBL;
        }
        catch (Exception e) {   
            System.Debug('Status in OutBound Contact all not equal to contacted');
        }
        test.stopTest();
    
    
    }
}

 

Thank you so much.

  • July 28, 2011
  • Like
  • 0

I'm Test Class and Trigger not work. becasue for loop 

 

trigger MarkforDelAllinCon on Contact(before Update) {
set<ID> setContactID = new set<ID>();
    
        for(Contact Con: Trigger.new){
        if(Con.MarkforDelete__c == true){   
            setContactID.Add(Con.id);  
        }
        }
             
        List<Relationship__c > lstRel = [Select id,Mark_for_Delete__c,Contact_ID__c,Account_ID__c,Rev_Account_ID__c,Rev_Contact_ID__c  from Relationship__c Where  Contact_ID__c in :   setContactID and Mark_for_Delete__c !=: True];
           
        for(Contact Con: Trigger.new){
            if(lstRel.size() != 0 ){
                     for(Relationship__c Res : lstRel){ 
                        Res.Contact_ID__c  = Con.id;
                        Res.Rev_Contact_ID__c  = Con.id;            
                        Res.Mark_for_Delete__c = true;
                        update Res;
                     }                  
            }
}
}

 Error in Test Class Line :

for(Relationship__c Res : lstRel){

                      Res.Contact_ID__c  = Con.id;

                      Res.Rev_Contact_ID__c  = Con.id;

                      Res.Mark_for_Delete__c = true; 

                      update Res; 

         }    

 

@isTest
private class TestMarkforDelAllinCon {
    static testMethod void myTest() {
    
    Account objAcc = new Account();
    objAcc.Name = 'testAcc1';
    objAcc.AccountNumber = 'TestA00001';
    insert objAcc;
    
    Account objAccRev = new Account();
    objAccRev.Name = 'testAcc2';
    objAccRev.AccountNumber = 'TestA00001';
    insert objAccRev;
    
    Contact con = new Contact();
    con.AccountID = objAcc.id;
    con.LastName = 'TestCon1';
    con.MarkforDelete__c = True;
    insert con;
    update con;
    
    Contact ConRev = new Contact();
    ConRev.AccountID = objAcc.id;
    ConRev.LastName = 'TestCon2';
    ConRev.MarkforDelete__c = True;
    insert conRev;
    update conRev;
    
    List<Relationship__c>  Rel = new List<Relationship__c> ();
    ApexPages.currentPage().getParameters().put('id',con.id);
        for(Relationship__c Res : Rel){
        Res.Contact_ID__c = Con.id;
        Res.Rev_Contact_ID__c = Con.id;
        Res.Mark_for_Delete__c = true;
        update Res;
        }    
}
}

 Thank you so much.

  • July 20, 2011
  • Like
  • 0

I can't open tab or subtab for Hyperlink in formula field.

formula can do this.

 

HYPERLINK(Id,'Mr. ' &  FirstName & ' ' &  LastName, '_parent') 

 

Thank you so much.

  • July 20, 2011
  • Like
  • 0
public class MarkDeleteAccount{

 public MarkDeleteAccount(ApexPages.StandardController controller) {
    Acc = new Account(id = Apexpages.Currentpage().getParameters().get('id'));
        Acc.Mark_for_Delete__c = true;
        
  
  }
  
Public Account Acc {get;set;}
    
    public PageReference save(){     
       update Acc;
        PageReference returnPage = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        returnPage.setRedirect(true);
        return returnPage;
        
    
    }
    public PageReference Cancel() {
        PageReference returnPage = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        returnPage.setRedirect(true);
        return returnPage;
        
    }
  
    }

 

@isTest 
    private  class TestMarkDeleteAccount{
    static testMethod void myTest1() {
    
      List<Account> lstAcc = new List<Account>();
      ApexPages.StandardSetController sc = new  ApexPages.StandardSetController(lstAcc);
      
      Account  Acc = new Account();
      Acc.Name = 'Test Acc1';
      Acc.BP_Type__c = 'SCCC Mason';
      Acc.Mark_for_Delete__c = true;
      insert Acc;
      update Acc;
      ApexPages.currentPage().getParameters().put('id', Acc.Id); 
      Test.StartTest();
      sc.Save();
      sc.Cancel();
      Test.StopTest(); 
    }    
    
   
}

Test Class is 0% CodeCoverage. I can not make an error. 

Thank you.

  • July 20, 2011
  • Like
  • 0

I'm not write test class is full loop. Because ploblem adderror method.

 

trigger RelationDuplicationA2A on Relationship__c(before insert) {
set<ID> setAccountID = new set<ID>();
set<ID> setRevAccountID = new set<ID>();
integer setRecordType;

for(Relationship__c ra: Trigger.new){
   if(ra.Account_ID__r.Mark_for_Delete__c != true || ra.Rev_Account_ID__r.Mark_for_Delete__c  != true && (ra.RecordTypeID == '01290000000Ym1W')){
       if (Trigger.new[0].Account_ID__c != NULL && Trigger.new[0].Rev_Account_ID__c != NULL)  {
           setAccountID.Add(ra.Account_ID__c);  //Set Value Relation Account to Account
           setRevAccountID.Add(ra.Rev_Account_ID__c);
           setRecordType = 1;  //set value criteria
       }  
   }
    
}
//------------------------------------------- End Add Data --------------------------------------------------------------------------------------------------

// SOQL for Duplicate Relationship without Loop
    if(setRecordType == 1){
           List<Relationship__c> rs = [ select id,Account_ID__c,Rev_Account_ID__c,Mark_for_Delete__c from Relationship__c  WHERE Account_ID__c = :Trigger.new[0].Account_ID__c And Rev_Account_ID__c =: trigger.new[0].Rev_Account_ID__c And Mark_for_Delete__c =: false];
               
               if (rs.size() > 0 ) {
                   Trigger.new[0].Account_ID__c.addError('Duplicate Relationship');
                   Trigger.new[0].Rev_Account_ID__c.addError('Duplicate Relationship');
               }
     }
}

 Ploblem Trigger Line : 

Trigger.new[0].Account_ID__c.addError('Duplicate Relationship');                 Trigger.new[0].Rev_Account_ID__c.addError('Duplicate Relationship');

 

@isTest
private class TestRelationDuplicationA2A  {
   static testMethod void myUnitTest() {
      Account Acc = new Account(Name = 'test',AccountNumber = '00000001');
         insert Acc;
      Contact Con = new Contact(LastName = 'test',AccountID = Acc.id);
         insert con;
      
      Relationship__c ra = new Relationship__c(Account_ID__c = Acc.id,Rev_Account_ID__c = Acc.id,Mark_for_Delete__c = False);
         try{      
            insert ra;
            }catch(DMLException de){

        }  
      Relationship__c Dup = new Relationship__c(Account_ID__c = Acc.id,Rev_Account_ID__c = Acc.id,Mark_for_Delete__c = False);
             try {
             insert Dup;
             }
             catch (Exception e) {
                   System.debug('Duplicate Relationship');                        
             } 
  }
}

 Thank you so much.


  • July 20, 2011
  • Like
  • 0

Button Code Error Cannot Call Method 'closeTeb' of undefined

 

{!REQUIRESCRIPT("/soap/ajax/8.0/connection.js")}
{!REQUIRESCRIPT("/support/console/20.0/integration.js")}
var Relationship__c = new sforce.SObject("Relationship__c"); 
Relationship__c.id = "{!Relationship__c.Id}"; 
Relationship__c.Mark_for_Delete__c = true;
var result = sforce.connection.update([Relationship__c]);
if (result[0].getBoolean("success")) 
{ 
// Refresh window 
window.location.reload(); 
window.open('', '_self', '');
sforce.console.closeTab();

} 
else 
{ 
alert("Error saving event"); 
}

 Thank you so much.

  • July 09, 2011
  • Like
  • 0

Not Error 

 

trigger CaseMasterSync on Case (before insert,before update) {
List<Case_Master__c> cm = new List<Case_Master__c>();

for(case ca : Trigger.new){
    if(ca.Case_Category__c != 'Z - Customer Care' && ca.Sub_Category__c != null ){
        
        cm = [select id,Case_Category__c,Case_Escalation_To__c,Description__c,Function__c,Priority__c,Queue__c,Queue_Name__c,SLA_Time_Hours__c,Status__c,Sub_Category__c,Text_Note__c,Type__c from
                Case_Master__c Where Case_Category__c =: ca.Case_Category__c and Sub_Category__c =: ca.Sub_Category__c and Description__c =: ca.Description__c and Customer_Class__c =: ca.Customer_Class__c];
        
        for(Case_Master__c cmt : cm){
                if(cmt.Function__c != null){ca.Function__c = cmt.Function__c;}
                if(cmt.Priority__c != null){ca.Priority = cmt.Priority__c;}
                if(cmt.SLA_Time_Hours__c != null){ca.SLATimeHours__c = cmt.SLA_Time_Hours__c;}
                if(cmt.Text_Note__c != null){ca.Text_Note__c = cmt.Text_Note__c;}
                if(cmt.Status__c != null){ca.Status = cmt.Status__c;}
                if(cmt.Type__c != null){ca.Type = cmt.Type__c;}       
                if(cmt.Case_Escalation_To__c != null){ ca.OwnerId = cmt.Case_Escalation_To__c;}
               
                
        }
    }   
}
}

 

@isTest 
private class TestCaseMasterSync {
    static testMethod void myTest() {
    
          
        Account Acc = new Account();
        Acc.Name = 'test'; 
        Acc.AccountNumber = '000001';
        insert Acc;
        update Acc;
     
        Contact con = new Contact();
        Con.AccountID = Acc.id;
        Con.Email = 'Test@Email.com';
        Con.Email_2__c = 'Test2@Email.com';
        Con.LastName = 'Test';
        insert Con;
        update Con;
        
        Profile p = [select id from profile where name='Standard User'];
        User ua = new User(alias = 'test123', email='test123@noemail.com',
            emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
            localesidkey='en_US', profileid = p.Id, country='United States',
            timezonesidkey='America/Los_Angeles', username='test123@noemail.com');
            insert ua; 
        
        Case_Master__c cm = new Case_Master__c();     
        cm.Type__c = 'Inquiry';
        cm.Status__c = 'Open 2nd Level';
        cm.Case_Category__c = 'CIPI';
        cm.Sub_Category__c = 'ISCC - Open ISCC Account';
        cm.Description__c = 'Request open ISCC account';
        cm.Customer_Class__c = 'Platinum';
        insert cm;
        update cm;
        
        Case ca = new Case();     
        ca.Account_Number__c  = '000001';
        ca.AccountID = Acc.id;
        ca.ContactID = con.id;
        ca.SuppliedEmail = 'Test@Email.com';     
        ca.Origin = 'Phone';      
        ca.Case_Category__c = 'CIPI';
        ca.Sub_Category__c = 'ISCC - Open ISCC Account';
        ca.Description__c = 'Request open ISCC account';
        ca.SLATimeHours__c = cm.SLA_Time_Hours__c ;
        ca.Text_Note__c = cm.Text_Note__c ;
        ca.Priority = cm.Priority__c ;
        ca.Function__c = cm.Function__c ;
        ca.Status = cm.Status__c ;
        ca.OwnerID = ua.id ;
        ca.Type = cm.Type__c;
        insert ca;
        Test.Starttest();
        update ca;
        Test.Stoptest();    
        }
        }

 Thank you so much.

  • June 30, 2011
  • Like
  • 0

System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []

 

rigger trgLookupSLAValues on Case (after insert) {

    for(Case caseArgs : Trigger.new) {
    
        List<Case_Master__c> caseMasters = [select Text_Note__c,Case_Escalation_To__c,Queue_Name__c, 
        Type__c,Priority__c, Function__c, SLA_Time_Hours__c, Status__c from Case_Master__c 
        where Case_Category__c =: caseArgs.Case_Category__c and Sub_Category__c =:caseArgs.Sub_Category__c 
        and Description__c =: caseArgs.Description__c and Customer_Class__c =: caseArgs.Customer_Class__c ];

        if(caseMasters.IsEmpty()) {
            RelationMgrException ex = new RelationMgrException('Cannot find Case Master record');
            throw ex;
        }
        else {
        
        
        Case_Master__c caseMasterTemp = caseMasters.get(0);
        
        Case caseNew = new Case(Id=caseArgs.Id);
        caseNew.OwnerId = caseMasterTemp.Case_Escalation_To__c;
        caseNew.Function__c = caseMasterTemp.Function__c;
        caseNew.Priority = caseMasterTemp.Priority__c;
        caseNew.SLATimeHours__c = caseMasterTemp.SLA_Time_Hours__c;
        caseNew.Text_Note__c = caseMasterTemp.Text_Note__c;
        caseNew.Status = caseMasterTemp.Status__c;
        caseNew.Type = caseMasterTemp.Type__c;
        
        update caseNew ;
        }
        
      
    }
  
}

 



@isTest 
private class TesttrgLookupSLAValues{
    static testMethod void TestMethodtrgLookupSLAValues() {
      
     Account Acc = new Account();
        Acc.Name = 'test1'; 
        Acc.AccountNumber = '000001';
        Acc.CustomerPriority__c = 'Platinum';       
        insert Acc;
        

    Case_Master__c CM = new Case_Master__c();
         CM.Text_Note__c = ' test ';
         CM.Case_Category__c ='Z - Customer Solution';
         CM.Sub_Category__c ='CSD - Price and Policy';
         CM.Description__c ='Complaint about price and policy';
         CM.Customer_Class__c ='Complaint about price and policy';       
    insert CM;
    
     Case ca = new Case();
        ca.AccountID = Acc.Id;
        ca.Origin = 'Web';
        ca.Status = 'Open 1st Level';
        ca.Type = 'Inquiry';
        ca.Multi_Account__c = true;
        ca.Case_Category__c = 'Z - Customer Solution';
        ca.Sub_Category__c = 'CSD - Open New Ship to';
        ca.Description__c = 'Request add new ship to';
    update ca;
    
    }

    
}

 

Thank you so much.

  • June 26, 2011
  • Like
  • 0

 

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, trgCreateRelationship: execution of AfterInsert caused by: System.AssertException: Assertion Failed: CUSTOM_MSG: IsEmpty: Expected: TOKEN1, Actual: TOKEN2 Class.RelationshipMgr.createRelationship: line 16, column 13 Trigger.trgCreateRelationship: line 8, column 13: []

 

@isTest 
private class TestRelationshipMgr {
    
    static testMethod void createRelationship() {
  
      Account objAcc = new Account();
      objAcc.Name = 'test';
      insert objAcc;
      
      Contact objcon = new Contact();
      objcon.LastName = 'test';
      objcon.AccountID = objAcc.ID;
      objcon.Sex__c = 'Male';   
      insert objcon;
      
      Relationship_Category__c RC = new Relationship_Category__c();
      RC.Name = 'Test';
      RC.Relationship_Type__c = 'Account to Account';
      RC.Reverse_Relationship_Category__c = RC.id;
      RC.Reversible__c = true;
      insert RC;
     
      Relationship__c objRe = new Relationship__c ();
      objRe.Account_ID__c = objAcc.id;
      objRe.Contact_ID__c = objCon.id;
      objRe.Rev_Account_ID__c = objAcc.id;
      objRe.Rev_Contact_ID__c = objCon.id;
      objRe.IsTrigger__c = '1';
      objRe.Relationship_Category__c = RC.id;
          
      test.starttest();
      insert objRe;
      test.stoptest();
     
    }
     static testMethod void markDeleteRelationship() {
     
     Account objAcc = new Account();
      objAcc.Name = 'test';
      insert objAcc;
      
      Contact objcon = new Contact();
      objcon.LastName = 'test';
      objcon.AccountID = objAcc.ID;
      objcon.Sex__c = 'Male';   
      insert objcon;
      
      Relationship_Category__c RC = new Relationship_Category__c();
      RC.Name = 'Test';
      RC.Relationship_Type__c = 'Account to Account';
      RC.Reverse_Relationship_Category__c = RC.id;
      RC.Reversible__c = true;
      insert RC;
     
      Relationship__c objRe = new Relationship__c ();
      objRe.Mark_for_Delete__c  = true;
      test.starttest();
      
      insert objRe;
      test.stoptest();
}
}

 

public class RelationshipMgr {


    public static void createRelationship(Relationship__c relArgs) {
           
        // First ,get corresponding "Relationship Type" from the given "Relationship Category", we
        // need to query from "Relationship Category" obj, "relArgs.Relationship_Category__c"
        // is a Lookup, thus, it contains system ID (Id field) of the "Relationship_Category" obj
        // not the "Name" field...
        List<Relationship_Category__c> relCats = [select Relationship_Type__c, Reverse_Relationship_Category__c, Name, Reversible__c from Relationship_Category__c where Id =: relArgs.Relationship_Category__c];
  
        // TEMP CODE: to be removed or cleaned...      
        if (relCats.IsEmpty()) {
            System.assertEquals('TOKEN1', 'TOKEN2', 'CUSTOM_MSG: IsEmpty');    
        }
        
        Relationship_Category__c relCatTemp = relCats.get(0);
                  
        // At the highest level, we group our business rules by "Relationship Type", inside each
        // top-level if/else clause implements BRs specific to each "Relationship Type"...        

        if (relCatTemp.Relationship_Type__c == 'Account to Account') {

            // "Account to Account", all business rules for this case here...
        
            // create second paried (reverse) record...    
            Relationship__c relReverse = new Relationship__c();
            relReverse.Relationship_Category__c = relCatTemp.Reverse_Relationship_Category__c;
            relReverse.Account_ID__c = relArgs.Rev_Account_ID__c;
            relReverse.Rev_Account_ID__c = relArgs.Account_ID__c;
            relReverse.IsTrigger__c = '1';
            
            //insert relReverse;
            
      
            // since, we only submit one obj, therefore, only one obj returned in SaveResult[] array...
            Relationship__c[] relTemps = new Relationship__c[1];
            relTemps[0] = relReverse;
            Database.SaveResult[] result = Database.Insert(relTemps);
            
            
            // now, we need to update the parent "Relationship" record (relArgs) with the new "Id" of the
            // reversed record just inserted...
            Relationship__c relArgsCloned = relArgs.clone(true, true);
            relArgsCloned.Rev_Relationship__c =  result[0].Id;
            update relArgsCloned;            
        
        } else if (relCatTemp.Relationship_Type__c == 'Account to Contact') {

            // "Account to Contact", all business rules for this case here...
     
            // First, we need to check of the underlying Contact record has a value in the "Account Name"
            // field, if NOT, then we need to populate it...
            List<Contact> contacts = [select AccountId from Contact where Id =: relArgs.Contact_ID__c];
            
            if (contacts.IsEmpty()) {
                System.assertEquals('TOKEN1', 'TOKEN2', 'CUSTOM_MSG: contacts IsEmpty');    
            }
        
            Contact contactTemp = contacts.get(0);
            
            
            if (contactTemp.AccountId == null) {
            
                List<Account> accounts = [select Id from Account where Id =: relArgs.Account_ID__c];
            
                if (accounts.IsEmpty()) {
                    System.assertEquals('TOKEN1', 'TOKEN2', 'CUSTOM_MSG: accounts IsEmpty');    
                }
            
                Account accountTemp = accounts.get(0);
                contactTemp.AccountId = accountTemp.Id;
                
                update contactTemp;
            }

            Relationship__c relReverse = new Relationship__c();
            
            // Next, we need to check whether the "Relationship" is created from Account or Contact page,
            // the ID assignment rule differs according to the source page...
            if (relArgs.Account_ID__c != null) {
                // "Relationship" is created from "Account" page (Account ID available)...
                relReverse.Contact_ID__c = relArgs.Rev_Contact_ID__c;
                relReverse.Rev_Account_ID__c = relArgs.Account_ID__c; 
                     
            }
            else if (relArgs.Contact_ID__c != null) {
                // "Relationship" is created from "Contact" page (Account ID available)...
                relReverse.Rev_Contact_ID__c = relArgs.Contact_ID__c;
                relReverse.Account_ID__c = relArgs.Rev_Account_ID__c; 

            }
            else {
                // invalid case, not supposed to happen, thus raise the exception...
                System.assertEquals('TOKEN1', 'TOKEN2', 'CUSTOM_MSG: either Account ID or Contact ID must exist...');    
            
            }
            
           
            // Now, create second paired (reverse) record...
            relReverse.Relationship_Category__c = relCatTemp.Reverse_Relationship_Category__c;
            relReverse.IsTrigger__c = '1';
            insert relReverse;

        } else if (relCatTemp.Relationship_Type__c == 'Contact to Contact') {

            // "Contact to Contact", all business rules for this case here...

            // create second paired (reverse) record...
            Relationship__c relReverse = new Relationship__c();
            
            
            // First, we need to check if the parent Contact has Account or not (AccountId field null),
            // if NO, then we need to auto link with the same Account as the reversed Contact...
            List<Contact> contacts = [select AccountId from Contact where Id =: relArgs.Contact_ID__c];
            
            if (contacts.IsEmpty()) {
                System.assertEquals('TOKEN1', 'TOKEN2', 'CUSTOM_MSG: contacts IsEmpty');    
            }
        
            Contact contactParent = contacts.get(0);
         
            if (contactParent.AccountId == null) {
                // the parent Contact does NOT have Account, we must copy the AccountId from the reversed Contact
                // into this parent Contact...            
                contacts = [select AccountId from Contact where Id =: relArgs.Rev_Contact_ID__c];
            
                if (contacts.IsEmpty()) {
                    System.assertEquals('TOKEN1', 'TOKEN2', 'CUSTOM_MSG: contacts IsEmpty');    
                }
            
                Contact contactTempReverse = contacts.get(0);
                contactParent.AccountId = contactTempReverse.AccountId;                
 
                update contactParent;
            }


            // Next, we need to check against "Reversible" flag (checkbox), normal cases are NOT reversible, if it's
            // reversible, then it's the case like "Is Married To" (we follow screen here, which a little conflict
            // with our code namving convention)...
            if (!relCatTemp.Reversible__c) {
            
                // Next, we need to check if this is "Has Child" relationship category, if yes,
                // then we need to figure out the parent Contact record whether it's "Male" or
                // "Female" via the "Sex" field, note that, the assumption here is that the "Sex"
                // field is always has value (required field in Contact object)...
                
                // note, we need to use "Relationship Category" obj, not "Relationship", because the "Relationship"
                // obj contains the system Id not actual text...
                if (relCatTemp.Name == 'Has Child') {
                
                    contacts = [select Sex__c from Contact where Id =: relArgs.Contact_ID__c];
                
                    if (contacts.IsEmpty()) {
                        System.assertEquals('TOKEN1', 'TOKEN2', 'CUSTOM_MSG: contacts IsEmpty');    
                    }
                
                    Contact contactTemp = contacts.get(0);
    
    
                    // we need to get the system "Id", because "Relationship" obj uses "Lookup" for the "Relationship Category"
                    // field...
                    List<Relationship_Category__c> relCatTemps = [select Id, Name from Relationship_Category__c where Name='Has Father' or Name='Has Mother'];
    
                    if (relCatTemps .IsEmpty()) {
                        System.assertEquals('TOKEN1', 'TOKEN2', 'CUSTOM_MSG: Relationship Category IsEmpty');    
                    }
                
                    String strRelCatIdFather = '';
                    String strRelCatIdMother = '';
                
                    for (Relationship_Category__c relCatTemp2 : relCatTemps) {
                        
                        if (relCatTemp2.Name == 'Has Father')
                            strRelCatIdFather = relCatTemp2.Id;
                        else if (relCatTemp2.Name == 'Has Mother')
                            strRelCatIdMother = relCatTemp2.Id;    
                    }
       
                    // now, assign corresponding "Relationship Category to the reverse "Relationship" obj...
                    if (contactTemp.Sex__c == 'Male')               
                        relReverse.Relationship_Category__c  = strRelCatIdFather; //'Has Father';
                    else if (contactTemp.Sex__c == 'Femail')
                        relReverse.Relationship_Category__c  = strRelCatIdMother; //'Has Mother';                   
                    else
                        relReverse.Relationship_Category__c  = strRelCatIdMother; //'default to Has Mother';
    
                }
                else {
                
                    relReverse.Relationship_Category__c = relCatTemp.Reverse_Relationship_Category__c;
    
                }
                
            }
            else {
            
                // REVERSIBLE: this is for case like "Is Married To" when the "Reversible" field
                // is checked...
                relReverse.Relationship_Category__c = relArgs.Relationship_Category__c;
            
            }
 
            relReverse.Contact_ID__c = relArgs.Rev_Contact_ID__c;
            relReverse.Rev_Contact_ID__c = relArgs.Contact_ID__c;
            relReverse.IsTrigger__c = '1';            
            insert relReverse;

        }

    
    } // end method...

    
    // This method implements logical delete (Mark Delete) for the Relationship record. It's required
    // "Mark Delete" because of trigger limitation, which does NOT allow delete of the same record type
    // in the "before and after" event via the "delete sObject[]" operation.
    public static void markDeleteRelationship(Relationship__c relArgs) {
        
        //System.assertEquals('TOKEN1', 'TOKEN2', 'CUSTOM_MSG: ' + relArgs.Rev_Relationship__c + ' - ' + relArgs.Id);       

        // NOTE - 140611: WE NO LONGER NEED THIS FLAGMENT BECAUSE WE USE THE STANDARD DELETE FUNCTION TO PHYSICALLY
        // DELETE PARENT RECORD!!!
        // first, update the parent record as deleted...
        //Relationship__c relArgsCloned = relArgs.clone(true, true);
        //relArgsCloned.Mark_for_Delete__c = true;
        //update relArgsCloned;
       
        // now, we need update the paired record as deleted (Mark for Delete = true), the Apex scheduler will
        // perform the physical delete at scheduled interval...
        Relationship__c relTemp = new Relationship__c(Id=relArgs.Rev_Relationship__c);
        relTemp.Mark_for_Delete__c = true;
        update relTemp;             
    
    } // end method...


} // end class...

 Thank you so much.


  • June 19, 2011
  • Like
  • 0
public class RelationshipMgr {


    public static void createRelationship(Relationship__c relArgs) {
    
        //System.assertEquals('TOKEN1', 'TOKEN2', 'CUSTOM_MSG: ' + relArgs.RecordType);
        
        // First ,get corresponding "Relationship Type" from the given "Relationship Category", we
        // need to query from "Relationship Category" obj, "relArgs.Relationship_Category__c"
        // is a Lookup, thus, it contains system ID (Id field) of the "Relationship_Category" obj
        // not the "Name" field...
        List<Relationship_Category__c> relCats = [select Relationship_Type__c, Reverse_Relationship_Category__c, Name, Reversible__c from Relationship_Category__c where Id =: relArgs.Relationship_Category__c];
  
        // TEMP CODE: to be removed or cleaned...      
        if (relCats.IsEmpty()) {
            System.assertEquals('TOKEN1', 'TOKEN2', 'CUSTOM_MSG: IsEmpty');    
        }
        
        Relationship_Category__c relCatTemp = relCats.get(0);
 
        
        //System.assertEquals('TOKEN1', 'TOKEN2', 'CUSTOM_MSG: ' + relCatTemp.Relationship_Type__c);
 
        
        // At the highest level, we group our business rules by "Relationship Type", inside each
        // top-level if/else clause implements BRs specific to each "Relationship Type"...        

        if (relCatTemp.Relationship_Type__c == 'Account to Account') {

            // "Account to Account", all business rules for this case here...
        
            // create second paried (reverse) record...    
            Relationship__c relReverse = new Relationship__c();
            relReverse.Relationship_Category__c = relCatTemp.Reverse_Relationship_Category__c;
            relReverse.Account_ID__c = relArgs.Rev_Account_ID__c;
            relReverse.Rev_Account_ID__c = relArgs.Account_ID__c;
            relReverse.IsTrigger__c = '1';
            
            //insert relReverse;
            
      
            // since, we only submit one obj, therefore, only one obj returned in SaveResult[] array...
            Relationship__c[] relTemps = new Relationship__c[1];
            relTemps[0] = relReverse;
            Database.SaveResult[] result = Database.Insert(relTemps);
            
            //System.assertEquals('TOKEN1', 'TOKEN2', 'CUSTOM_MSG: ' + relTemps[0].Id);
            //System.assertEquals('TOKEN1', 'TOKEN2', 'CUSTOM_MSG: ' + result[0].Id);
            
            // now, we need to update the parent "Relationship" record (relArgs) with the new "Id" of the
            // reversed record just inserted...
            Relationship__c relArgsCloned = relArgs.clone(true, true);
            relArgsCloned.Rev_Relationship__c =  result[0].Id;
            update relArgsCloned;            
        
        } else if (relCatTemp.Relationship_Type__c == 'Account to Contact') {

            // "Account to Contact", all business rules for this case here...
     
            // First, we need to check of the underlying Contact record has a value in the "Account Name"
            // field, if NOT, then we need to populate it...
            List<Contact> contacts = [select AccountId from Contact where Id =: relArgs.Contact_ID__c];
            
            if (contacts.IsEmpty()) {
                System.assertEquals('TOKEN1', 'TOKEN2', 'CUSTOM_MSG: contacts IsEmpty');    
            }
        
            Contact contactTemp = contacts.get(0);
            
            //System.assertEquals('TOKEN1', 'TOKEN2', 'CUSTOM_MSG: ' + contactTemp.AccountId);
            
            if (contactTemp.AccountId == null) {
            
                List<Account> accounts = [select Id from Account where Id =: relArgs.Account_ID__c];
            
                if (accounts.IsEmpty()) {
                    System.assertEquals('TOKEN1', 'TOKEN2', 'CUSTOM_MSG: accounts IsEmpty');    
                }
            
                Account accountTemp = accounts.get(0);
                contactTemp.AccountId = accountTemp.Id;
                
                update contactTemp;
            }

            Relationship__c relReverse = new Relationship__c();
            
            // Next, we need to check whether the "Relationship" is created from Account or Contact page,
            // the ID assignment rule differs according to the source page...
            if (relArgs.Account_ID__c != null) {
                // "Relationship" is created from "Account" page (Account ID available)...
                relReverse.Contact_ID__c = relArgs.Rev_Contact_ID__c;
                relReverse.Rev_Account_ID__c = relArgs.Account_ID__c; 
                     
            }
            else if (relArgs.Contact_ID__c != null) {
                // "Relationship" is created from "Contact" page (Account ID available)...
                relReverse.Rev_Contact_ID__c = relArgs.Contact_ID__c;
                relReverse.Account_ID__c = relArgs.Rev_Account_ID__c; 

            }
            else {
                // invalid case, not supposed to happen, thus raise the exception...
                System.assertEquals('TOKEN1', 'TOKEN2', 'CUSTOM_MSG: either Account ID or Contact ID must exist...');    
            
            }
            
           
            // Now, create second paired (reverse) record...
            relReverse.Relationship_Category__c = relCatTemp.Reverse_Relationship_Category__c;
            relReverse.IsTrigger__c = '1';
            insert relReverse;

        } else if (relCatTemp.Relationship_Type__c == 'Contact to Contact') {

            // "Contact to Contact", all business rules for this case here...

            // create second paired (reverse) record...
            Relationship__c relReverse = new Relationship__c();
            
            
            // First, we need to check if the parent Contact has Account or not (AccountId field null),
            // if NO, then we need to auto link with the same Account as the reversed Contact...
            List<Contact> contacts = [select AccountId from Contact where Id =: relArgs.Contact_ID__c];
            
            if (contacts.IsEmpty()) {
                System.assertEquals('TOKEN1', 'TOKEN2', 'CUSTOM_MSG: contacts IsEmpty');    
            }
        
            Contact contactParent = contacts.get(0);
         
            if (contactParent.AccountId == null) {
                // the parent Contact does NOT have Account, we must copy the AccountId from the reversed Contact
                // into this parent Contact...            
                contacts = [select AccountId from Contact where Id =: relArgs.Rev_Contact_ID__c];
            
                if (contacts.IsEmpty()) {
                    System.assertEquals('TOKEN1', 'TOKEN2', 'CUSTOM_MSG: contacts IsEmpty');    
                }
            
                Contact contactTempReverse = contacts.get(0);
                contactParent.AccountId = contactTempReverse.AccountId;                
 
                update contactParent;
            }


            // Next, we need to check against "Reversible" flag (checkbox), normal cases are NOT reversible, if it's
            // reversible, then it's the case like "Is Married To" (we follow screen here, which a little conflict
            // with our code namving convention)...
            if (!relCatTemp.Reversible__c) {
            
                // Next, we need to check if this is "Has Child" relationship category, if yes,
                // then we need to figure out the parent Contact record whether it's "Male" or
                // "Female" via the "Sex" field, note that, the assumption here is that the "Sex"
                // field is always has value (required field in Contact object)...
                
                // note, we need to use "Relationship Category" obj, not "Relationship", because the "Relationship"
                // obj contains the system Id not actual text...
                if (relCatTemp.Name == 'Has Child') {
                
                    contacts = [select Sex__c from Contact where Id =: relArgs.Contact_ID__c];
                
                    if (contacts.IsEmpty()) {
                        System.assertEquals('TOKEN1', 'TOKEN2', 'CUSTOM_MSG: contacts IsEmpty');    
                    }
                
                    Contact contactTemp = contacts.get(0);
    
        
                    //System.assertEquals('TOKEN1', 'TOKEN2', 'CUSTOM_MSG: ' + contactTemp.Sex__c);
    
                    // we need to get the system "Id", because "Relationship" obj uses "Lookup" for the "Relationship Category"
                    // field...
                    List<Relationship_Category__c> relCatTemps = [select Id, Name from Relationship_Category__c where Name='Has Father' or Name='Has Mother'];
    
                    if (relCatTemps .IsEmpty()) {
                        System.assertEquals('TOKEN1', 'TOKEN2', 'CUSTOM_MSG: Relationship Category IsEmpty');    
                    }
                
                    String strRelCatIdFather = '';
                    String strRelCatIdMother = '';
                
                    for (Relationship_Category__c relCatTemp2 : relCatTemps) {
                        
                        if (relCatTemp2.Name == 'Has Father')
                            strRelCatIdFather = relCatTemp2.Id;
                        else if (relCatTemp2.Name == 'Has Mother')
                            strRelCatIdMother = relCatTemp2.Id;    
                    }
       
                    // now, assign corresponding "Relationship Category to the reverse "Relationship" obj...
                    if (contactTemp.Sex__c == 'Male')               
                        relReverse.Relationship_Category__c  = strRelCatIdFather; //'Has Father';
                    else if (contactTemp.Sex__c == 'Femail')
                        relReverse.Relationship_Category__c  = strRelCatIdMother; //'Has Mother';                   
                    else
                        relReverse.Relationship_Category__c  = strRelCatIdMother; //'default to Has Mother';
    
                }
                else {
                
                    relReverse.Relationship_Category__c = relCatTemp.Reverse_Relationship_Category__c;
    
                }
                
            }
            else {
            
                // REVERSIBLE: this is for case like "Is Married To" when the "Reversible" field
                // is checked...
                relReverse.Relationship_Category__c = relArgs.Relationship_Category__c;
            
            }
 
            relReverse.Contact_ID__c = relArgs.Rev_Contact_ID__c;
            relReverse.Rev_Contact_ID__c = relArgs.Contact_ID__c;
            relReverse.IsTrigger__c = '1';            
            insert relReverse;

        }

    
    } // end method...

    
    // This method implements logical delete (Mark Delete) for the Relationship record. It's required
    // "Mark Delete" because of trigger limitation, which does NOT allow delete of the same record type
    // in the "before and after" event via the "delete sObject[]" operation.
    public static void markDeleteRelationship(Relationship__c relArgs) {
        
        //System.assertEquals('TOKEN1', 'TOKEN2', 'CUSTOM_MSG: ' + relArgs.Rev_Relationship__c + ' - ' + relArgs.Id);       

        // NOTE - 140611: WE NO LONGER NEED THIS FLAGMENT BECAUSE WE USE THE STANDARD DELETE FUNCTION TO PHYSICALLY
        // DELETE PARENT RECORD!!!
        // first, update the parent record as deleted...
        //Relationship__c relArgsCloned = relArgs.clone(true, true);
        //relArgsCloned.Mark_for_Delete__c = true;
        //update relArgsCloned;
       
        // now, we need update the paired record as deleted (Mark for Delete = true), the Apex scheduler will
        // perform the physical delete at scheduled interval...
        Relationship__c relTemp = new Relationship__c(Id=relArgs.Rev_Relationship__c);
        relTemp.Mark_for_Delete__c = true;
        update relTemp;             
    
    } // end method...


} // end class...

 

@isTest 
private class TestRelationshipMgr {
    
    static testMethod void myTest() {
  
      Account objAcc = new Account();
      objAcc.Name = 'test';
      insert objAcc;
      
      Contact objcon = new Contact();
      objcon.LastName = 'test';
      objcon.AccountID = objAcc.ID;
      objcon.Sex__c = 'Male';
    
      insert objcon;
      
      Relationship_Category__c RC = new Relationship_Category__c();
      RC.Name = 'Test';
      RC.Relationship_Type__c = 'Account to Account';
      RC.Reverse_Relationship_Category__c = RC.id;
      RC.Reversible__c = true;
      insert RC;
      
      Relationship__c objRe = new Relationship__c ();
      objRe.Account_ID__c = objAcc.id;
      //objRe.Contact_ID__c = objCon.id;
      objRe.Rev_Account_ID__c = objAcc.id;
      //objRe.Rev_Contact_ID__c = objCon.id;
      objRe.IsTrigger__c = '1';
      objRe.Relationship_Category__c = RC.id;
      objRe.Mark_for_Delete__c  = true;
      
      test.starttest();
      insert objRe;
      test.stoptest();
     
    }
    
    static testMethod void myTest1() {
  
      Account objAcc = new Account();
      objAcc.Name = 'test';
      insert objAcc;
      
      Contact objcon = new Contact();
      objcon.LastName = 'test';
      objcon.AccountID = objAcc.ID;
      objcon.Sex__c = 'Male';
    
      insert objcon;
      
      Relationship_Category__c RC = new Relationship_Category__c();
      RC.Name = 'Test';
      RC.Relationship_Type__c = 'Account to Contact';
      RC.Reverse_Relationship_Category__c = RC.id;
      RC.Reversible__c = true;
      insert RC;
      
      Relationship__c objRe = new Relationship__c ();
      objRe.Account_ID__c = objAcc.id;
      objRe.Contact_ID__c = objCon.id;
     // objRe.Rev_Account_ID__c = objAcc.id;
      //objRe.Rev_Contact_ID__c = objCon.id;
      objRe.IsTrigger__c = '1';
      objRe.Relationship_Category__c = RC.id;
      objRe.Mark_for_Delete__c  = true;
      
      test.starttest();
      insert objRe;
      test.stoptest();
     
    }
     static testMethod void myTest2() {
  
      Account objAcc = new Account();
      objAcc.Name = 'test';
      insert objAcc;
      
      Contact objcon = new Contact();
      objcon.LastName = 'test';
      objcon.AccountID = objAcc.ID;
      objcon.Sex__c = 'Male';
    
      insert objcon;
      
      Relationship_Category__c RC = new Relationship_Category__c();
      RC.Name = 'Test';
      RC.Relationship_Type__c = 'Contact to Contact';
      RC.Reverse_Relationship_Category__c = RC.id;
      RC.Reversible__c = true;
      insert RC;
      
      Relationship__c objRe = new Relationship__c ();
      //objRe.Account_ID__c = objAcc.id;
      objRe.Contact_ID__c = objCon.id;
     // objRe.Rev_Account_ID__c = objAcc.id;
      objRe.Rev_Contact_ID__c = objCon.id;
      objRe.IsTrigger__c = '1';
      objRe.Relationship_Category__c = RC.id;
      objRe.Mark_for_Delete__c  = true;
      
      test.starttest();
      insert objRe;
      test.stoptest();
     
    }
    
}

 

Code Coverage Low Please Help me!

Thank you so much.

  • June 17, 2011
  • Like
  • 0

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PopulateOpportunities: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.PopulateOpportunities: line 12, column 43: []

 

trigger PopulateOpportunities on Delivery__c (before insert, before update) {
   
    //Set of SaleOrder Ids
    Set<Id> SODIDs = new Set<Id>();
            
    for (Delivery__c deliveryNew : trigger.new) {
        SODIDs.add(deliveryNew.Sales_Order__c); //A set of SaleOder 
    }        
     Map<Id, Sales_Order__c> pSale = new Map<Id, Sales_Order__c>([SELECT a.id, a.OpportunitiesID__c, a.Name,a.Quotes__c FROM Sales_Order__c a WHERE a.id IN :SODIDs]);
                                                         
    for(Delivery__c fcon : Trigger.New){
        if(pSale.get(fcon.Sales_Order__c).OpportunitiesID__c != null){
        fcon.OpportunitiesID__c = pSale.get(fcon.Sales_Order__c).OpportunitiesID__c;
        fcon.Quotes__c = pSale.get(fcon.Sales_Order__c).Quotes__c ;}
    }
    

}

 

@isTest
private class TestPopulateOpportunities {

   static testMethod void myUnitTest() {
    Account Acc = new Account(Name = 'test',Type = 'Domestic');
    insert Acc;
    Opportunities__c Opp = new Opportunities__c(Account_Name__c=Acc.id,Stage__c='Closed Won',Probability__c='100%',Unit__c='Kg',Currency__c='Bath');
    insert Opp; 
    Quotes__c Quo = new Quotes__c(OpportunitiesID__c = Opp.id);
    insert Quo;
     
      
    Sales_Order__c pSale1 = new Sales_Order__c(OpportunitiesId__c=Opp.Id,Quotes__c = Quo.id);
    insert pSale1;
    Sales_Order__c fSale1 = new Sales_Order__c(OpportunitiesId__c=Opp.Id,Quotes__c = Quo.id);
    insert fSale1;
        Delivery__c pDO1 = new Delivery__c(OpportunitiesID__c=pSale1.OpportunitiesId__c,Quotes__c =pSale1.Quotes__c );
        insert pDO1;
        Delivery__c fDO1 = new Delivery__c(OpportunitiesID__c=fSale1.OpportunitiesId__c,Quotes__c =fSale1.Quotes__c );
        insert fDO1;
                
        // TO DO: implement unit test
    }
}

 Thank you so much.


  • June 17, 2011
  • Like
  • 0

Trigger have multi Condition I can write Test Class has only 35% of you guide me !

 

 

trigger UpdateStatus on Case (Before update) {
    for(Case ca:Trigger.new){
         if(ca.New__c == False && ca.O1L__c == False && ca.O2L__c == False && ca.IP1L__c == False 
           && ca.IP2L__c == False  && ca.Reso__c == False && ca.Close__c == False && (ca.Status != 'New'))
           {          
                if(ca.Status == 'Open 1st Level')
                        {ca.new__c = true;ca.O1L__c = False; ca.O2L__c=False; ca.IP1L__c=False; ca.IP2L__c=False;  ca.Reso__c=False; ca.Cen__c=False;}   
                else if(ca.Status == 'Open 2nd Level')
                        {ca.new__c = true; ca.O1L__c = true;ca.O2L__c=False; ca.IP1L__c=False; ca.IP2L__c=False; ca.Reso__c=False; ca.Cen__c=False;}   
                else if(ca.Status == 'In Progress 1st Level')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true;}   
                else if(ca.Status == 'In Progress 2nd Level')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true;}            
                else if(ca.Status == 'Resolved')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true; ca.IP2L__c = true; }
                else if(ca.Status == 'Closed')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true; ca.IP2L__c = true;  ca.Reso__c = true;}
                else if(ca.Status == 'Cancel')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true; ca.IP2L__c = true; ca.Reso__c = true; ca.Close__c = true;}
                
         } 

         else if(ca.New__c == True && ca.O1L__c == False && ca.O2L__c == False && ca.IP1L__c == False 
         && ca.IP2L__c == False  && ca.Reso__c == False && ca.Close__c == False && (ca.Status != 'New'))
           {          
                if(ca.Status == 'Open 1st Level')
                        {ca.new__c = true;ca.O1L__c = False; ca.O2L__c=False; ca.IP1L__c=False; ca.IP2L__c=False;  ca.Reso__c=False; ca.Cen__c=False;}   
                else if(ca.Status == 'Open 2nd Level')
                        {ca.new__c = true; ca.O1L__c = true;ca.O2L__c=False; ca.IP1L__c=False; ca.IP2L__c=False; ca.Reso__c=False; ca.Cen__c=False;}   
                else if(ca.Status == 'In Progress 1st Level')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true;}   
                else if(ca.Status == 'In Progress 2nd Level')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true;}      
                else if(ca.Status == 'Resolved')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true; ca.IP2L__c = true; }
                else if(ca.Status == 'Closed')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true; ca.IP2L__c = true;  ca.Reso__c = true;}
                else if(ca.Status == 'Cancel')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true; ca.IP2L__c = true;  ca.Reso__c = true; ca.Close__c = true;}
                
         } 
        else if(ca.New__c == True && ca.O1L__c == True && ca.O2L__c == False && ca.IP1L__c == False 
           && ca.IP2L__c == False && ca.Reso__c == False && ca.Close__c == False && ((ca.Status != 'New') || (ca.Status != 'Open 1st Level')))
        {                                   
                if(ca.Status == 'Open 2nd Level')
                        {ca.new__c = true; ca.O1L__c = true;ca.O2L__c=False; ca.IP1L__c=False; ca.IP2L__c=False; ca.Reso__c=False; ca.Cen__c=False;}   
                else if(ca.Status == 'In Progress 1st Level')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true;}   
                else if(ca.Status == 'In Progress 2nd Level')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true;}          
                else if(ca.Status == 'Resolved')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true; ca.IP2L__c = true;}
                else if(ca.Status == 'Closed')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true; ca.IP2L__c = true; ca.Reso__c = true;}
                else if(ca.Status == 'Cancel')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true; ca.IP2L__c = true;  ca.Reso__c = true; ca.Close__c = true;}
                   
        }

 

@isTest
Private Class TestUpdateStatus{
    static testMethod void myTest1() {
            
            Case ca = new Case(Origin = 'Phone',Status = 'Open 1st Level',Function__c = 'CC',Type = 'Inquiry',new__c = true,O1L__c = False, O2L__c=False, IP1L__c=False, IP2L__c=False,  Reso__c=False, Cen__c=False);
            test.startTest(); 
            try{      
            insert ca;
            update ca;
            }catch(DMLException de){

        }  
            //Assert your results
            test.stopTest();
    }

   static testMethod void myTest2() {
            
            Case ca = new Case(Origin = 'Phone',Status = 'Open 2nd Level',Function__c = 'CC',Type = 'Inquiry',new__c = true,O1L__c = True);
            test.startTest();       
           try{      
            insert ca;
            update ca;
            }catch(DMLException de){

        }  
            //Assert your results
            test.stopTest();
    }

 

 

Thank you so much.

 

  • June 14, 2011
  • Like
  • 0

Not Error , but 0% CodeCoverage 

 

 

public class MassCreation{
    public List<Case> Cases {get; set;}
    
    public MassCreation(){
        Cases = new List<Case>();
        Case CaseAdd = new Case();
        
        if(Apexpages.Currentpage().getParameters().get('ID')!=null) {
            CaseAdd.ContactID = Apexpages.Currentpage().getParameters().get('id');
        }
      
        //accts.add(new Opportunities_Line_Item__c());
        Cases.add(CaseAdd);
        
    }
    public void addrow(){
        Case CaseAdd;
        if (cases.size()>0)
        {
           caseAdd=cases[cases.size()-1].clone(false, true);
        }
        else 
        {
           CaseAdd=new Case();
           if(Apexpages.Currentpage().getParameters().get('ID')!=null)    {
              CaseAdd.ContactID = Apexpages.Currentpage().getParameters().get('id');
           }
         }
         Cases.add(CaseAdd);
        //accts.add(new Opportunities_Line_Item__c());
    }
   public PageReference deleteRow() {
   if (cases.size()>1)
   {
      cases.remove(Cases.size()-1);
   }
 return null;
 }
    public PageReference save(){
        insert Cases;
        PageReference home = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        home.setRedirect(true);
        return home;
    }
    public PageReference Cancel() {
        PageReference returnPage = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        returnPage.setRedirect(true);
        return returnPage;
    }
    }

 

@isTest 
private class TestMassCreation{
    static testMethod void myTest() {
      List<Case > lstILI = new List<Case >();
      ApexPages.StandardSetController sc = new  ApexPages.StandardSetController(lstILI);
      
      
      Account objAcc = new Account();
      objAcc.Name = 'test';
      insert objAcc;
      
      Contact objcon = new Contact();
      objcon.LastName = 'test';
      objcon.AccountID = objAcc.ID;
      insert objcon;
      
      Case objca = new Case();
      objca.Origin = 'Phone';
      objca.Status = 'Closed';
      insert objca;
      
      
     
    }
}

 Thank you so much.

 

 

  • June 13, 2011
  • Like
  • 0

 

trigger LockStatus on Case (After update) {
    for(Case ca:Trigger.new){
         if(ca.New__c == True && ca.O1L__c == False && ca.O2L__c == False && ca.IP1L__c == False 
           && ca.IP2L__c == False  && ca.Reso__c == False && ca.Close__c == False && (ca.Status == 'New')){
            Trigger.new[0].Status.addError('Can not choose less than Open 1st Level');  // Open 1st Level
        } 
        else if(ca.New__c == True && ca.O1L__c == True && ca.O2L__c == False && ca.IP1L__c == False 
           && ca.IP2L__c == False  && ca.Reso__c == False && ca.Close__c == False && ((ca.Status == 'New') || (ca.Status == 'Open 1st Level'))){
            Trigger.new[0].Status.addError('Can not choose less than Open 2nd Level');  // Open 2nd Level
        }
        else if(ca.New__c == True && ca.O1L__c == True && ca.O2L__c == True && ca.IP1L__c == False 
           && ca.IP2L__c == False  && ca.Reso__c == False && ca.Close__c == False && ((ca.Status == 'New') || (ca.Status == 'Open 1st Level') || (ca.Status == 'Open 2nd Level')) ){
            Trigger.new[0].Status.addError('Can not choose less than In Progress 1st Level'); //In Progress 1st Level
        }
        else if(ca.New__c == True && ca.O1L__c == True && ca.O2L__c == True && ca.IP1L__c == True 
           && ca.IP2L__c == False  && ca.Reso__c == False && ca.Close__c == False && ((ca.Status == 'New') || (ca.Status == 'Open 1st Level') || (ca.Status == 'Open 2nd Level') || (ca.Status == 'In Progress 1st Level'))){
            Trigger.new[0].Status.addError('Can not choose less than In Progress 2nd Level'); //In Progress 2nd Level
        }
        else if(ca.New__c == True && ca.O1L__c == True && ca.O2L__c == True && ca.IP1L__c == True 
           && ca.IP2L__c == True  && ca.Reso__c == False && ca.Close__c == False && ((ca.Status == 'New') || (ca.Status == 'Open 1st Level') || (ca.Status == 'Open 2nd Level') || (ca.Status == 'In Progress 1st Level') || (ca.Status == 'In Progress 2nd Level'))){
            Trigger.new[0].Status.addError('Can not choose less than Resolved'); //Resolved
        }
        else if(ca.New__c == True && ca.O1L__c == True && ca.O2L__c == True && ca.IP1L__c == True 
           && ca.IP2L__c == True  && ca.Reso__c == True && ca.Close__c == False && ((ca.Status == 'New') || (ca.Status == 'Open 1st Level') || (ca.Status == 'Open 2nd Level') || (ca.Status == 'In Progress 1st Level') || (ca.Status == 'In Progress 2nd Level') || (ca.Status == 'Resolved'))){
            Trigger.new[0].Status.addError('Can not choose less than Closed'); //Closed
        }
        else if(ca.New__c == True && ca.O1L__c == True && ca.O2L__c == True && ca.IP1L__c == True 
           && ca.IP2L__c == True  && ca.Reso__c == True && ca.Close__c == True && ((ca.Status == 'New') || (ca.Status == 'Open 1st Level') || (ca.Status == 'Open 2nd Level') || (ca.Status == 'In Progress 1st Level') || (ca.Status == 'In Progress 2nd Level')  || (ca.Status == 'Resolved') || (ca.Status == 'Closed'))){
            Trigger.new[0].Status.addError('Can not choose less than Cancle'); //Cancel
        }
}
}

 

@isTest
private class TestLockStatus  {
   static testMethod void myUnitTest() {   
      Case ca = new Case(Origin = 'Phone',Status = 'New',Subject = 'A',Type = 'Dummy',New__c = true,O1L__c = False,O2L__c = False,IP1L__c = False,
      IP2L__c = False,Reso__c = False,Close__c = False);
      test.startTest();
             try {      insert ca; update ca;    }
                 catch (Exception e) {                
                        System.debug('Can not choose less than Open 1st Level'); 
                    } 
       test.stopTest();  
     }

 Thank you so much.

 

  • June 13, 2011
  • Like
  • 0

CodeCoverage 50%. I want more 75 % 

 

 

trigger PopAccount on Case (before insert,before update) {
    for(Case ca : trigger.new){   
    if(ca.AccountID == null && ca.Account_Number__c != null){
        Account acc = [select id,AccountNumber From Account Where AccountNumber  =: ca.Account_Number__c];
        ca.AccountID = acc.id;  
        }
    }
}

 

@isTest 
private class TestPopAccount{
    static testMethod void myTest() {
    
        
          
        Account Acc = new Account();
        Acc.Name = 'test'; 
        insert Acc;
        
        Acc = [select id,AccountNumber,Type From Account Where id =: acc.id];
        
        
        Contact con = new Contact();
        Con.AccountID = Acc.id;
        Con.LastName = 'Test';
        insert con;
        
        Case ca = new Case();
        ca.Account_Number__c  = '000001';
        ca.AccountID = Acc.id;
        ca.ContactID = con.id;
        ca.Origin = 'Phone';
        ca.Status = 'Closed';
        insert ca;
        update ca;

 Thank you so much.

 

 

  • June 11, 2011
  • Like
  • 0

I can not save because the Field Subject in Interaction Log is  Required. I want to have some unRequiredit.

 

 

trigger PopSubject on Task (before insert) {
   
    //Set of SaleOrder Ids
    Set<Id> CaseID = new Set<Id>();
            
    for (Task Ta : trigger.new) {
        CaseID.add(Ta.WhatID); //A set of SaleOder 
    }        
     Map<Id, Case> pSale = new Map<Id, Case>([SELECT a.id, a.subject FROM Case a WHERE a.id IN :CaseID ]);
                                                         
    for(Task fcon : Trigger.New){
        fcon.subject  = pSale.get(fcon.WhatID).subject;
    }
    

}

 Thank you so much.

 

 

  • June 03, 2011
  • Like
  • 0

I would like to add time. Do not count holidays.

 

Date + 4 day if Start Thursday Ended Tures. Thursday  Friday Saturday Sunday Monday Tues. 

Do you have guide me.

 

Thank you so much.

  • June 03, 2011
  • Like
  • 0

Average Code Low . I can update Average Code?

 

 

trigger SumSodcSync on Sales_Order_Complete__c(Before insert) {
for(Sales_Order_Complete__c sodc:trigger.new){
      
        Sales_Order__c  Sod = [Select id from Sales_Order__c Where id = : ApexPages.currentPage().getParameters().get('id')];
        
        Sales_Order_Complete__c[] Scom = [Select id,OpportunitiesID__c ,DimensionTxWxL__c,Grade__c,Total_Weight__c,Quotes__c,
        Fail__c, Name, Products__c, Quantity__c,Quantity_Remain__c,Sales_OrderID__c,Success__c,Date__c,Pop__c,
        Sales_Order_Line_ItemID__c,Deliver_Remain__c,Delivery_Good_Pcs__c,Order_Quantity__c,Total_Finished_Good__c ,
        Delivery_Good_Ton__c,Delivery_Remain_Ton__c,Finished_Good_Remain__c,Finished_Good_Remain_Ton__c,Finished_Tons__c 
        from Sales_Order_Complete__c where Sales_OrderID__c  =: Sod.id And Pop__c != true ];
            
            Sodc_Sumary__c[] objssc = new Sodc_Sumary__c[]{};
            Sodc_Sumary__c Sc = new Sodc_Sumary__c();
      
                for(Sales_Order_Complete__c Ssc: Scom ){
                
                Sc = new Sodc_Sumary__c();
                Sc.Sales_Order__c = Ssc.Sales_OrderID__c;
                Sc.Dimen__c = Ssc.DimensionTxWxL__c;
                Sc.Grade__c = Ssc.Grade__c;
                Sc.Order_Status__c = Ssc.Id;
                Sc.Name = Ssc.Name;
                Sc.Finished_Good_Remain__c = Ssc.Finished_Good_Remain__c;
                Sc.Finished_Good_Remain_Ton__c = Ssc.Finished_Good_Remain_Ton__c;
                Sc.Deliver_Remain__c= Ssc.Deliver_Remain__c;
                Sc.Delivery_Remain_Ton__c = Ssc.Delivery_Remain_Ton__c;
                Sc.Quantity__c = Ssc.Order_Quantity__c;
                
                objssc.add(Sc); 
                }
                insert objssc; 
        
    }
}

 

 

@isTest
private class TestSumSodcSync {
 static testMethod void myUnitTest() {    
                Account Acc = New Account(Name = 'test',Type='Partner');
                insert Acc;
                Opportunities__c Opp = new Opportunities__c(Account_Name__c = Acc.ID,Stage__c = 'Negotiation',Probability__c ='60%',Unit__c ='Ton');
                insert Opp;
                Opportunities_Line_Item__c OppL = new Opportunities_Line_Item__c(OpportunitiesID__c = Opp.id);
                insert OppL;
                Quotes__c N = new Quotes__c(OpportunitiesID__c=Opp.id,Account_Name__c = Acc.id);
                insert N;    
                Quotes_Line_Item__c QL = new Quotes_Line_Item__c(QuotesID__c = N.id,Opportunities_Line_Item__c = OppL.id);
                insert QL;
                Sales_Order__c Sod = new Sales_Order__c(Quotes__c = N.id);
                insert Sod;
                Sales_Order_Line_Item__c SoL = new Sales_Order_Line_Item__c(Sales_OrderID__c = Sod.id);
                insert SoL;
                Sales_Order_Complete__c Sodc = new Sales_Order_Complete__c(Sales_OrderID__c = Sod.id,OpportunitiesID__c = Opp.id,Quotes__c = N.id,Sales_Order_Line_ItemID__c = SoL.id);
                insert Sodc;
                Sodc_Sumary__c Sos = new Sodc_Sumary__c(Order_Status__c = Sodc.id,Sales_Order__c = Sod.id);
                insert Sos;

              
  }                 
}

 

Thank you so much.

 

 

  • May 24, 2011
  • Like
  • 0

I can't copy data from the first record to secord Record when AddRow. 


 

 

public class MassCreatetion{
    public List<Case> Cases {get; set;}
    
    public MassCreatetion(){
        Cases = new List<Case>();
        Case CaseAdd = new Case();
        
        if(Apexpages.Currentpage().getParameters().get('ID')!=null) {
            CaseAdd.ContactID = (id)Apexpages.Currentpage().getParameters().get('id');
        }
      
        //accts.add(new Opportunities_Line_Item__c());
        Cases.add(CaseAdd);
        
    }
    public void addrow(){
        Case CaseAdd = new Case();
        
        if(Apexpages.Currentpage().getParameters().get('ID')!=null) {
            CaseAdd.ContactID = (id)Apexpages.Currentpage().getParameters().get('id');
        }
         Cases.add(CaseAdd);
        //accts.add(new Opportunities_Line_Item__c());
    }
   public PageReference deleteRow() {
   if (cases.size()>1)
   {
      cases.remove(Cases.size()-1);
   }
 return null;
 }
    public PageReference save(){
        insert Cases;
        PageReference home = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        home.setRedirect(true);
        return home;
    }
    public PageReference Cancel() {
        PageReference returnPage = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        returnPage.setRedirect(true);
        return returnPage;
    }
    }

 

Thank you so much.

  • May 24, 2011
  • Like
  • 0

one error is null id after insert

 

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PopAccounttoPayment: execution of AfterInsert caused by: System.StringException: Invalid id: Trigger.PopAccounttoPayment: line 16, column 42: 

 

trigger PopAccounttoPayment on Payment_Line__c (after insert) {
set<ID> setInvID = new set<ID>();

        for(Payment_Line__c Pml : trigger.new){
                if(Pml.Invoice_BC__c != null || Pml.Invoice_BC__c != ''){
                        setInvID.Add(Pml.Invoice_BC__c);
                }
        }   
        
        Invoice_BC__c InvBC = new Invoice_BC__c();
        List<Invoice_BC__c> lstInvBC = [Select id,AccountID__c from Invoice_BC__c Where id in : setInvID];
            if(lstInvBC.size() != 0){
                InvBC = lstInvBC[0];
            }   
        if(InvBC.AccountID__c != null && InvBC.AccountID__c != ''){  
            Payment_Line__c pml = Trigger.new[0];   
            List<Payments__c> lstPm = new List<Payments__c>();
            Payments__c Pm = new Payments__c(id = pml.DocNo__c);
            Pm.AccountID__c = InvBC.AccountID__c;
            lstPm.Add(Pm);
        
            Update lstPm;
        }
}

 Test class

@isTest 
private class TestPopAccounttoPayment{
    static testMethod void myTest() {
    
      Account objAcc = new Account();
      objAcc.Name = 'test';
      insert objAcc;
        
      Opportunities__c objOpp = new Opportunities__c();
      objOpp.Account_Name__c = objAcc.Id;
      insert objOpp;
           
      Quotes__c objQuo = new Quotes__c();
      objQuo.Account_Name__c = objAcc.Id;
      objQuo.OpportunitiesID__c = objOpp.Id;
      insert objQuo;
                
      Sales_Order__c  objSOD = new Sales_Order__c();
      objSOD.Name = 'test4';
      objSOD.OpportunitiesID__c = objOpp.Id;
      objSOD.Quotes__c = objQuo.Id;
      insert objSOD;
      
      Invoice_BC__c  objInvBc = new Invoice_BC__c();
      objInvBc.Name = 'Test5';
      objInvBc.Sales_OrderID__c = objSOD.id;
      objInvBc.AccountID__c = objAcc.id;
      insert objInvBc;
      
      Payments__c objPay = new Payments__c();
      objPay.Name = 'Test2';
      objPay.Due_Date__c = System.Today();
      objPay.AccountID__c = objInvBc.AccountID__c;
      insert objPay;
      
      Test.StartTest();
      Payment_Line__c objPayLine = new Payment_Line__c();
      ApexPages.currentPage().getParameters().put('id', objPay.id);
      objPayLine.Name = 'Test3';
      objPayLine.DocNo__c = objPay.id;
      objPayLine.Invoice_BC__c = objInvBc.id;
      insert objPayLine;
           
      Payments__c objPay2 = new Payments__c();
      ApexPages.currentPage().getParameters().put('id', objPayLine.DocNo__c);
      objPay2.Name = 'Test2';
      objPay2.Due_Date__c = System.Today();
      objPay2.AccountID__c = objInvBc.AccountID__c;
      insert objPay2;
      update objPay2;
      Test.StopTest();
    
    }
}

 thank you so much

public class MarkDeleteAccount{

 public MarkDeleteAccount(ApexPages.StandardController controller) {
    Acc = new Account(id = Apexpages.Currentpage().getParameters().get('id'));
        Acc.Mark_for_Delete__c = true;
        
  
  }
  
Public Account Acc {get;set;}
    
    public PageReference save(){     
       update Acc;
        PageReference returnPage = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        returnPage.setRedirect(true);
        return returnPage;
        
    
    }
    public PageReference Cancel() {
        PageReference returnPage = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        returnPage.setRedirect(true);
        return returnPage;
        
    }
  
    }

 

@isTest 
    private  class TestMarkDeleteAccount{
    static testMethod void myTest1() {
    
      List<Account> lstAcc = new List<Account>();
      ApexPages.StandardSetController sc = new  ApexPages.StandardSetController(lstAcc);
      
      Account  Acc = new Account();
      Acc.Name = 'Test Acc1';
      Acc.BP_Type__c = 'SCCC Mason';
      Acc.Mark_for_Delete__c = true;
      insert Acc;
      update Acc;
      ApexPages.currentPage().getParameters().put('id', Acc.Id); 
      Test.StartTest();
      sc.Save();
      sc.Cancel();
      Test.StopTest(); 
    }    
    
   
}

Test Class is 0% CodeCoverage. I can not make an error. 

Thank you.

  • July 20, 2011
  • Like
  • 0

System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []

 

rigger trgLookupSLAValues on Case (after insert) {

    for(Case caseArgs : Trigger.new) {
    
        List<Case_Master__c> caseMasters = [select Text_Note__c,Case_Escalation_To__c,Queue_Name__c, 
        Type__c,Priority__c, Function__c, SLA_Time_Hours__c, Status__c from Case_Master__c 
        where Case_Category__c =: caseArgs.Case_Category__c and Sub_Category__c =:caseArgs.Sub_Category__c 
        and Description__c =: caseArgs.Description__c and Customer_Class__c =: caseArgs.Customer_Class__c ];

        if(caseMasters.IsEmpty()) {
            RelationMgrException ex = new RelationMgrException('Cannot find Case Master record');
            throw ex;
        }
        else {
        
        
        Case_Master__c caseMasterTemp = caseMasters.get(0);
        
        Case caseNew = new Case(Id=caseArgs.Id);
        caseNew.OwnerId = caseMasterTemp.Case_Escalation_To__c;
        caseNew.Function__c = caseMasterTemp.Function__c;
        caseNew.Priority = caseMasterTemp.Priority__c;
        caseNew.SLATimeHours__c = caseMasterTemp.SLA_Time_Hours__c;
        caseNew.Text_Note__c = caseMasterTemp.Text_Note__c;
        caseNew.Status = caseMasterTemp.Status__c;
        caseNew.Type = caseMasterTemp.Type__c;
        
        update caseNew ;
        }
        
      
    }
  
}

 



@isTest 
private class TesttrgLookupSLAValues{
    static testMethod void TestMethodtrgLookupSLAValues() {
      
     Account Acc = new Account();
        Acc.Name = 'test1'; 
        Acc.AccountNumber = '000001';
        Acc.CustomerPriority__c = 'Platinum';       
        insert Acc;
        

    Case_Master__c CM = new Case_Master__c();
         CM.Text_Note__c = ' test ';
         CM.Case_Category__c ='Z - Customer Solution';
         CM.Sub_Category__c ='CSD - Price and Policy';
         CM.Description__c ='Complaint about price and policy';
         CM.Customer_Class__c ='Complaint about price and policy';       
    insert CM;
    
     Case ca = new Case();
        ca.AccountID = Acc.Id;
        ca.Origin = 'Web';
        ca.Status = 'Open 1st Level';
        ca.Type = 'Inquiry';
        ca.Multi_Account__c = true;
        ca.Case_Category__c = 'Z - Customer Solution';
        ca.Sub_Category__c = 'CSD - Open New Ship to';
        ca.Description__c = 'Request add new ship to';
    update ca;
    
    }

    
}

 

Thank you so much.

  • June 26, 2011
  • Like
  • 0

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PopulateOpportunities: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.PopulateOpportunities: line 12, column 43: []

 

trigger PopulateOpportunities on Delivery__c (before insert, before update) {
   
    //Set of SaleOrder Ids
    Set<Id> SODIDs = new Set<Id>();
            
    for (Delivery__c deliveryNew : trigger.new) {
        SODIDs.add(deliveryNew.Sales_Order__c); //A set of SaleOder 
    }        
     Map<Id, Sales_Order__c> pSale = new Map<Id, Sales_Order__c>([SELECT a.id, a.OpportunitiesID__c, a.Name,a.Quotes__c FROM Sales_Order__c a WHERE a.id IN :SODIDs]);
                                                         
    for(Delivery__c fcon : Trigger.New){
        if(pSale.get(fcon.Sales_Order__c).OpportunitiesID__c != null){
        fcon.OpportunitiesID__c = pSale.get(fcon.Sales_Order__c).OpportunitiesID__c;
        fcon.Quotes__c = pSale.get(fcon.Sales_Order__c).Quotes__c ;}
    }
    

}

 

@isTest
private class TestPopulateOpportunities {

   static testMethod void myUnitTest() {
    Account Acc = new Account(Name = 'test',Type = 'Domestic');
    insert Acc;
    Opportunities__c Opp = new Opportunities__c(Account_Name__c=Acc.id,Stage__c='Closed Won',Probability__c='100%',Unit__c='Kg',Currency__c='Bath');
    insert Opp; 
    Quotes__c Quo = new Quotes__c(OpportunitiesID__c = Opp.id);
    insert Quo;
     
      
    Sales_Order__c pSale1 = new Sales_Order__c(OpportunitiesId__c=Opp.Id,Quotes__c = Quo.id);
    insert pSale1;
    Sales_Order__c fSale1 = new Sales_Order__c(OpportunitiesId__c=Opp.Id,Quotes__c = Quo.id);
    insert fSale1;
        Delivery__c pDO1 = new Delivery__c(OpportunitiesID__c=pSale1.OpportunitiesId__c,Quotes__c =pSale1.Quotes__c );
        insert pDO1;
        Delivery__c fDO1 = new Delivery__c(OpportunitiesID__c=fSale1.OpportunitiesId__c,Quotes__c =fSale1.Quotes__c );
        insert fDO1;
                
        // TO DO: implement unit test
    }
}

 Thank you so much.


  • June 17, 2011
  • Like
  • 0

Not Error , but 0% CodeCoverage 

 

 

public class MassCreation{
    public List<Case> Cases {get; set;}
    
    public MassCreation(){
        Cases = new List<Case>();
        Case CaseAdd = new Case();
        
        if(Apexpages.Currentpage().getParameters().get('ID')!=null) {
            CaseAdd.ContactID = Apexpages.Currentpage().getParameters().get('id');
        }
      
        //accts.add(new Opportunities_Line_Item__c());
        Cases.add(CaseAdd);
        
    }
    public void addrow(){
        Case CaseAdd;
        if (cases.size()>0)
        {
           caseAdd=cases[cases.size()-1].clone(false, true);
        }
        else 
        {
           CaseAdd=new Case();
           if(Apexpages.Currentpage().getParameters().get('ID')!=null)    {
              CaseAdd.ContactID = Apexpages.Currentpage().getParameters().get('id');
           }
         }
         Cases.add(CaseAdd);
        //accts.add(new Opportunities_Line_Item__c());
    }
   public PageReference deleteRow() {
   if (cases.size()>1)
   {
      cases.remove(Cases.size()-1);
   }
 return null;
 }
    public PageReference save(){
        insert Cases;
        PageReference home = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        home.setRedirect(true);
        return home;
    }
    public PageReference Cancel() {
        PageReference returnPage = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        returnPage.setRedirect(true);
        return returnPage;
    }
    }

 

@isTest 
private class TestMassCreation{
    static testMethod void myTest() {
      List<Case > lstILI = new List<Case >();
      ApexPages.StandardSetController sc = new  ApexPages.StandardSetController(lstILI);
      
      
      Account objAcc = new Account();
      objAcc.Name = 'test';
      insert objAcc;
      
      Contact objcon = new Contact();
      objcon.LastName = 'test';
      objcon.AccountID = objAcc.ID;
      insert objcon;
      
      Case objca = new Case();
      objca.Origin = 'Phone';
      objca.Status = 'Closed';
      insert objca;
      
      
     
    }
}

 Thank you so much.

 

 

  • June 13, 2011
  • Like
  • 0

CodeCoverage 50%. I want more 75 % 

 

 

trigger PopAccount on Case (before insert,before update) {
    for(Case ca : trigger.new){   
    if(ca.AccountID == null && ca.Account_Number__c != null){
        Account acc = [select id,AccountNumber From Account Where AccountNumber  =: ca.Account_Number__c];
        ca.AccountID = acc.id;  
        }
    }
}

 

@isTest 
private class TestPopAccount{
    static testMethod void myTest() {
    
        
          
        Account Acc = new Account();
        Acc.Name = 'test'; 
        insert Acc;
        
        Acc = [select id,AccountNumber,Type From Account Where id =: acc.id];
        
        
        Contact con = new Contact();
        Con.AccountID = Acc.id;
        Con.LastName = 'Test';
        insert con;
        
        Case ca = new Case();
        ca.Account_Number__c  = '000001';
        ca.AccountID = Acc.id;
        ca.ContactID = con.id;
        ca.Origin = 'Phone';
        ca.Status = 'Closed';
        insert ca;
        update ca;

 Thank you so much.

 

 

  • June 11, 2011
  • Like
  • 0

I can't copy data from the first record to secord Record when AddRow. 


 

 

public class MassCreatetion{
    public List<Case> Cases {get; set;}
    
    public MassCreatetion(){
        Cases = new List<Case>();
        Case CaseAdd = new Case();
        
        if(Apexpages.Currentpage().getParameters().get('ID')!=null) {
            CaseAdd.ContactID = (id)Apexpages.Currentpage().getParameters().get('id');
        }
      
        //accts.add(new Opportunities_Line_Item__c());
        Cases.add(CaseAdd);
        
    }
    public void addrow(){
        Case CaseAdd = new Case();
        
        if(Apexpages.Currentpage().getParameters().get('ID')!=null) {
            CaseAdd.ContactID = (id)Apexpages.Currentpage().getParameters().get('id');
        }
         Cases.add(CaseAdd);
        //accts.add(new Opportunities_Line_Item__c());
    }
   public PageReference deleteRow() {
   if (cases.size()>1)
   {
      cases.remove(Cases.size()-1);
   }
 return null;
 }
    public PageReference save(){
        insert Cases;
        PageReference home = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        home.setRedirect(true);
        return home;
    }
    public PageReference Cancel() {
        PageReference returnPage = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        returnPage.setRedirect(true);
        return returnPage;
    }
    }

 

Thank you so much.

  • May 24, 2011
  • Like
  • 0

 

trigger PopWebCasetoField on Case(before insert)
{
For (Case c : Trigger.new){
        if(c.Origin == 'Web'{
        c.ContactID = c.Email_Description__c;     
        }
}
}

 

 

I can't pop data because Type not macth.

ContacctID Type Lookup and Email Des Type Text;

Please help me.

 

Thank you so much.

  • May 19, 2011
  • Like
  • 0

System.LimitException: Too many SOQL queries: 101 

 

Trigger.UpdateQLine: line 4, column 44

 

 

trigger UpdateQLine on Quotes_Line_Item__c (after update) {
    for(Quotes_Line_Item__c QL:trigger.new){
    if(QL.isClosed__c == false){
        Opportunities_Line_Item__c[] OPL = [Select Id ,UP1__c,Quantity__c from Opportunities_Line_Item__c Where Id =: QL.Opportunities_Line_Item__c Limit 1000];
        for(Opportunities_Line_Item__c OL:OPL){
        OL.Quantity__c = QL.Quantity__c;
        OL.UP1__c = QL.Unit_Price_For__c;
        }
        update OPL;
        }
    }
}

 

 

  • May 16, 2011
  • Like
  • 0

I can not use the Field Autonumber Standard. because it was not Run 1,2,3,4. but it runs from Old LineItem  when creating New Lineitem.

 

Item API = Name

 

 

public class NewAddProducts{

    public List<Opportunities_Line_Item__c> accts {get; set;}
    
    public NewAddProducts(){
        accts = new List<Opportunities_Line_Item__c>();
        Opportunities_Line_Item__c opplineitem = new Opportunities_Line_Item__c();
        
        if(Apexpages.Currentpage().getParameters().get('ID')!=null) {
            opplineitem.OpportunitiesID__c = Apexpages.Currentpage().getParameters().get('ID');
            }
        
        //accts.add(new Opportunities_Line_Item__c());
        accts.add(opplineitem);
        
    }
    
    public void addrow(){
        Opportunities_Line_Item__c opplineitem = new Opportunities_Line_Item__c();
        
        if(Apexpages.Currentpage().getParameters().get('ID')!=null) {
            opplineitem.OpportunitiesID__c = Apexpages.Currentpage().getParameters().get('ID');
        }
         accts.add(opplineitem);
        //accts.add(new Opportunities_Line_Item__c());
    }
   public PageReference deleteRow() {
   if (accts.size()>1)
   {
      accts.remove(accts.size()-1);
   }
 return null;
 }
    public PageReference save(){
        insert accts;
        PageReference home = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        home.setRedirect(true);
        return home;
    }
 public PageReference Cancel() {
        PageReference returnPage = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        returnPage.setRedirect(true);
        return returnPage;
    }
    }

 

 

Thank you so much

  • May 11, 2011
  • Like
  • 0

I want copy data from Web-to-case field SuppliedCompany put in Account_Name__c. But it's error!.

 Error: Invalid Data.

 Review all error messages below to correct your data.

 Apex trigger UpdateType caused an unexpected exception, contact your administrator: UpdateType: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.UpdateType: line 5, column 127

 

 

trigger UpdateType on Case(after insert,after update) {
    for(Case C:trigger.new){
    
    if(C.Origin == 'Web'){
        Case[] CA = [Select Id,SuppliedCompany,SuppliedEmail,SuppliedName,SuppliedPhone,Account_Name__c from Case Where id = :ApexPages.currentPage().getParameters().get('id') ];
        for(Case Cased:CA){
        //Cased.Contact= C.SuppliedName;
        Cased.Account_Name__c = C.SuppliedCompany;
        //Cased.ContactEmail = C.SuppliedEmail;
        //Cased.ContactPhone = C.SuppliedPhone;
        }
        insert CA;
        update CA;
        }  
        }
    }

 

 

I want copy data from Web-to-case field SuppliedName type Text put in Case.Contact type lookup field. But error!  

Error: Compile Error: Illegal assignment from String to SOBJECT:Contact at line 7 column 9 Cased.Contact= C.SuppliedName;

 

 

Cased.Contact= C.SuppliedName;

 

 

Thank you so much.

  • May 10, 2011
  • Like
  • 0

Code Coverage 18% 

 

 

trigger UpdateType on Quotes__c (after update) {
    for(Quotes__c Q:trigger.new){
    
    if(Q.Status__c== 'Rejected'){
        Opportunities__c[] OP = [Select Id,name,Stage__c from Opportunities__c Where Id =: Q.OpportunitiesID__c];
        for(Opportunities__c O:OP){
        O.Stage__c = 'Closed Lost';
        O.Reason_for_Lost__c = 'Please input Data';
        }
         update OP;
        }
    else if(Q.Status__c== 'Accepted'){
        Opportunities__c[] OPP = [Select Id,name,Stage__c from Opportunities__c Where Id =: Q.OpportunitiesID__c];
        for(Opportunities__c OA:OPP){
        OA.Stage__c = 'Closed Won';
        }
        update OPP;
        }        
        }
    }

 Test

 

@isTest
private class TestUpdateType{

   static testMethod void myUnitTest() {
        Account Acc = new Account(Name='test');
        insert Acc;
        Opportunities__c O = new Opportunities__c(Account_Name__c=Acc.Id,Stage__c='Prospecting',Probability__c='10%',Unit__c = 'Kg',Currency__c = 'Bath',Reason_for_Lost__c ='Test');
        insert O;
        
        Quotes__c Q = new Quotes__c(OpportunitiesID__c=O.Id);
        insert Q;
   
    } 
}

 

 

Thank you so much.

 

  • May 06, 2011
  • Like
  • 0

Hey,

I created the AddRow () Function. but I can not delete a Record.

 

 

 

public class NewAddProducts{
    public List<Case> Cases {get; set;}
    
    public NewAddProducts(){
        Cases = new List<Case>();
        Case CaseAdd = new Case();
        
        if(Apexpages.Currentpage().getParameters().get('ID')!=null) {
            CaseAdd.Contacts__c = Apexpages.Currentpage().getParameters().get('id');
        }
      
        //accts.add(new Opportunities_Line_Item__c());
        Cases.add(CaseAdd);
        
    }
    public void addrow(){
        Case CaseAdd = new Case();
        
        if(Apexpages.Currentpage().getParameters().get('ID')!=null) {
            CaseAdd.Contacts__c = Apexpages.Currentpage().getParameters().get('id');
        }
         Cases.add(CaseAdd);
        //accts.add(new Opportunities_Line_Item__c());
    }
   
    public PageReference save(){
        insert Cases;
        PageReference home = new PageReference('/' +    ApexPages.currentPage().getParameters().get('id'));
        home.setRedirect(true);
        return home;
    }
    public PageReference Cancel() {
        PageReference returnPage = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        returnPage.setRedirect(true);
        return returnPage;
    }
    }

 

And I can not come available Standard Field.

Standard Object : Case

Standard Field Name : Contact

Type : Lookup

Error: Compile Error: Illegal assignment from String to SOBJECT:Contact at line 9 column 13

 

 

public class NewAddProducts{
    public List<Case> Cases {get; set;}
    
    public NewAddProducts(){
        Cases = new List<Case>();
        Case CaseAdd = new Case();
        
        if(Apexpages.Currentpage().getParameters().get('ID')!=null) {
            CaseAdd.Contact = Apexpages.Currentpage().getParameters().get('id');
        }
      
        //accts.add(new Opportunities_Line_Item__c());
        Cases.add(CaseAdd);
        
    }
    public void addrow(){
        Case CaseAdd = new Case();
        
        if(Apexpages.Currentpage().getParameters().get('ID')!=null) {
            CaseAdd.Contact = Apexpages.Currentpage().getParameters().get('id');
        }
         Cases.add(CaseAdd);
        //accts.add(new Opportunities_Line_Item__c());
    }
   
    public PageReference save(){
        insert Cases;
        PageReference home = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        home.setRedirect(true);
        return home;
    }
    public PageReference Cancel() {
        PageReference returnPage = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        returnPage.setRedirect(true);
        return returnPage;
    }
    }

 

 

I hope you will help me.

Thank you.

  • May 05, 2011
  • Like
  • 0