• Kunal Purohit 4
  • NEWBIE
  • 40 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 28
    Questions
  • 7
    Replies
Hello Team, I want to create a scratch org. But it is giving error
Socket timeout occurred while listening for results.
DevHub is also enabled. Please help to resolve issue.

 
Hello All, I have written below Apex Class and its Test Class... Can somebody help me to achieve 100% code coverage?

Apex Class
@RestResource(urlMapping='/Tasks/*')
global class GetTasksFromTeamWork {
	@HttpPost
    global static void handleTWTaskRequest() {
        RestRequest req = RestContext.request;
        String jsonresponse = req.requestBody.toString();
        system.debug('jsonresponse'+jsonresponse);
        TasksWrapper tasksObj = (TasksWrapper)JSON.deserialize(jsonresponse, TasksWrapper.class);
        
        TW_Task_List__c taskListRefference = new TW_Task_List__c(TaskListId__c = tasksObj.task.taskListId);
        // Contact contactRefference = new Contact(UserId__c = tasksObj.task.taskListId);
        
        TW_Task__c twTasksobj = new TW_Task__c();
        twTasksobj.Name = tasksObj.task.name;
        twTasksobj.TW_Description__c = tasksObj.task.description;
        twTasksobj.TW_Due_Date__c =  Date.valueOf(tasksObj.task.dueDate);
        twTasksobj.TW_Progress__c = Decimal.valueOf(tasksObj.task.progress);
        twTasksobj.TW_Priority__c = tasksObj.task.priority;
        twTasksobj.TW_Start_Date__c =  Date.valueOf(tasksObj.task.startDate);
        twTasksobj.TW_Estimated_Total_Time__c = Decimal.valueOf(tasksObj.task.estimatedMinutes);
        twTasksobj.TaskId__c = tasksObj.task.id;
        twTasksobj.TW_Task_List_Name__r = taskListRefference;
        if(tasksObj.task.parentId != '0'){
            TW_Task__c parentTaskRefference = new TW_Task__c(TaskId__c = tasksObj.task.parentId);
            twTasksobj.TW_Parent_Task__r = parentTaskRefference;
        }
        system.debug('twTasksobj =>'+twTasksobj);
        upsert twTasksobj TaskId__c;
    }
    
    public class TasksWrapper{
        public EventCreator eventCreator;
        public Project project;
        public Task  task;
        public TaskList taskList;
        public List<Tags> users;
     }
    
    public class Project {
		public String id;
		public String name;
		public String description;
		public String status;
		public Object startDate;
		public Object endDate;
		public List<Tags> tags;
		public Integer ownerId;
		public Integer companyId;
		public Integer categoryId;
		public String dateCreated;
	}

	public class Task {
		public String id;
		public String name;
		public String description;
		public String priority;
		public String status;
		public List<Tags> assignedUserIds;
		public String parentId;
		public String taskListId;
		public String startDate;
		public String dueDate;
		public Integer progress;
		public Integer estimatedMinutes;
		public List<Tags> tags;
		public Integer projectId;
		public String dateCreated;
		public String dateUpdated;
		public Boolean hasCustomFields;
	}

	
	

	public class TaskList {
		public Integer id;
		public String name;
		public String description;
		public String status;
		public Integer milestoneId;
		public Integer projectId;
		public Object templateId;
		public List<Tags> tags;
	}

	public class EventCreator {
		public Integer id;
		public String firstName;
		public String lastName;
		public String avatar;
	}

	public class Tags {
	}

}
Test Class
@isTest
public class GetTasksFromTeamWorkTest {
    
