• 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 
I had a requirement where i need to create records based on the Campaign Members in the Opportunity.i had done the trigger and the code was working fine but today i had an error .Can anyone help me out !
Error:Apex trigger CreateList caused an unexpected exception, contact your administrator: CreateList: execution of AfterUpdate caused by: System.DmlException: Insert failed. First exception on row 0 with id 0062800000CMrpPAAT; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]: Trigger.CreateList: line 34, column 1
trigger CreateList on Campaign (after insert) {
     List<Opportunity> opp = new List<Opportunity>();
    List <OpportunityContactRole> ocrole = new List<OpportunityContactRole>();
     public integer iOPPCount {get; set;}
    public integer icount {get; set;}
    
    
 for( Campaign camp : trigger.new ){
     if( camp.Create_List__c == True ){
             String sCamp= String.valueof(camp.id);
             iOPPCount  = [SELECT count() FROM CampaignMember WHERE CampaignId =:sCamp];
             if (iOPPCount  > 0 ){                
                // camp.addError(String.Valueof(iOPPCount));
                 List<CampaignMember> camps = [SELECT id,FirstName,LastName,CompanyOrAccount,ContactId FROM CampaignMember WHERE CampaignId =:sCamp];            
                 
                 for(CampaignMember CM : camps){
                     String sEvent = String.valueof(camp.EventIDName__c);
                     String sName = String.valueof(CM.FirstName) + ' ' + String.valueof(CM.LastName);
                     icount = [SELECT count() FROM Opportunity WHERE Campaign__c =:camp.Id and Name=:sEvent +'-' + sName];
                     
                     if (icount == 0){                    
                         
                     // camp.addError(sEvent + '-' + sLast);
                  //Opportunity  op = new Opportunity(Campaign__c=camp.Id,Name=sEvent+ '-' + sName,CloseDate=camp.EndDate,StageName='Prospecting'); 
                  Opportunity op = new Opportunity(
                      Campaign__c=camp.Id,
                      Name=sEvent +'-' + sName,
                      CloseDate=camp.EndDate,
                      StageName='Prospecting',
                      Contact__c= cm.ContactId );                                                            
                   opp.add(op);                                                                       
                  }
                        insert opp;    
              
                 for(Opportunity ops : opp){
                     string sOppId = String.Valueof(ops.get('id'));
                     string sConId = String.Valueof(ops.get('Contact__c'));
                // camp.addError(String.Valueof(opp[0].id));        
                                       
                  OpportunityContactRole ocr = new OpportunityContactRole(
                    OpportunityId = sOppId,
                    //ContactId = cm.ContactId,
                    ContactId = sConId,
                    IsPrimary = TRUE);
                     ocrole.add(ocr);
                    }
                 insert ocrole;    
                 
               // insert ocrole;        
               }  
             } else if(iOPPCount  < 0){
                 //do nothing
             }
               /*  {
                     List<Contact> OPPList =[Select Name from  Contact];
                     for ( Contact OPP : OPPList  )
                     {
                         String sOPPList= String.Valueof( OPP.get( 'Name' ) );
                         Opportunity o = new Opportunity( Campaign = camp.id, Name=camp.Name + '-' + sOPPList ,Contact__c =camp.Contact__c );
                         ot.add( o );
                     }
                     insert ot;
                 } */
         }
 }

}

 
hi,
I do have a requirement where i need to develop SRS(
software requirements specification) for my salesforce app but i'm unable to know what are the use case to specify in it and how to write use case for my salesforce project for example if it is a event mangaement system what are the points i should consider in the use case, can anyone help me out with this !
thanks
LionHeart WhiteMetro
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