• sreekanth reddy
  • NEWBIE
  • 20 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 26
    Questions
  • 8
    Replies
Hi All,

Please help with the following trigger. The trigger is used to prevent creation of more than 2 receipts per opportunity with the exception for one profile ( Accounts). Now if I am trying to add another profile to the trigger for excemtion, but I am not getting code coverage. Please help with possible solution.

trigger Receiptt on Invoice__c(before insert) {
    ReceiptRestiction__c ua = ReceiptRestiction__c.getInstance (userinfo.getUserId());
    if (ua.Active__c) {
        set<id> Opportunity = new set<id>();
        Profile adminId = [SELECT Id from Profile where Name='Accounts' LIMIT 1]; //First profile
        profile adminId1 =[SELECT Id from Profile where Name='System Administrator' LIMIT 1]; //Second Profile
        //&&Userinfo.getProfileId() !=adminId1.id&&UserInfo.getProfileId() !=adminId1.Id
        
        if((trigger.isBefore && trigger.isInsert) && UserInfo.getProfileId() != adminId.Id&&Userinfo.getProfileId() !=adminId1.id){
            for(Invoice__c i: Trigger.new){
                Opportunity.add(i.Opportunity1__c);
            
            List<Invoice__c> lstBatAlt =[select id,Opportunity1__c,Name 
                                         from Invoice__c
                                         where Opportunity1__c IN:Opportunity and Opportunity1__r.recordType.developerName != 'Concierge' ];
                
            if(lstBatAlt.size()>1){
                i.addError('You cannot create more than two receipts for opportunity');
            }
        } 
         }
    }

Regards
Srikanth
Hi All,

How to Exclude one opportunity record type in below trigger.
Recordtype='Recordtypename'.

trigger Receiptt on Invoice__c(before insert) {
    ReceiptRestiction__c ua = ReceiptRestiction__c.getInstance (userinfo.getUserId());
    if (ua.Active__c) {
        set<id> Opportunity = new set<id>();
        
        Profile adminId = [SELECT Id from Profile where Name='Accounts' LIMIT 1];
        
        
        if((trigger.isBefore && trigger.isInsert) && UserInfo.getProfileId() != adminId.Id){
            for(Invoice__c cb:System.Trigger.new){
                
                
                Opportunity.add(cb.Opportunity1__c);
                
                List<Invoice__c> lstBatAlt =[select id,Opportunity1__c,Name from Invoice__c
                                             where Opportunity1__c IN:Opportunity ];
                
                if(lstBatAlt.size()>1){
                    
                    cb.addError('You cannot create more than two receipts for opportunity');
                }
            }
            
        }  
        
    }
}

Thanks
Srikanth
Hi All,

Please help in the problem I am facing for the below Scenario.
I am working on a trigger to auto count the number of times a filed is updated each month. Though the problem is the filed is on Opportunity object and each User has muiltiple opportunities. So if the field is updated in any opportunity, the field on the User page should increment. This will help us know the number of dispaches each month from each user.

Please help me in approaching the issue.

Regards
Avinash
Hi All,

How to write test class for below trigger.

rigger UpdateAmount on Training_Enquiry_Details__c (after insert, after update) { 
  Map<ID, Lead> parentOpps = new Map<ID, Lead>(); 
  List<Id> listIds = new List<Id>();

  for (Training_Enquiry_Details__c childObj : Trigger.new) {
    listIds.add(childObj.Lead__c);
  }

  parentOpps = new Map<Id, Lead>([SELECT id, Opted_Batch__c,(SELECT ID, Batch_Selected__c FROM Training_Enquiry_Details__r) FROM Lead WHERE ID IN :listIds]);

  for (Training_Enquiry_Details__c quote: Trigger.new){
     Lead myParentOpp = parentOpps.get(quote.Lead__c);
     myParentOpp.Opted_Batch__c = quote.Batch_Selected__c;
  }

  update parentOpps.values();
}

Thanks
Sai
Hi All,

I  Am trying to get result using below query.

select name,phone,email from account where name=:name and phone=:phone and email=:email . And
how to get combinational query.means
name+phone OR name+phone+email.
Thanks
Sai
Hi All,

I need a field update on account page based on opportunity record types. As we have multiple record types for opportunities lets say for example A and  B. Whenever an Account has record type opportunity and aslo B record type opportunity, i need a filed update on the account page to know this. I am using below formula field but its not working

IF( Test1__r.RecordType.Id = "12345678932565", true,false)

                Please help

Thanks
Srikanth
Hi All,
How to write test class for below class.pls help me

public class searchres2
{

    public String selectedvalue { get; set; }
    public string country{get;set;}
    public string TypeOfProgram{get;set;}
    public string  CourseSepcialisation1{get;set;}
    public string CourseCategory3{get;set;}
    
    public list<University_Database__c> bank{get;set;}
    Public University_Database__c ban{get;set;}
    public id sh;
    public void login()
    {
        
        bank = [select id,Country1__c,TypeOfProgram__c,Course_Sepcialisation1__c,Course_Category__c from University_Database__c where Country1__c=:country 
                                                                                and TypeOfProgram__c=:TypeOfProgram and Course_Category__c=:CourseCategory3 and Course_Sepcialisation1__c=:CourseSepcialisation1 LIMIT 1000];
    }
    public String getSelected_value() 
    {
        return null;
    }
     public List<SelectOption> getcountryOptions()    
    {    
        List<SelectOption> options =  new List<SelectOption>();    
        options.add(new selectOption('None','--- None ---'));    
        Schema.DescribeFieldResult fieldResult = University_Database__c.Country1__c.getDescribe();    
        List<Schema.picklistEntry> ple = fieldResult.getPicklistValues();    
        for(Schema.picklistEntry f:ple)    
          {
            options.add(new selectOption(f.getLabel(),f.getValue()));
           
         }  
        return options;
    }
     public List<SelectOption> getTypeOfProgramOptions()    
    {    
        List<SelectOption> options =  new List<SelectOption>();    
        options.add(new selectOption('None','--- None ---'));    
        Schema.DescribeFieldResult fieldResult = University_Database__c.TypeOfProgram__c.getDescribe();    
        List<Schema.picklistEntry> ple = fieldResult.getPicklistValues();    
        for(Schema.picklistEntry f:ple)    
          {
            options.add(new selectOption(f.getLabel(),f.getValue()));
           
         }  
        return options;
    }
    public List<SelectOption> getCourseCategory3Options()    
    {    
        List<SelectOption> options =  new List<SelectOption>();    
        options.add(new selectOption('None','--- None ---'));    
        Schema.DescribeFieldResult fieldResult = University_Database__c.Course_Category__c.getDescribe();    
        List<Schema.picklistEntry> ple = fieldResult.getPicklistValues();    
        for(Schema.picklistEntry f:ple)    
          {
            options.add(new selectOption(f.getLabel(),f.getValue()));
           
         }  
        return options;
    } 
                
}
 
Hi All

How to get record type in Query.
I am trying below query.
it's Not Working.


 String qry = 'select id, name, Country__c,RecordType.Name from Contact where name LIKE \'%'+searchText+'%\' and  RecordType.Name =srikanth order by name';

Thanks
Srikanth.
Hi All,

How to write test class for below class.

public with sharing class ContactSearchController {

  // the soql without the order and limit
  private String soql {get;set;}
  // the collection of contacts to display
  public List<Contact> contacts {get;set;}

  // the current sort direction. defaults to asc
  public String sortDir {
    get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
    set;
  }

  // the current field to sort by. defaults to last name
  public String sortField {
    get  { if (sortField == null) {sortField = 'lastName'; } return sortField;  }
    set;
  }

  // format the soql for display on the visualforce page
  public String debugSoql {
    get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
    set;
  }

  // init the controller and display some sample data when the page loads
  public ContactSearchController() {
    soql = 'select id,firstname, lastname, account.name, interested_technologies__c,Test__c from contact where account.name != null ';
    runQuery();
  }
//account.name != null 
  // toggles the sorting of query from asc<-->desc
  public void toggleSort() {
    // simply toggle the direction
    sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
    // run the query again
    runQuery();
  }

  // runs the actual query
  public void runQuery() {

    try {
      contacts = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
    } catch (Exception e) {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
    }

  }

  // runs the search with parameters passed via Javascript
  public PageReference runSearch() {

    String firstName = Apexpages.currentPage().getParameters().get('firstname');
    String lastName = Apexpages.currentPage().getParameters().get('lastname');
    String accountName = Apexpages.currentPage().getParameters().get('accountName');
    String technology = Apexpages.currentPage().getParameters().get('technology');
    String Test= Apexpages.currentPage().getParameters().get('Test');
    

    soql = 'select id,firstname, lastname, account.name,interested_technologies__c,Test__c from contact where account.name != null';
if (!firstName.equals(''))
soql += ' and firstname LIKE \''+String.escapeSingleQuotes(firstName)+'%\'';
if (!lastName.equals(''))
soql += ' and lastname LIKE \''+String.escapeSingleQuotes(lastName)+'%\'';
if (!accountName.equals(''))
soql += ' and account.name LIKE \''+String.escapeSingleQuotes(accountName)+'%\''; 
if (!accountName.equals(''))
soql += ' and Test__c  LIKE \''+String.escapeSingleQuotes(Test)+'%\''; 
if (!technology.equals(''))
soql += ' and interested_technologies__c includes (\''+technology+'\')';
    // run the query again
    runQuery();

    return null;
  }

  // use apex describe to build the picklist values
  public List<String> technologies {
    get {
      if (technologies == null) {

        technologies = new List<String>();
        Schema.DescribeFieldResult field = Contact.interested_technologies__c.getDescribe();

        for (Schema.PicklistEntry f : field.getPicklistValues())
          technologies.add(f.getLabel());

      }
      return technologies;          
    }
    set;
  }

}

Thanks
Srikanth
Hi All,
How to write test class for below class.
public class searchres {
public string country{get;set;}
public string PartneredNonPartneredUniversities{get;set;}
public string name{get;set;}
public string Qualification{get;set;}
public string quali{get;set;}
public string CourseCategory{get;set;}
public string Course{get;set;}
public string ProgramSepcialisation{get;set;}
public string Program{get;set;}

public list<SOV_Database__c> bank{get;set;}
Public SOV_Database__c ban{get;set;}
public id sh;
   public void login()
   {
       
       bank = [select id,country__c,qualification__c,Partnered_Non_Partnered_Universities__c,Course_Category__c,Program_Sepcialisation__c from SOV_Database__c where country__c=:country and Partnered_Non_Partnered_Universities__c=:PartneredNonPartneredUniversities ];
   }
   public List<SelectOption> getqualification()
   {
     List<SelectOption> options = new List<SelectOption>();
           
      Schema.DescribeFieldResult fieldResult =SOV_Database__c.qualification__c.getDescribe();
      List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
           
      for( Schema.PicklistEntry f : ple)
      {
         options.add(new SelectOption(f.getLabel(), f.getValue()));
      }       
      return options;
   }
   public List<SelectOption> getCourseCategory()
   {
     List<SelectOption> options = new List<SelectOption>();
           
      Schema.DescribeFieldResult fieldResult =SOV_Database__c.Course_Category__c.getDescribe();
      List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
           
      for( Schema.PicklistEntry f : ple)
      {
         options.add(new SelectOption(f.getLabel(), f.getValue()));
      }       
      return options;
   }
   public List<SelectOption> getProgramSepcialisation()
   {
     List<SelectOption> options = new List<SelectOption>();
           
      Schema.DescribeFieldResult fieldResult =SOV_Database__c.Program_Sepcialisation__c .getDescribe();
      List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
           
      for( Schema.PicklistEntry f : ple)
      {
         options.add(new SelectOption(f.getLabel(), f.getValue()));
      }       
      return options;
   }
}

Thanks
Pawan.
Hi All,
How To Write Test Class For Below Trigger.
trigger create_zapping_rec_Empaccount on Account(before insert)
{
 list<Zapping_Directory__c> zappinglist = new list<Zapping_Directory__c>();
 for(Account c:trigger.new)
 {
  if(c.RecordTypeId=='6666464564')
  {
  Zapping_Directory__c zap = new Zapping_Directory__c(Name=c.Company_Name__c,Company_Type__c=c.Company_Type__c,Main_Industry__c=c.Industrys__c
  );
  zappinglist.add(zap);
  }
  insert zappinglist;
 }
}
Thanks 
Srikanth.
Hi
How to update opportunity field with product custom field (using trigger).

   
Thanks 
Srikanth.
Hi,

How to write test class for below class.


public with sharing class JSS_JobSearch{
    public Integer pageSize = 200;
    public Integer pageNumber = 0;
    public String Id {get; set;}
    public Opportunity opportunityID {get; set;}
    public List<Job_Search__c> jobSearchB {get;set;}
    public List<Job_Search__c> jobSearchA {get;set;}
    public List<Open_Job__c> OpenJobsTop{get;set;}
    public List<Open_Job__c> OpenJobsTop2{get;set;}
    public Job_Search__c jobsearch{get; set;}
    public Map<String,Boolean> JobMap = new Map<String,Boolean>();
    public List<Job_Search__c> OpenJobstest{get;set;}
    public Boolean nextBool {get;set;}
    public Boolean prevBool {get;set;}
    public integer Openjobscount {get;set;}
    public integer Openjobscount2 {get;set;}
    public integer jobSearchcount {get;set;}
    public String openjobsId {get; set;}
    public integer count{get;set;}
    public List<Open_Job__c> OpenJobsList{get;set;}
    public String jSSSubIndustry{get;set;}
    public JSS_JobSearch(){
        This.id = Apexpages.currentpage().getparameters().get('id');
    }
    
    public void search(){
    jSSSubIndustry ='';
        OpportunityID = [Select id,name,JSS_Countries__c,JSS_Industry__c,Sub_Industry__c from Opportunity where id =:id]; 
        Boolean baddata = False;
        Boolean Sponsors = False;
        jobSearchA = new List<Job_Search__c>();
        jobSearchB = new List<Job_Search__c>();
        String  jSSCountry = opportunityID.JSS_Countries__c;
        String jSSIndustry = opportunityID.JSS_Industry__c;
        jSSSubIndustry = opportunityID.Sub_Industry__c;
        String baseQuery='Select id,name,Check__c,Email_Send__c ,Email_Bounced_Back__c,LastModifiedBy.LastName,Dummy_Job_Link__c,LastModifiedDate,Sub_Industry_oj__c,Country__c,Expiry_Date__c,Occupation__r.name,Job_captured_date__c,Job_Link__c,Province__c,Industry__c,CreatedBy.Name from Open_Job__c where ';
     
        if(jSSSubIndustry != null)
        {
            system.debug('has value in sub'+jSSSubIndustry);
            baseQuery +='Country__c =: jSSCountry and Industry__c =: jSsIndustry and Sub_Industry_oj__c =: jSSSubIndustry and Email_Bounced_Back__c =:baddata and Expiry_Date__c >= Today order by Expiry_Date__c ASC';
        }else
        {
            system.debug('does not have value in sub');
            baseQuery +='Country__c =: jSSCountry and Industry__c =: jSsIndustry  and Email_Bounced_Back__c =:baddata and Expiry_Date__c >= Today order by Expiry_Date__c ASC';
        }
      
        jobSearchB = [Select id,name,Country__c,Industry__c,Dummy_Job_Link_JS__c,LastModifiedBy.LastName,LastModifiedDate,Job_Link__c,Occupation__r.name,Opportunity__c,Province__c from Job_Search__c where Opportunity__c =: Id order by CreatedDate ASC];
        Boolean baddatas = True;
      
        OpenJobsList = [Select id,name,Check__c,Email_Send__c ,LastModifiedBy.LastName,LastModifiedDate,Country__c,Expiry_Date__c,Occupation__r.name,Job_captured_date__c,Job_Link__c,Province__c,Industry__c,Sub_Industry_oj__c,CreatedBy.Name from Open_Job__c where Country__c =: jSSCountry and Industry__c =: jSsIndustry and Sub_Industry_oj__c =: jSSSubIndustry and Expiry_Date__c >= Today order by Expiry_Date__c ASC];
        Integer offset = pageNumber * pageSize;
        String query = baseQuery + ' LIMIT '+pageSize +' OFFSET '+ offset;
        String query2 = baseQuery;
        OpenJobsTop = Database.query(query);
       OpenJobsTop2 = Database.query(query);
        Openjobscount = OpenJobsList.Size();
        Openjobscount2= OpenJobsTop2.Size();
        jobSearchcount = jobSearchB.size();
      
        for(Open_Job__c opens: OpenJobsTop){
            for(Job_Search__c jobs: jobSearchB){
                //jobs.Dummy_Job_Link_JS__c = opens.Dummy_Job_Link__c;
                system.debug('!!!!!!!!!!!!!!!!'+jobs.Dummy_Job_Link_JS__c);
                if(opens.Dummy_Job_Link__c == jobs.Dummy_Job_Link_JS__c){
                    system.debug('@@@@@@@@@@@@@@@'+opens.name);
                    system.debug('@@@@@@@@@@@@@@@'+jobs.Name);
                    system.debug('0000000000000'+opens.Dummy_Job_Link__c);
                    system.debug('0000000000000'+jobs.Dummy_Job_Link_JS__c);
                    opens.check__c = True;
                }
            }
        }
        OpenJobstest = jobSearchB;
    }
   
    public Pagereference commits(){
        jobSearchA = new List<Job_Search__c>();
        for(Job_Search__c jobss:jobSearchB){
            JobMap.put(jobss.Dummy_Job_Link_JS__c,True);
        }
        for(Open_Job__c FinalJobs: OpenJobsTop){
            jobsearch = new Job_Search__c();
            if(JobMap.get(FinalJobs.Dummy_Job_Link__c) != True){
                if(FinalJobs.check__c == True){
                    jobSearch.Name = FinalJobs.Name;
                    jobSearch.Country__c = FinalJobs.Country__c;
                    jobSearch.Industry__c = FinalJobs.Industry__c;
                 
                    if(jSSSubIndustry != null)
                    {
                        jobSearch.Sub_Industry_jss__c = FinalJobs.Sub_Industry_oj__c;
                    }                       
                   
                    jobSearch.Job_Link__c = FinalJobs.Job_Link__c;
                    jobSearch.Dummy_Job_Link_JS__c  = FinalJobs.Dummy_Job_Link__c;
                    jobSearch.Occupation__c = FinalJobs.Occupation__c;
                    jobSearch.Province__c = FinalJobs.Province__c;
                    jobSearch.Record_Id__c = FinalJobs.id +' '+ opportunityID.id;
                    jobSearch.opportunity__c = opportunityID.id;
                    jobSearch.Status__c = 'Completed';
                    jobSearchA.add(jobSearch);
                    jobSearchB.add(jobSearch);
                }      
            }
        }
        if(jobSearchA.Size()>0)
           insert jobSearchA;
        PageReference customPage = new PageReference('/'+opportunityID.Id);
        return customPage;
        return null;
    }
     //Custom Pagination for next
    public PageReference next(){
        pageNumber++;
        search();
        prevBool = false;
        return null;
    }
  //Custom Pagination for previous
    public PageReference previous(){
        pageNumber--;
        if (pageNumber < 0)    
            return null; 
        search();
        nextBool = false; 
        return null;
    }
     public void DeleteAcc(){
    system.debug('ddddddddddddd');
        if ( openjobsId  == null ){
            return;
        }
        Open_Job__c  tobeDeleted = null;
        for( Open_Job__c a : OpenJobsTop )
            if ( a.Id == openjobsId ) {
                tobeDeleted = a;
                  system.debug('tobeDeleted tobeDeleted '+tobeDeleted );
                break;
            }
    
        if ( tobeDeleted != null ) {
            tobeDeleted.Email_Bounced_Back__c= True;
             system.debug('tobeDeleted'+tobeDeleted);
            Update tobeDeleted;
            }
    }
}

Thanks.
hello.
how to write Commission trigger based on client feedback.
feedback is 4 types excellent,good,average,bad.
client select feedback is excellent then commision gets 4%
client select feedback is good then commision gets 3%.

thanks.
 
Hi,

This is my trigger and how to write test class for this trigger.

trigger OppProductDelete on OpportunityLineItem (before delete){
Id sysAdminId = [Select Id, Name from Profile where id = '00e90000001qXNbAAM' LIMIT 1].Id;
for (OpportunityLineItem oppProd : trigger.old){
if(UserInfo.getProfileId() ==sysAdminId)
oppProd.addError('This Opp Product may not be deleted');}
}

thanks.
Hi,

This is my trigger and how to write test class for this trigger.

trigger OppProductDelete on OpportunityLineItem (before delete){
Id sysAdminId = [Select Id, Name from Profile where id = '00e90000001qXNbAAM' LIMIT 1].Id;
for (OpportunityLineItem oppProd : trigger.old){
if(UserInfo.getProfileId() ==sysAdminId)
oppProd.addError('This Opp Product may not be deleted');}
}

thanks.
 
Hello
in vf page 3 radio buttos is their if i select one radio button and click send button in page
it sends email to one user.
thanks.
 
Hi,

This is my trigger and how to write test class for this trigger.

trigger OppProductDelete on OpportunityLineItem (before delete){
Id sysAdminId = [Select Id, Name from Profile where id = '00e90000001qXNbAAM' LIMIT 1].Id;
for (OpportunityLineItem oppProd : trigger.old){
if(UserInfo.getProfileId() ==sysAdminId)
oppProd.addError('This Opp Product may not be deleted');}
}

thanks.
Hi,

This is my trigger and how to write test class for this trigger.

trigger OppProductDelete on OpportunityLineItem (before delete){
Id sysAdminId = [Select Id, Name from Profile where id = '00e90000001qXNbAAM' LIMIT 1].Id;
for (OpportunityLineItem oppProd : trigger.old){
if(UserInfo.getProfileId() ==sysAdminId)
oppProd.addError('This Opp Product may not be deleted');}
}

thanks.