    static testMethod void testPost() {
        
        //Insert Records
        Account acc = new Account(Name = 'Testing');
        insert acc;
        
        String Uid = UserInfo.getUserId();
        
        Contact con = new Contact(LastName = 'TestCon',Title = 'Testing ', Phone = '1223456789', Email = 'test123@gmail.com', UserId__c = Uid);
        insert con;
        
        Opportunity OppObj = new Opportunity (Name = 'Opp Test', AccountId = acc.Id, StageName= 'Qualification', CloseDate = system.today()+2);
        insert OppObj;
        
        TW_Project__c projObj = new TW_Project__c(Name = 'Test Project', TW_Opportunity__c = OppObj.Id , ProjectId__c = '438022');
        insert projObj;
        
        TW_Milestone__c milestoneObj = new TW_Milestone__c(Name = 'Test Milestone', MilestoneId__c = '2233', TW_Project__c = projObj.Id);
        insert milestoneObj;
        
        TW_Task_List__c taskListObj = new TW_Task_List__c(Name = 'Test TaskList', TW_Project__c = projObj.Id, TW_Milestone__c = milestoneObj.Id , TaskListId__c = '2336');
        insert taskListObj;
        
        TW_Task__c taskObj = new TW_Task__c(Name = 'Test Task', TaskId__c = '1234', TW_Task_List_Name__c = taskListObj.Id);
        insert taskObj;
        
        TW_Time__c timeObj = new TW_Time__c(TW_Project__c = projObj.Id,TW_Who__c = con.Id, TimeId__c = '2336', TW_Task__c = taskObj.Id);
        insert timeObj;
        
        GetTasksFromTeamWork.eventCreator eveCreaObj = new GetTasksFromTeamWork.eventCreator();
        //eveCreaObj.id;
		eveCreaObj.firstName = 'eventCreator';
		eveCreaObj.lastName = 'Test';
        
        GetTasksFromTeamWork.Project project = new GetTasksFromTeamWork.Project();
        GetTasksFromTeamWork.Task task = new GetTasksFromTeamWork.Task();
        GetTasksFromTeamWork.TaskList taskList = new GetTasksFromTeamWork.TaskList();
        
        GetTasksFromTeamWork.TasksWrapper wrapTask = new GetTasksFromTeamWork.TasksWrapper();
        wrapTask.eventCreator = eveCreaObj;
        wrapTask.project = project;
        wrapTask.task = task;
        wrapTask.taskList = taskList;
        String myJSON = JSON.serialize(wrapTask);
        
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
        req.requestURI = '/services/apexrest/GetTasksFromTeamWork/';
        req.httpMethod = 'POST';
        req.requestBody = Blob.valueof(myJSON);
        RestContext.request = req;
        RestContext.response= res;
        GetTasksFromTeamWork.handleTWTaskRequest();
    }

}


 
@RestResource(urlMapping='/Projects/*')
global class GetProjectsFromTeamWork {
    @HttpPost
    global static void doPost() {
        RestRequest req = RestContext.request;
        String jsonresponse = req.requestBody.toString();
        system.debug('jsonresponse=='+jsonresponse);
        
        wrapperOfProject proj = (wrapperOfProject)JSON.deserialize(jsonresponse, wrapperOfProject.class);
        Contact contactRefference = new Contact(UserId__c = proj.Project.ownerId);
        List<Account> accList = [Select id From Account Where CompanyId__c = :proj.Project.companyId];
        system.debug('accList==='+accList);
        List<Opportunity> oppList = [Select id from Opportunity Where AccountId = :accList[0].id];
        System.debug('oppList==='+oppList);
        TW_Project__c projectObj = new TW_Project__c();
        projectObj.Name = proj.Project.name;
        projectObj.TW_Description__c = proj.Project.description;
        projectObj.TW_Opportunity__c = oppList[0].id;
        projectObj.ProjectId__c = proj.Project.id;
        projectObj.TW_Project_Manager__c = contactRefference.id;
        insert projectObj;
    }
    
    public class wrapperOfProject{
        public eventCreator eventCreator;
        public Project project;
    }
    
   	public class EventCreator {
		public Integer id;
		public String firstName;
		public String lastName;
		public String avatar;
	}
    
    public class Project {
		public String id;
		public String name;
		public String description;
		public String status;
		public Object startDate;
		public Object endDate;
		public List<Tags> tags;
		public String ownerId;
		public String companyId;
		public String categoryId;
		public String dateCreated;
	}
    
    public class Tags {
	}
}

 
Hello team, Plz help me for writing test class for code given below.
@RestResource(urlMapping='/Projects/*')
global class GetProjectsFromTeamWork {
    @HttpPost
    global static void doPost() {
        RestRequest req = RestContext.request;
        String jsonresponse = req.requestBody.toString();
        system.debug('jsonresponse=='+jsonresponse);
        
        wrapperOfProject proj = (wrapperOfProject)JSON.deserialize(jsonresponse, wrapperOfProject.class);
        Contact contactRefference = new Contact(UserId__c = proj.Project.ownerId);
        List<Account> accList = [Select id From Account Where CompanyId__c = :proj.Project.companyId];
        system.debug('accList==='+accList);
        List<Opportunity> oppList = [Select id from Opportunity Where AccountId = :accList[0].id];
        System.debug('oppList==='+oppList);
        TW_Project__c projectObj = new TW_Project__c();
        projectObj.Name = proj.Project.name;
        projectObj.TW_Description__c = proj.Project.description;
        projectObj.TW_Opportunity__c = oppList[0].id;
        projectObj.ProjectId__c = proj.Project.id;
        projectObj.TW_Project_Manager__c = contactRefference.id;
        insert projectObj;
    }
    
    public class wrapperOfProject{
        public eventCreator eventCreator;
        public Project project;
    }
    
   	public class EventCreator {
		public Integer id;
		public String firstName;
		public String lastName;
		public String avatar;
	}
    
    public class Project {
		public String id;
		public String name;
		public String description;
		public String status;
		public Object startDate;
		public Object endDate;
		public List<Tags> tags;
		public String ownerId;
		public String companyId;
		public String categoryId;
		public String dateCreated;
	}
    
    public class Tags {
	}
}
Hello Team,
i am writing Webservice and want to map json.But in debug log shows status ""For input string: "" at [line:1, column:218]..

