• riojohn
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
trigger Trg_IntegrityIndex on Project__c (before update) {
    
    for(Project__c P : Trigger.New){
        String PID = p.Id;
        Project__c P1=[select Id,Name,Status__r.Name, Value__c, ContractValue__c, Contract__r.Name, Country__c, Workflow__c, CreatedDate,Scope__c  from Project__c where Id=:PID];
        
        string Status =P1.Status__r.Name;
        String sContract =P1.Contract__r.Name;
        String sContractValue =String.Valueof(P.ContractValue__c);
        String sScope =String.valueof(P.Scope__c);
        String sIndustry=P.Industry__c;
        String sName=P.Name; //for Project name
        String sScopeReplace;
        Integer iScope =0;
        
        Boolean bBad=false;
        Boolean bFair=false;
        String sErrorComments='';
  List<News__c> News= [select Id,Date__c,Name from News__c where Project__c=:PID];
        if (News.Size() >0){
              for(News__c N :News){
              //Validation 8: News:News-Study    Should be within 90 days from today   except design build in contract type             
                if(Status=='Study' &&  !(sContract=='Design Build (DB)')){
                  if(N.Date__c > date.today() +90 && N.Date__c < date.today() +97){
                    bFair = True; 
                    sErrorComments +='Status-Study Should be within 90 days from today for News Record-' + N.Name + '\r\n'; 
                  }else if (N.Date__c > date.today() +97){
                    bBad= True; 
                    sErrorComments +='Status Study as exceeded 97 days from today for News Record-' + N.Name + '\r\n';                                         
                  } 
               } 
i wrote test class below i dont know what is wrong in this can anyone have solutions for this . Kindly help me.

@isTest 
Public class testIntegrity{
    public static void init()
    {
        List <Project__c> proj = New List<Project__c>();
        Public Static String PID = p.Id;
        Project__c sproj=[select Id,Name,Status__r.Name, Value__c, ContractValue__c, Contract__r.Name, Country__c, Workflow__c, CreatedDate,Scope__c  from Project__c where Id=:PID];
        Public Static String Status = sproj.Status__r.Name;
        Public Static String sContract =sproj.Contract__r.Name;
        Public Static String sContractValue =String.Valueof(sproj.ContractValue__c);
        
    }
    
    
@isTest Static void testinsertproject()
    {
        
        Project__c sproj = New Project__c();
        sproj.Parent__c = 'a042000000IPjwg';
        sproj.Name ='Abu Dhabi Commercial Bank - Office Building';
        sproj.Type__c='a0I200000064HgY';
        sproj.Type_MCI__c='a0I200000064HgY';
        sproj.Location__c ='a0I20000006hEdO';
        sproj.Workflow__c = 'Recalled';
        sproj.Status__r.Name = 'Study';
        sproj.Inactive__c=true;
        sproj.Value__c=400;
        sproj.Integrity_Errors__c='Scope Should be more than 5 Pointers for the Status :Design';
        sproj.ContractValue__c=40;
        sproj.Contract__r.Name='Design Build (DB)';
        //sproj.Contract_Type_MCI__c='Build';
        sproj.Scope__c='Abu Dhabi Commercial Bank is constructing an office building in Abu Dhabi.\n\nScope of the project includes:\n*Office building (12-storey)\n*Associated facilities';
        sproj.Brownfield__c=false;
        sproj.Offshore__c=false;
        insert sproj;
        
        
        News__c sobj = New News__c();
        sobj.Inactive__c = false;
        sobj.News__c = 'fsfsfdsgsddsf';
        sobj.Date__c = Date.valueOf('20-10-2017');
        sobj.Source_Type__c ='Primary';
        sobj.Number_of_Updates__c ='2';
        sobj.Project__c = sobj.Id;
        insert sobj;
        
        
        if(sproj.Status__c =='Study' && !(sproj.Contract__c=='Design Build (DB)'))
        {
            String spro = String.valueof(sproj.Id);
            if(sobj.Date__c>date.today() +90 && sobj.Date__c<date.today() +97 )
            {
                
            }
            else if(sobj.Date__c > date.today()+97)
            {
               //do nothing 
            }
                
        }
    
        }
    
}

Thanks