Here is Json Response:
invoice":{"id":2651,"number":"In-151","poNumber":""}

Here is the code:
@RestResource(urlMapping='/Invoice/*')
global class GetInvoiceFromTeamWork {
	@HttpPost
    global static void doPost() {
        RestRequest req = RestContext.request;
        String jsonresponse = req.requestBody.toString();
        system.debug('jsonresponse'+jsonresponse);
        
        
        wrapperofInvoice wrapinvoice=(wrapperofInvoice)JSON.deserialize(jsonresponse, wrapperofInvoice.class);
        TW_Invoice__c inv =new TW_Invoice__c();
        inv.TW_Invoice_ID__c=wrapinvoice.invoice.id;
        
        //inv.TW_PO_Number__c=wrapinvoice.invoice.poNumber;
        insert inv;   
    }
    
    public class wrapperofInvoice{
        public eventCreator eventCreator;
        public Invoice invoice;
    }
    
    public class eventCreator {
        public String wholeJson;
    }
    
    public class invoice{
        Public integer id;
        public integer number;
        public decimal poNumber;
        public String description;
       public String Status;
        public String currencyCode;
	public String dateCreated;        
    }
}

 
Hello Team,
My requirement is that whenever record is created/edited in external application,it should get displayed in salesforce...How to perform this task? Please suggest..
Hi, i have written below code to retreive project information from Teamwork into Salesforce. But it is not reteriving projects. Instead its showing Not Authorised...
Public class RestApp1 {
public void basicAuthCallout(){
HttpRequest request=new HttpRequest();
request.setEndpoint('https://blueflamelab1.teamwork.com/projects.json');
request.setMethod('GET');
request.setHeader('Authorization','Bearer tkn.v1_OGZhNWRhNjYtZjVhOS00ZDBhLWJhODEtODVhZTA2MTgzYTE5LTcxMjQ3Ny40MTE3NTAuVVM=');
 Http http = new Http();
 HTTPResponse res = http.send(request);
 System.debug(res.getBody());   
}
}

 
I am having custom object Test__c. There is no sigle record in this object.  I want to insert multiple records using batch apex. Plz help.
public class StatusPublished implements database.Batchable<sobject>,Schedulable{

    public void execute(Schedulablecontext sc)
    {
         string cron='0 2 * * * ?*';
        StatusPublished sp =new StatusPublished();
        system.schedule('updatepaper', cron, sp);
      //database.executeBatch(sp);
    }
        public database.QueryLocator start(database.BatchableContext bc)
    {
        string query='select id,Name,Status__c from Research_Paper__c';
        return database.getQueryLocator(query);
    }
        public void execute(database.BatchableContext bc,list<Account> acc)
    {
        List<Research_Paper__c> rlist=new list<Research_Paper__c>();
        for(Research_Paper__c rp: rlist)
        {
            if(rp.Status__c=='Paper registration Complete')
            {
                rp.Status__c='Published';
                rlist.add(rp);
            }
        }
        update rlist;
    }
    
     public void finish(database.BatchableContext bc)
    {
 
    }

 
I am writing this trigger to prevent duplicate entry. But this trigger runs even at time of creating new record..How to resolve?
trigger TriggerOpp on Opportunity (before insert,before update) {
   set<id> setid=new set<id>();
    for(Opportunity opp:trigger.new)
    {
       setid.add(opp.AccountId);
    }
    
    Map<id,Account> acmap=new map<id,Account>();
    
    for(account acc:[select id,Name,(select id,Name,StageName from Opportunities) from Account where id in:setid])
    {
        acmap.put(acc.id,acc);
    }
    
    for(Opportunity opp:trigger.new)
    {
        if(acmap.containsKey(opp.AccountId) && acmap.get(opp.AccountId).Opportunities!=null)
        {
        
           {
               if(opp.StageName=='Prospecting')
               {
                     (opp.AccountId).addError('Duplicate value');
               }
           }
        }
    }
}
Scenario for trigger is that, if Opportunity Object having record with field stageName=='Prospecting ' and Parent Account name with,lets say XYZ.,so another record with same field value and same parent should not get duplicated.. I have written below trigger but it is showing error.

 
trigger TriggerOpp on Opportunity (before insert,before update) {
   set<id> setid=new set<id>();
    for(Opportunity opp:trigger.new)
    {
       setid.add(opp.AccountId);
    }
    
    Map<id,Account> acmap=new map<id,Account>();
    
    for(account acc:[select id,Name,(select id,Name,StageName from Opportunities) from Account where id in:setid])
    {
        acmap.put(acc.id,acc);
    }
    
    for(Opportunity opp:trigger.new)
    {
        if(acmap.containsKey(opp.AccountId))
        {
           if(acmap.get(opp.AccountId).StageName=='Prospecting')
           {
               (opp.AccountId).addError('Duplicate value');
           }
        }
    }
}
Hello All, I am having two objects Account and Opportunity. Now scenario is that, there should be no duplicate entry of Account and Opportunity when i select stage field of opportuntiy. 
How to write trigger?
Hi, i am having Object named Research_Paper__c . How to dispay records depending on selected dates.. For example,after clicking show button, i want to display name of Research Papers whose publication date is between 1/8/2020 and 14/8/2020.. How to do it in Lightning?
I am havng following Custom Controller class. How to write test Class for follwing code:
 
public with sharing class JournalPage1 {
public integer limitvalue=5;
public integer offsetvalue=0;
public integer papersize=0;
 public Date endDate { get; set; }
         public Date startDate { get; set; }
        public List<Author_Research_Paper__c> AuthList { get; set; }
    public boolean Showdetailsflag { get; set; }
    public List<wrapJournalPage1> WrapList { get; set; }
    public PageReference lastPage() {
    offsetValue = papersize - limitValue;
    callQuery();
            return null;
    }
    public PageReference nextPage() {
  offsetValue = offsetValue + LimitValue;
    callQuery();
        return null;
    }


    public PageReference previousPage() {
   i

f(offsetValue > 0){
    offsetValue = offsetValue - LimitValue;
    callQuery();
    }
        return null;
    }

    public PageReference firstPage() {
    offsetValue = 0;
    callQuery();
        return null;
    }
 public void callQuery(){
 WrapList = new List<wrapJournalPage1>();
// list<Research_Paper__c> rlist=[Select id from Research_Paper__c];
  papersize=count;
  for(Research_Paper__c rc:[Select Id,Name, Paper_Title__c,Name_of_Primary_Author__c,Status__c,Publication_Date__c from Research_Paper__c  limit:limitvalue OFFSET:offsetvalue]){
               wrapJournalPage1 obj=new wrapJournalPage1(rc);
                            Wraplist.add(obj); 
                            }                          
 }

    public void Showdetails() {
         List<Id> rpID = new List<Id>();
         for(wrapJournalPage1 wp : wrapList)
         {
         if(wp.flagWrap==true)
         {
         rpID.add(wp.rcWrap.Id);
         }
         }
         for(Id i : rpID)
         {
     AuthList=[Select Id, Research_Paper__r.Name, Research_Paper__r.Paper_Title__c, Author__r.Name,
                      Research_Paper__r.Status__c, Research_Paper__r.Submission_Date__c
                       From Author_Research_Paper__c
                       Where Research_Paper__c =: i];
         }
         
         Showdetailsflag=true;
    }
     public void updated() {
        Research=[Select id from Research_Paper__c];
                                
    count=Research.size();
    }

    public Integer count { get; set; }

    public List<Research_Paper__c> Research { get; set; }
    
    public JournalPage1()
{
Research=new list<Research_Paper__c>();

}
   public PageReference Show() {
         WrapList = new List<wrapJournalPage1>();
    
    if(startDate!=null && endDate!=null)
    {
         Research=[Select Id,Name, Paper_Title__c,Name_of_Primary_Author__c,Status__c,Publication_Date__c from Research_Paper__c where Publication_Date__c>=:startDate AND
                                         Publication_Date__c<=:endDate limit:limitvalue OFFSET:offsetvalue];
                            count=Research.size();
                            for(Research_Paper__c rc:Research)
                            {
                            wrapJournalPage1 obj=new wrapJournalPage1(rc);
                            Wraplist.add(obj);
                            }
    }
    
        return null;
    }


    
    
    Public class wrapJournalPage1{
    
    Public Research_Paper__c rcWrap{get; set;}
    public boolean flagWrap{get;set;}
    
    public wrapJournalPage1(Research_Paper__c rc){
            this.rcWrap=rc;
            this.flagWrap=false;
    }
    
    }
}

 
Hello All, can someone help me to write test case for below custom controller VF page?

public with sharing class JournalPage1 {

public integer limitvalue=5;
public integer offsetvalue=0;
public integer papersize=0;


    public Date endDate { get; set; }
    
    //public List<Research_Paper__C> Research{get;set;}

    public Date startDate { get; set; }
    
    public List<Author_Research_Paper__c> AuthList { get; set; }

    public boolean Showdetailsflag { get; set; }

    public List<wrapJournalPage1> WrapList { get; set; }

   

    public PageReference lastPage() {
    offsetValue = papersize - limitValue;
    callQuery();
    
        return null;
    }


    
    
    public PageReference nextPage() {
  offsetValue = offsetValue + LimitValue;
    callQuery();
        return null;
    }


    public PageReference previousPage() {
   if(offsetValue > 0){
    offsetValue = offsetValue - LimitValue;
    callQuery();
    }
        return null;
    }


    public PageReference firstPage() {
    offsetValue = 0;
    callQuery();
        return null;
    }
 public void callQuery(){
 WrapList = new List<wrapJournalPage1>();
// list<Research_Paper__c> rlist=[Select id from Research_Paper__c];
  papersize=count;
  for(Research_Paper__c rc:[Select Id,Name, Paper_Title__c,Name_of_Primary_Author__c,Status__c,Publication_Date__c from Research_Paper__c  limit:limitvalue OFFSET:offsetvalue]){
               wrapJournalPage1 obj=new wrapJournalPage1(rc);
                            Wraplist.add(obj); 
                            }                          
 }

    public void Showdetails() {
         List<Id> rpID = new List<Id>();
         for(wrapJournalPage1 wp : wrapList)
         {
         if(wp.flagWrap==true)
         {
         rpID.add(wp.rcWrap.Id);
         }
         }
         for(Id i : rpID)
         {
     AuthList=[Select Id, Research_Paper__r.Name, Research_Paper__r.Paper_Title__c, Author__r.Name,
                      Research_Paper__r.Status__c, Research_Paper__r.Submission_Date__c
                       From Author_Research_Paper__c
                       Where Research_Paper__c =: i];
         }
         
         Showdetailsflag=true;
    }


   // public Boolean selectionflag { get; set; }

    public void updated() {
        Research=[Select id from Research_Paper__c];
                                
    count=Research.size();
    }


    public Integer count { get; set; }

    public List<Research_Paper__c> Research { get; set; }
    
    public JournalPage1()
{
Research=new list<Research_Paper__c>();

}

    public PageReference Show() {
    
     WrapList = new List<wrapJournalPage1>();
    
    if(startDate!=null && endDate!=null)
    {
         Research=[Select Id,Name, Paper_Title__c,Name_of_Primary_Author__c,Status__c,Publication_Date__c from Research_Paper__c where Publication_Date__c>=:startDate AND
                                         Publication_Date__c<=:endDate limit:limitvalue OFFSET:offsetvalue];
                            count=Research.size();
                            for(Research_Paper__c rc:Research)
                            {
                            wrapJournalPage1 obj=new wrapJournalPage1(rc);
                            Wraplist.add(obj);
                            }
    }
    
        return null;
    }


    
    
    Public class wrapJournalPage1{
    
    Public Research_Paper__c rcWrap{get; set;}
    public boolean flagWrap{get;set;}
    
    public wrapJournalPage1(Research_Paper__c rc){
            this.rcWrap=rc;
            this.flagWrap=false;
    }
    
    }
}
I am trying to send mail through Batch Apex. But it shows following Error.

Method does not exist or incorrect signature: void setHtmlBody(String, Decimal) from the type Messaging.SingleEmailMessage

batch Apex Class

public class EmailBatch implements database.Batchable<sobject>,Schedulable{
public decimal count=0;
    public void execute(Schedulablecontext sc)
    {
        EmailBatch eb=new EmailBatch();
    database.executeBatch(eb);
    }
    
    public database.QueryLocator start(database.BatchableContext bc)
    {
        string query='select Name,Journal_Email_Address__c,Total_Published_Paper__c from Account';
        return database.getQueryLocator(query);
    }
    
    public void execute(database.BatchableContext bc,list<Account> acc)
    {
        list<Account> alist=new list<Account>();
        for(Account a:acc)
        {
            count=count+a.Total_Published_Paper__c;
        }
        list<Messaging.SingleEmailMessage> mlist=new list<Messaging.SingleEmailMessage>();
        messaging.SingleEmailMessage email=new messaging.SingleEmailMessage();
        email.setSubject('Welcome');
        email.setHtmlBody('Total Paper Published is',+count);
        string[] to=new string[]{'kunalpurohit7@gmail.com'};
            email.setToAddresses(to);
        mlist.add(email);
        messaging.SendEmail(mlist);
        system.debug('Mail sent Successfully');
    }        
    public void finish(database.BatchableContext bc)
    {
system.debug('Email Sent');        
    }
}
I want to send mail with Total_Paper_Published value. Total_Paper_Published__c is a rollup summary field.
Here is the code. Plz suggest correction.
public class EmailBatch implements database.Batchable<sobject>,Schedulable{
public decimal count=0;
    public void execute(Schedulablecontext sc)
    {
        EmailBatch eb=new EmailBatch();
    database.executeBatch(eb);
    }
    
    public database.QueryLocator start(database.BatchableContext bc)
    {
        string query='select Name,Journal_Email_Address__c,Total_Published_Paper__c from Account';
        return database.getQueryLocator(query);
    }
    
    public void execute(database.BatchableContext bc,list<Account> acc)
    {
       list<Account>alist=new list<Account>();
        for(Account a:acc)
        {
         count=a.Total_Published_Paper__c;
        
    }
    list<Messaging.SingleEmailMessage> mlist=new list<Messaging.SingleEmailMessage>();
        messaging.SingleEmailMessage email=new messaging.SingleEmailMessage();
        email.setSubject('Welcome');
        email.setPlainTextBody('Total Paper Published' +count);
        string[] to=new string[]{'kunalpurohit7@gmail.com'};
            email.setToAddresses(to);
        mlist.add(email);
        messaging.SendEmail(mlist);
        system.debug('Mail sent Successfully');
    }        
    public void finish(database.BatchableContext bc)
    {
//system.debug(count);        
    }
}
Hello Team,
I want to write batch Apex for sending mail with Total_paper_Count field. It is a custom field in Account Object. Please help
In pagination,while clicking on last button,it shows above eror.

public with sharing class JournalPage1 {

public integer limitvalue=3;
public integer offsetvalue=0;
public integer papersize=0;


    public Date endDate { get; set; }
    
    //public List<Research_Paper__C> Research{get;set;}

    public Date startDate { get; set; }
    
    public List<Author_Research_Paper__c> AuthList { get; set; }

    public boolean Showdetailsflag { get; set; }

    public List<wrapJournalPage1> WrapList { get; set; }

   

    public PageReference lastPage() {
    offsetValue = papersize - limitValue;
    callQuery();
    
        return null;
    }


    
    
    public PageReference nextPage() {
  offsetValue = offsetValue + LimitValue;
    callQuery();
        return null;
    }


    public PageReference previousPage() {
   if(offsetValue > 0){
    offsetValue = offsetValue - LimitValue;
    callQuery();
    }
        return null;
    }


    public PageReference firstPage() {
    offsetValue = 0;
    callQuery();
        return null;
    }
 public void callQuery(){
 WrapList = new List<wrapJournalPage1>();
 list<Research_Paper__c> rlist=[Select id from Research_Paper__c];
  papersize=rlist.size();
  for(Research_Paper__c rc:[Select Id,Name, Paper_Title__c,Name_of_Primary_Author__c,Status__c,Publication_Date__c from Research_Paper__c  limit:limitvalue OFFSET:offsetvalue]){
               wrapJournalPage1 obj=new wrapJournalPage1(rc);
                            Wraplist.add(obj); 
                            }                          
 }

    public void Showdetails() {
         List<Id> rpID = new List<Id>();
         for(wrapJournalPage1 wp : wrapList)
         {
         if(wp.flagWrap==true)
         {
         rpID.add(wp.rcWrap.Id);
         }
         }
         for(Id i : rpID)
         {
     AuthList=[Select Id, Research_Paper__r.Name, Research_Paper__r.Paper_Title__c, Author__r.Name,
                      Research_Paper__r.Status__c, Research_Paper__r.Submission_Date__c
                       From Author_Research_Paper__c
                       Where Research_Paper__c =: i];
         }
         
         Showdetailsflag=true;
    }


   // public Boolean selectionflag { get; set; }

    public void updated() {
        Research=[Select id from Research_Paper__c];
                                
    count=Research.size();
    }


    public Integer count { get; set; }

    public List<Research_Paper__c> Research { get; set; }
    
    public JournalPage1()
{
Research=new list<Research_Paper__c>();

}

    public PageReference Show() {
    
     WrapList = new List<wrapJournalPage1>();
    
    if(startDate!=null && endDate!=null)
    {
         Research=[Select Id,Name, Paper_Title__c,Name_of_Primary_Author__c,Status__c,Publication_Date__c from Research_Paper__c where Publication_Date__c>=:startDate AND
                                         Publication_Date__c<=:endDate limit:limitvalue OFFSET:offsetvalue];
                            count=Research.size();
                            for(Research_Paper__c rc:Research)
                            {
                            wrapJournalPage1 obj=new wrapJournalPage1(rc);
                            Wraplist.add(obj);
                            }
    }
    
        return null;
    }


    
    
    Public class wrapJournalPage1{
    
    Public Research_Paper__c rcWrap{get; set;}
    public boolean flagWrap{get;set;}
    
    public wrapJournalPage1(Research_Paper__c rc){
            this.rcWrap=rc;
            this.flagWrap=false;
    }
    
    }
}
Below is the code and couldn't figure out what exactly is the reason, Any Suggestions??

VF code

<apex:page controller="JournalPage1" docType="html-5.0">
 <apex:form >
<apex:pageBlock title="Journal Information">
<apex:pageBlockButtons location="Bottom" >
<apex:OutputPanel >
<apex:commandButton value="|<-First" action="{!firstPage}" />
<apex:commandButton value="<-Previous" action="{!previousPage}"/>
<apex:commandButton value="Next ->" action="{!nextPage}"/>
<apex:commandButton value="Last ->|" action="{!lastPage}"/>
<apex:commandbutton value="Show Details" action="{!Showdetails}"/>
</apex:OutputPanel>
</apex:pageBlockButtons>
<apex:pageBlockSection >

From Date: <apex:input type="date" value="{!startDate}" required="true" />
 To Date: <apex:input type="date" value="{!endDate}" required="true" />
 <apex:commandButton value="Show" action="{!Show}"/> <br/><br/>
  
 
 <apex:outputPanel id="dt">
 Total No of Papers:<apex:outputText value="{!count}"></apex:outputText>
 <apex:actionPoller action="{!updated}" interval="300" reRender="dt"/>
 </apex:outputPanel>
</apex:pageBlockSection>
<apex:pageBlockTable value="{!Wraplist}" var="rp" rendered="{!(Research.size!=0)}" >

<apex:column >
<apex:facet name="header"> Select CheckBox</apex:facet>
 <apex:inputCheckbox value="{!rp.flagWrap}" />
 </apex:column>

<apex:column headerValue="Paper Id">
 <apex:outputField value="{!rp.rcWrap.id}"/>
 </apex:column>
 
 <apex:column headerValue="Paper Title">
 <apex:outputField value="{!rp.rcWrap.Paper_Title__c}"/>
 </apex:column>
 
 <apex:column headerValue="Primary Author">
 <apex:outputField value="{!rp.rcWrap.Name_of_Primary_Author__c}"/>
 </apex:column>

<apex:column headerValue="Status">
 <apex:outputField value="{!rp.rcWrap.Status__c}"/>
 </apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock id="Table2" rendered="{!Showdetailsflag}" >
<apex:pageblockSection title="List of Authors">
<apex:pageBlockTable value="{!AuthList}" var="a">
<apex:column value="{!a.Research_Paper__r.Name}"/>
<apex:column value="{!a.Research_Paper__r.Paper_Title__c}"/>
<apex:column value="{!a.Author__r.Name}"/>
<apex:column value="{!a.Research_Paper__r.Status__c}"/>
<apex:column value="{!a.Research_Paper__r.Submission_Date__c}"/>
</apex:pageBlockTable>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Apex Controller

public with sharing class JournalPage1 {

    public Date endDate { get; set; }
    
    //public List<Research_Paper__C> Research{get;set;}

    public Date startDate { get; set; }
    
    public List<Author_Research_Paper__c> AuthList { get; set; }

    public boolean Showdetailsflag { get; set; }

    public List<wrapJournalPage1> WrapList { get; set; }

   

    public PageReference lastPage() {
        return null;
    }


    public PageReference nextPage() {
        return null;
    }


    public PageReference previousPage() {
        return null;
    }


    public PageReference firstPage() {
        return null;
    }


    public void Showdetails() {
         List<Id> rpID = new List<Id>();
         for(wrapJournalPage1 wp : wrapList)
         {
         if(wp.flagWrap==true)
         {
         rpID.add(wp.rcWrap.Id);
         }
         }
         for(Id i : rpID)
         {
     AuthList=[Select Id, Research_Paper__r.Name, Research_Paper__r.Paper_Title__c, Author__r.Name,
                      Research_Paper__r.Status__c, Research_Paper__r.Submission_Date__c
                       From Author_Research_Paper__c
                       Where Research_Paper__c =: i];
         }
         
         Showdetailsflag=true;
    }


   // public Boolean selectionflag { get; set; }

    public void updated() {
        Research=[Select id from Research_Paper__c];
                                
    count=Research.size();
    }


    public Integer count { get; set; }

    public List<Research_Paper__c> Research { get; set; }
    
    public JournalPage1()
{
Research=new list<Research_Paper__c>();

}

    public PageReference Show() {
    
     Research=[Select Id,Paper_Title__c,Name_of_Primary_Author__c,Status__c,Publication_Date__c from Research_Paper__c where Publication_Date__c>=:startDate AND
                                         Publication_Date__c<=:endDate];
                          //  count=Research.size();
                            for(Research_Paper__c rc:Research)
                            {
                            wrapJournalPage1 obj=new wrapJournalPage1(rc);
                            Wraplist.add(obj);
                            }
    
    
        return null;
    }


    
    
    Public class wrapJournalPage1{
    
    Public Research_Paper__c rcWrap{get; set;}
    public boolean flagWrap{get;set;}
    public wrapJournalPage1(Research_Paper__c rc){
    this.rcWrap=rc;
    this.flagWrap=false;
    }
    }
}
public class StatusPublished implements database.Batchable<sobject>,Schedulable{

    public void execute(Schedulablecontext sc)
    {
         string cron='0 2 * * * ?*';
        StatusPublished sp =new StatusPublished();
        system.schedule('updatepaper', cron, sp);
      //database.executeBatch(sp);
    }
        public database.QueryLocator start(database.BatchableContext bc)
    {
        string query='select id,Name,Status__c from Research_Paper__c';
        return database.getQueryLocator(query);
    }
        public void execute(database.BatchableContext bc,list<Account> acc)
    {
        List<Research_Paper__c> rlist=new list<Research_Paper__c>();
        for(Research_Paper__c rp: rlist)
        {
            if(rp.Status__c=='Paper registration Complete')
            {
                rp.Status__c='Published';
                rlist.add(rp);
            }
        }
        update rlist;
    }
    
     public void finish(database.BatchableContext bc)
    {
 
    }

 
I am writing this trigger to prevent duplicate entry. But this trigger runs even at time of creating new record..How to resolve?
trigger TriggerOpp on Opportunity (before insert,before update) {
   set<id> setid=new set<id>();
    for(Opportunity opp:trigger.new)
    {
       setid.add(opp.AccountId);
    }
    
    Map<id,Account> acmap=new map<id,Account>();
    
    for(account acc:[select id,Name,(select id,Name,StageName from Opportunities) from Account where id in:setid])
    {
        acmap.put(acc.id,acc);
    }
    
    for(Opportunity opp:trigger.new)
    {
        if(acmap.containsKey(opp.AccountId) && acmap.get(opp.AccountId).Opportunities!=null)
        {
        
           {
               if(opp.StageName=='Prospecting')
               {
                     (opp.AccountId).addError('Duplicate value');
               }
           }
        }
    }
}
Scenario for trigger is that, if Opportunity Object having record with field stageName=='Prospecting ' and Parent Account name with,lets say XYZ.,so another record with same field value and same parent should not get duplicated.. I have written below trigger but it is showing error.

 
trigger TriggerOpp on Opportunity (before insert,before update) {
   set<id> setid=new set<id>();
    for(Opportunity opp:trigger.new)
    {
       setid.add(opp.AccountId);
    }
    
    Map<id,Account> acmap=new map<id,Account>();
    
    for(account acc:[select id,Name,(select id,Name,StageName from Opportunities) from Account where id in:setid])
    {
        acmap.put(acc.id,acc);
    }
    
    for(Opportunity opp:trigger.new)
    {
        if(acmap.containsKey(opp.AccountId))
        {
           if(acmap.get(opp.AccountId).StageName=='Prospecting')
           {
               (opp.AccountId).addError('Duplicate value');
           }
        }
    }
}
I want to remove prefix 'Mr.' from my Account object. I have tried through the BatchApex class. But still its not working.
public class BatchApex1 implements database.Batchable<Sobject> {
    public database.QueryLocator start(database.BatchableContext Bc)
    {
        string query='select id,name from Account';
        return database.getQueryLocator(query);
    }
    
    public void execute(database.BatchableContext Bc, list<Account> alist)
    {
        for(account a:alist)
        {
           a.name= a.Name.removeStart('Mr.');
        }
        
        update alist;
        system.debug(alist);
    }
     public void finish(database.BatchableContext Bc)
    {
        
    }

}
 
I have junction object "Author-Research Paper". This object has two master detail relationship with objects "Authors" and "Research Paper".
Now,there must not be more than 5 Authors for single research paper. How to write validtion rule for it?