• Arash Teimoupoor
  • NEWBIE
  • 39 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 20
    Replies
I have a large joing report(more than 35 MB) that I need to schedule, it cannot be created via dataloader or jitterbit, and it cannot be emailed as attachment because it's too large. is there any way to use apex coding so I can export this report to local network share folders?
I'm using the following to email my report as CSV but it just includes the first 2000 rowes in the csv file while my report has more than 50000 rowes. how can I solve this? thanks in advance:


global class Report implements System.Schedulable {
    global void execute(SchedulableContext sc) {
        ApexPages.PageReference report = new ApexPages.PageReference('/00O60000003XpO6?csv=1');
        Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
        attachment.setFileName('testcsv');
        attachment.setBody(report.getContent());
        attachment.setContentType('text/csv');
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        message.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment } );
        message.setSubject('test');
        message.setPlainTextBody('test is attached.');
        message.setToAddresses( new String[] { 'test@test.com' } );
        Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } );
        
    }
}
Hi Every one
I have a report that I need to place in my network every day as a CSV. it includes fileds from a custom object(Chart) and also fields from the tasks and events created on the records of Chart.
, so a record of Chart can have so many tasks and events, I need a query to export for example "ID" and "Name" fields from the chart record and "Subject" field from the tasks and Events on those records so I can export a csv file with dataloader or Jitterbit and schedule it to be  placeed  in my network.

Thanks in advance
Hi everyone,

I have created a search bar(ProjectSearch) in VF page to show the records in the page based on the result for a specific field(Project_ID__C), but right now it showes the results if I put the exact value of that field(Project_ID__C), while I need it to show the results if I just enter a part of the value of that field(Project_ID__C). please advise:


 stdSetCont =  new ApexPages.StandardSetController(Database.getQueryLocator([Select id,,Project_ID__c from Charts__c where Project_ID__c =: ProjectSearch and HRS_Site_ID__c =: ApexPages.CurrentPage().getParameters().get('hrsId') Limit 10000]));
        
Hi Everyone,

I want to have a validation rule to prevent special characters in text field except these 2: (.) and (‘).  please advise. thanks
Hi  Everyone, I have a trigger that updates the child records if there is a change on the parent record. my problem is if I change certain fields on the child records, it changes the value of the rollup summaty fields on the parent and fires the trigger. So I added the conditon like this to prevent that: 

if ((c.TCR_Total_Charts__c != oldProj.TCR_Total_Charts__c) || (c.TCR_Total_Delivered__c != oldProj.TCR_Total_Delivered__c) ||
        (c.TCR_Total_Scheduled__c != oldProj.TCR_Total_Scheduled__c)) {
            isExecute = TRUE;
        }
    }
    
    if(isExecute = false){


but now even if I change other  fields on the parent , it does not fire the trigger. Please help me if you know a solution for this. below is the whole trigger. thanks








trigger ProjectSettings_ChartsTrigger on Project_Setting__c (After Insert,After Update){
    List<id> ProjectIds = new list<id>();
    List<Project_Setting__c > prj = [select Id, Total_Charts__c from Project_Setting__c where Id In : ProjectIds];
    boolean isfalse = false;
    String userName = UserInfo.getUserName();
    string Profile = UserInfo.getprofileId();
    
    Boolean isExecute = false;
    
    for (Project_Setting__c c : Trigger.new) {
        Project_Setting__c oldProj = Trigger.oldMap.get(c.ID);
        if ((c.TCR_Total_Charts__c != oldProj.TCR_Total_Charts__c) || (c.TCR_Total_Delivered__c != oldProj.TCR_Total_Delivered__c) ||
        (c.TCR_Total_Scheduled__c != oldProj.TCR_Total_Scheduled__c)) {
            isExecute = TRUE;
        }
    }
    
    if(isExecute = false){
        if(userName != 'arash' && profile != 'xxxxx' && profile != 'xxxxx' && profile != 'xxxx'){ 
            for(Project_Setting__c PS : Trigger.new){
                if (PS.Total_Charts__c < 2000) {
                    ProjectIds.add(PS.id);
                    isfalse = true;  
                }
                else{
                    ProjectSettings_ChartsBatchClass pro = new ProjectSettings_ChartsBatchClass(); 
                    database.executebatch(pro,2000);
                }
            } 
            if ( isfalse ){
                projectSettingsChartClass.ProjectMethods(ProjectIds);
            }
        }
    }
}
Hi Everyone, I'm trying to update a custom field on my sample object with the creation date of any task that is created. I receive the following error when I try to save the trigger:


Error: Compile Error: Initial term of field expression must be a concrete SObject: List<OpenActivity> at line 8 column 2

below is my trigger:

trigger UpdatePresDate on Task(after insert, after delete){
 Set<ID> tWhatIDs = new Set<ID>();
Task t= Trigger.new[0];
List<Sample__c> acclist = new List<Sample__C>();
    List<OpenActivity> openlist = new List<OpenActivity>();
    
 acclist = [Select Score__C, (Select Id, CreatedDate From OpenActivities where isTask =: true ) From Sample__C where Id IN: tWhatIDs];
 openlist.CreatedDate = acclist.Score__C;
update acclist;
}


what should I change in my trigger? Thanks in advance


 
Hi I receive this error for some of the batches. I found out that if I use "FOR Update" in my querry the problem will be solved. can someone help me to how should I add "for update" to my batch? thanks in advance


global class ProjectSettings_ChartsBatchClass implements Database.Batchable<sObject>{
    // Start Method
    global Database.QueryLocator start(Database.BatchableContext BC){
      
      
        return Database.getQueryLocator([select id,Project_Name__c,Project_Name__r.Parent_Project_Name__c,Project_Name__r.Healthplan_Contact__c,Project_Name__r.PR_Number__c,
                                 Project_Name__r.Line_Of_Business__c,Project_Name__r.Requestor__c,Project_Name__r.Project_End_Date__c,
                                 Project_Name__r.Project_Start_Date__c,Project_Name__r.ChartSecure_Account_Manager__r.Name,Project_Name__r.Extended_Project_End_Date__c,Project_Name__r.Project_Closed__c,
                                 Project_Name__r.Date_Project_Closed__c,Project_Name__r.Copy_Cost__c,Project_Name__r.Onsite_Threshold__c,
                                 Project_Name__r.Reporting_Active__c from charts__c where Project_Name__r.Total_Charts__c > 2000 and Project_Name__r.time_check__c < 3 ]);
    }
    global void execute(Database.BatchableContext BC, List<charts__c> scope){
             
        List<charts__c> Chart_All_Update = new List<charts__c>();
        for(charts__c Ps : scope){
            charts__c chart = new charts__c();
            chart.id = Ps.id;
            chart.Parent_Project_Name__c = Ps.Project_Name__r.Parent_Project_Name__c;
            chart.Healthplan_Contact__c = Ps.Project_Name__r.Healthplan_Contact__c;
            chart.Client_Number__c = Ps.Project_Name__r.PR_Number__c;
            chart.Line_of_Business__c = Ps.Project_Name__r.Line_Of_Business__c;
            Chart.Healthplan_Account_Manager__c = Ps.Project_Name__r.ChartSecure_Account_Manager__r.Name;
            chart.Healthplan_Requestor__c = Ps.Project_Name__r.Requestor__c;
            chart.Project_End_Date__c = Ps.Project_Name__r.Project_End_Date__c;
            chart.Project_Start_Date__c = Ps.Project_Name__r.Project_Start_Date__c;
            chart.Extended_Project_End_Date__c = Ps.Project_Name__r.Extended_Project_End_Date__c;
            chart.Project_Closed__c = Ps.Project_Name__r.Project_Closed__c;
            chart.Date_Project_Closed__c= Ps.Project_Name__r.Date_Project_Closed__c;
            chart.Copy_Cost__c = Ps.Project_Name__r.Copy_Cost__c;
            chart.Onsite_Threshold__c = Ps.Project_Name__r.Onsite_Threshold__c;
            chart.Reporting_Active__c = Ps.Project_Name__r.Reporting_Active__c;
            Chart_All_Update.add(chart);
        }
        if(Chart_All_Update.size() > 0){
            Update Chart_All_Update;
        }
       
    }  
    global void finish(Database.BatchableContext BC){
        
    }
}
Hi, I am trying to write a trigger to call a btach class if a check box is true, otherwise call the future class. but IDK what is wrong with my code I can't save it. please advise. here is my code:

trigger ProjectSettings_ChartsTrigger on Project_Setting__c (After Insert,After Update){
    
    List<id> ProjectIds = new list<id>();
    List<Project_Setting__c > prj = [select Id, total_check__c from Project_Setting__c where Id In : ProjectIds];
    for(Project_Setting__c PS : Trigger.new){
    if (Project_Setting__c.total_check__c = true) {
      ProjectIds.add(PS.id);   
    }
    ProjectSettings_ChartsBatchClass pro = new ProjectSettings_ChartsBatchClass(); 
              database.executebatch(pro,2000);
} if (Project_Setting__c.total_check__c = false){
     projectSettingsChartClass.ProjectMethods(ProjectIds);
    }
    

Thanks
Hi,
 

I have a batch that when I run I get the too many querry rows:50001 error. the reason I'm using this batch is because som of my parent records has more than 200 thousand childs adn I need to update the. please advise:


global class ProjectSettings_ChartsTriggerBatchClass implements Database.Batchable<sObject>{
    // Start Method
    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator([Select Id,Name,Parent_Project_Name__c,Healthplan_Contact__c,PR_Number__c,
        Line_Of_Business__c,ChartSecure_Account_Manager__r.Name,Covering_Account_Manager__r.Name,Requestor__c,
        Project_End_Date__c,Project_Start_Date__c,Extended_Project_End_Date__c,Project_Closed__c,Date_Project_Closed__c,
        Copy_Cost__c,Onsite_Threshold__c,Reporting_Active__c from Project_Setting__c]);
    }
    global void execute(Database.BatchableContext BC, List<Project_Setting__c> scope){
        Set<id> ProjectIds = new Set<id>();
        for(Project_Setting__c PS : scope){
            ProjectIds.add(PS.id);   
        }
        List<charts__c> ChartListFirst = [select id,Project_Name__c,Parent_Project_Name__c,Healthplan_Contact__c,Client_Number__c,Line_of_Business__c,
                                 Healthplan_Account_Manager__c,Healthplan_Requestor__c,Covering_Account_Manager__c,Project_End_Date__c,
                                 Project_Start_Date__c,Extended_Project_End_Date__c,Project_Closed__c,Date_Project_Closed__c,Copy_Cost__c,Onsite_Threshold__c,
                                 Reporting_Active__c from charts__c where Project_Name__c In : ProjectIds limit 50000];
    
        
        set<id> FirstIds = new set<id>();
        for(charts__c c : ChartListFirst){
            FirstIds.add(c.id);
        }
        
        List<charts__c> ChartListSecond = [select id,Project_Name__c,Parent_Project_Name__c,Healthplan_Contact__c,Client_Number__c,Line_of_Business__c,
                                 Healthplan_Account_Manager__c,Healthplan_Requestor__c,Covering_Account_Manager__c,Project_End_Date__c,
                                 Project_Start_Date__c,Extended_Project_End_Date__c,Project_Closed__c,Date_Project_Closed__c,Copy_Cost__c,Onsite_Threshold__c,
                                 Reporting_Active__c from charts__c where Project_Name__c In : ProjectIds and id Not In : FirstIds limit 50000];
    
        
        set<id> SecondIds = new set<id>();
        for(charts__c c : ChartListFirst){
            SecondIds.add(c.id);
        }
        for(charts__c c : ChartListSecond){
            SecondIds.add(c.id);
        }
        
        List<charts__c> ChartListThird = [select id,Project_Name__c,Parent_Project_Name__c,Healthplan_Contact__c,Client_Number__c,Line_of_Business__c,
                                 Healthplan_Account_Manager__c,Healthplan_Requestor__c,Covering_Account_Manager__c,Project_End_Date__c,
                                 Project_Start_Date__c,Extended_Project_End_Date__c,Project_Closed__c,Date_Project_Closed__c,Copy_Cost__c,Onsite_Threshold__c,
                                 Reporting_Active__c from charts__c where Project_Name__c In : ProjectIds and id Not In : SecondIds limit 50000];
    
        List<charts__c> UpdateChartList = new List<charts__c>();
    
        for(Project_Setting__c Ps : scope){
            for(charts__c ch : ChartListFirst){        
                if(ch.Project_Name__c == Ps.id){
                    ch.Parent_Project_Name__c = Ps.Parent_Project_Name__c;
                    Ch.Healthplan_Contact__c = Ps.Healthplan_Contact__c;
                    Ch.Client_Number__c = Ps.PR_Number__c;
                    Ch.Line_of_Business__c = Ps.Line_Of_Business__c;
                    Ch.Healthplan_Account_Manager__c = Ps.ChartSecure_Account_Manager__r.Name;
                    Ch.Healthplan_Requestor__c = Ps.Requestor__c;
                    Ch.Covering_Account_Manager__c = Ps.Covering_Account_Manager__r.Name;
                    Ch.Project_End_Date__c = Ps.Project_End_Date__c;
                    Ch.Project_Start_Date__c = Ps.Project_Start_Date__c;
                    Ch.Extended_Project_End_Date__c = Ps.Extended_Project_End_Date__c;
                    Ch.Project_Closed__c = Ps.Project_Closed__c;
                    Ch.Date_Project_Closed__c= Ps.Date_Project_Closed__c;
                    Ch.Copy_Cost__c = Ps.Copy_Cost__c;
                    Ch.Onsite_Threshold__c = Ps.Onsite_Threshold__c;
                    Ch.Reporting_Active__c = Ps.Reporting_Active__c;
                    UpdateChartList.Add(ch);   
                }
            }    
        }
        
        for(Project_Setting__c Ps : scope){
            for(charts__c ch : ChartListSecond){        
                if(ch.Project_Name__c == Ps.id){
                    ch.Parent_Project_Name__c = Ps.Parent_Project_Name__c;
                    Ch.Healthplan_Contact__c = Ps.Healthplan_Contact__c;
                    Ch.Client_Number__c = Ps.PR_Number__c;
                    Ch.Line_of_Business__c = Ps.Line_Of_Business__c;
                    Ch.Healthplan_Account_Manager__c = Ps.ChartSecure_Account_Manager__r.Name;
                    Ch.Healthplan_Requestor__c = Ps.Requestor__c;
                    Ch.Covering_Account_Manager__c = Ps.Covering_Account_Manager__r.Name;
                    Ch.Project_End_Date__c = Ps.Project_End_Date__c;
                    Ch.Project_Start_Date__c = Ps.Project_Start_Date__c;
                    Ch.Extended_Project_End_Date__c = Ps.Extended_Project_End_Date__c;
                    Ch.Project_Closed__c = Ps.Project_Closed__c;
                    Ch.Date_Project_Closed__c= Ps.Date_Project_Closed__c;
                    Ch.Copy_Cost__c = Ps.Copy_Cost__c;
                    Ch.Onsite_Threshold__c = Ps.Onsite_Threshold__c;
                    Ch.Reporting_Active__c = Ps.Reporting_Active__c;
                    UpdateChartList.Add(ch);   
                }
            }    
        }
        
        for(Project_Setting__c Ps : scope){
            for(charts__c ch : ChartListThird){        
                if(ch.Project_Name__c == Ps.id){
                    ch.Parent_Project_Name__c = Ps.Parent_Project_Name__c;
                    Ch.Healthplan_Contact__c = Ps.Healthplan_Contact__c;
                    Ch.Client_Number__c = Ps.PR_Number__c;
                    Ch.Line_of_Business__c = Ps.Line_Of_Business__c;
                    Ch.Healthplan_Account_Manager__c = Ps.ChartSecure_Account_Manager__r.Name;
                    Ch.Healthplan_Requestor__c = Ps.Requestor__c;
                    Ch.Covering_Account_Manager__c = Ps.Covering_Account_Manager__r.Name;
                    Ch.Project_End_Date__c = Ps.Project_End_Date__c;
                    Ch.Project_Start_Date__c = Ps.Project_Start_Date__c;
                    Ch.Extended_Project_End_Date__c = Ps.Extended_Project_End_Date__c;
                    Ch.Project_Closed__c = Ps.Project_Closed__c;
                    Ch.Date_Project_Closed__c= Ps.Date_Project_Closed__c;
                    Ch.Copy_Cost__c = Ps.Copy_Cost__c;
                    Ch.Onsite_Threshold__c = Ps.Onsite_Threshold__c;
                    Ch.Reporting_Active__c = Ps.Reporting_Active__c;
                    UpdateChartList.Add(ch);   
                }
            }    
        }
        if(UpdateChartList.size() > 0 ){
            Update UpdateChartList;
        }
    }  
    
    global void finish(Database.BatchableContext BC){
        
    }
}
II'm getting this error when my trigger calls the following @future class:

Public class projectSettingsChartClass{
    @future
    public Static void ProjectMethods(List<id> PSList){
        Set<id> ProjectIds = new Set<id>();
        for(id PS : PSList){
            ProjectIds.add(PS);   
        }
        
        List<Project_Setting__c> PList = [select id,Name,Parent_Project_Name__c,Covering_Account_Manager__c,Healthplan_Contact__c,PR_Number__c,Line_Of_Business__c,ChartSecure_Account_Manager__r.Name,Requestor__c,Covering_Account_Manager__r.Name,Project_End_Date__c,Project_Start_Date__c,Extended_Project_End_Date__c,Project_Closed__c,Date_Project_Closed__c,Copy_Cost__c,Onsite_Threshold__c,Reporting_Active__c from Project_Setting__c where id In : ProjectIds];
        
        List<charts__c> ChartList = [select id,Project_Name__c,Parent_Project_Name__c,Healthplan_Contact__c,Client_Number__c,Line_of_Business__c,
                                 Healthplan_Account_Manager__c,Healthplan_Requestor__c,Covering_Account_Manager__c,Project_End_Date__c,
                                 Project_Start_Date__c,Extended_Project_End_Date__c,Project_Closed__c,Date_Project_Closed__c,Copy_Cost__c,Onsite_Threshold__c,
                                 Reporting_Active__c from charts__c where Project_Name__c In : ProjectIds];
    
        List<charts__c> UpdateChartList = new List<charts__c>();
    
        for(Project_Setting__c Ps : PList){
            for(charts__c ch : ChartList){        
                if(ch.Project_Name__c == Ps.id){
                    ch.Parent_Project_Name__c = Ps.Parent_Project_Name__c;
                    Ch.Healthplan_Contact__c = Ps.Healthplan_Contact__c;
                    Ch.Client_Number__c = Ps.PR_Number__c;
                    Ch.Line_of_Business__c = Ps.Line_Of_Business__c;
                    Ch.Healthplan_Account_Manager__c = Ps.ChartSecure_Account_Manager__r.Name;
                    Ch.Healthplan_Requestor__c = Ps.Requestor__c;
                    Ch.Covering_Account_Manager__c = Ps.Covering_Account_Manager__c;
                    Ch.Project_End_Date__c = Ps.Project_End_Date__c;
                    Ch.Project_Start_Date__c = Ps.Project_Start_Date__c;
                    Ch.Extended_Project_End_Date__c = Ps.Extended_Project_End_Date__c;
                    Ch.Project_Closed__c = Ps.Project_Closed__c;
                    Ch.Date_Project_Closed__c= Ps.Date_Project_Closed__c;
                    Ch.Copy_Cost__c = Ps.Copy_Cost__c;
                    Ch.Onsite_Threshold__c = Ps.Onsite_Threshold__c;
                    Ch.Reporting_Active__c = Ps.Reporting_Active__c;
                    UpdateChartList.Add(ch);   
                }
            }    
        }
        if(UpdateChartList.size() > 0 ){
            Update UpdateChartList;
        }
    }
}


why my future class cannot return more than 50000 querry rows?
I'm using the following to email my report as CSV but it just includes the first 2000 rowes in the csv file while my report has more than 50000 rowes. how can I solve this? thanks in advance:


global class Report implements System.Schedulable {
    global void execute(SchedulableContext sc) {
        ApexPages.PageReference report = new ApexPages.PageReference('/00O60000003XpO6?csv=1');
        Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
        attachment.setFileName('testcsv');
        attachment.setBody(report.getContent());
        attachment.setContentType('text/csv');
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        message.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment } );
        message.setSubject('test');
        message.setPlainTextBody('test is attached.');
        message.setToAddresses( new String[] { 'test@test.com' } );
        Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } );
        
    }
}
Hi everyone,

I have created a search bar(ProjectSearch) in VF page to show the records in the page based on the result for a specific field(Project_ID__C), but right now it showes the results if I put the exact value of that field(Project_ID__C), while I need it to show the results if I just enter a part of the value of that field(Project_ID__C). please advise:


 stdSetCont =  new ApexPages.StandardSetController(Database.getQueryLocator([Select id,,Project_ID__c from Charts__c where Project_ID__c =: ProjectSearch and HRS_Site_ID__c =: ApexPages.CurrentPage().getParameters().get('hrsId') Limit 10000]));
        
Hi Everyone,

I want to have a validation rule to prevent special characters in text field except these 2: (.) and (‘).  please advise. thanks
Hi  Everyone, I have a trigger that updates the child records if there is a change on the parent record. my problem is if I change certain fields on the child records, it changes the value of the rollup summaty fields on the parent and fires the trigger. So I added the conditon like this to prevent that: 

if ((c.TCR_Total_Charts__c != oldProj.TCR_Total_Charts__c) || (c.TCR_Total_Delivered__c != oldProj.TCR_Total_Delivered__c) ||
        (c.TCR_Total_Scheduled__c != oldProj.TCR_Total_Scheduled__c)) {
            isExecute = TRUE;
        }
    }
    
    if(isExecute = false){


but now even if I change other  fields on the parent , it does not fire the trigger. Please help me if you know a solution for this. below is the whole trigger. thanks








trigger ProjectSettings_ChartsTrigger on Project_Setting__c (After Insert,After Update){
    List<id> ProjectIds = new list<id>();
    List<Project_Setting__c > prj = [select Id, Total_Charts__c from Project_Setting__c where Id In : ProjectIds];
    boolean isfalse = false;
    String userName = UserInfo.getUserName();
    string Profile = UserInfo.getprofileId();
    
    Boolean isExecute = false;
    
    for (Project_Setting__c c : Trigger.new) {
        Project_Setting__c oldProj = Trigger.oldMap.get(c.ID);
        if ((c.TCR_Total_Charts__c != oldProj.TCR_Total_Charts__c) || (c.TCR_Total_Delivered__c != oldProj.TCR_Total_Delivered__c) ||
        (c.TCR_Total_Scheduled__c != oldProj.TCR_Total_Scheduled__c)) {
            isExecute = TRUE;
        }
    }
    
    if(isExecute = false){
        if(userName != 'arash' && profile != 'xxxxx' && profile != 'xxxxx' && profile != 'xxxx'){ 
            for(Project_Setting__c PS : Trigger.new){
                if (PS.Total_Charts__c < 2000) {
                    ProjectIds.add(PS.id);
                    isfalse = true;  
                }
                else{
                    ProjectSettings_ChartsBatchClass pro = new ProjectSettings_ChartsBatchClass(); 
                    database.executebatch(pro,2000);
                }
            } 
            if ( isfalse ){
                projectSettingsChartClass.ProjectMethods(ProjectIds);
            }
        }
    }
}
Hi Everyone, I'm trying to update a custom field on my sample object with the creation date of any task that is created. I receive the following error when I try to save the trigger:


Error: Compile Error: Initial term of field expression must be a concrete SObject: List<OpenActivity> at line 8 column 2

below is my trigger:

trigger UpdatePresDate on Task(after insert, after delete){
 Set<ID> tWhatIDs = new Set<ID>();
Task t= Trigger.new[0];
List<Sample__c> acclist = new List<Sample__C>();
    List<OpenActivity> openlist = new List<OpenActivity>();
    
 acclist = [Select Score__C, (Select Id, CreatedDate From OpenActivities where isTask =: true ) From Sample__C where Id IN: tWhatIDs];
 openlist.CreatedDate = acclist.Score__C;
update acclist;
}


what should I change in my trigger? Thanks in advance


 
Hi I receive this error for some of the batches. I found out that if I use "FOR Update" in my querry the problem will be solved. can someone help me to how should I add "for update" to my batch? thanks in advance


global class ProjectSettings_ChartsBatchClass implements Database.Batchable<sObject>{
    // Start Method
    global Database.QueryLocator start(Database.BatchableContext BC){
      
      
        return Database.getQueryLocator([select id,Project_Name__c,Project_Name__r.Parent_Project_Name__c,Project_Name__r.Healthplan_Contact__c,Project_Name__r.PR_Number__c,
                                 Project_Name__r.Line_Of_Business__c,Project_Name__r.Requestor__c,Project_Name__r.Project_End_Date__c,
                                 Project_Name__r.Project_Start_Date__c,Project_Name__r.ChartSecure_Account_Manager__r.Name,Project_Name__r.Extended_Project_End_Date__c,Project_Name__r.Project_Closed__c,
                                 Project_Name__r.Date_Project_Closed__c,Project_Name__r.Copy_Cost__c,Project_Name__r.Onsite_Threshold__c,
                                 Project_Name__r.Reporting_Active__c from charts__c where Project_Name__r.Total_Charts__c > 2000 and Project_Name__r.time_check__c < 3 ]);
    }
    global void execute(Database.BatchableContext BC, List<charts__c> scope){
             
        List<charts__c> Chart_All_Update = new List<charts__c>();
        for(charts__c Ps : scope){
            charts__c chart = new charts__c();
            chart.id = Ps.id;
            chart.Parent_Project_Name__c = Ps.Project_Name__r.Parent_Project_Name__c;
            chart.Healthplan_Contact__c = Ps.Project_Name__r.Healthplan_Contact__c;
            chart.Client_Number__c = Ps.Project_Name__r.PR_Number__c;
            chart.Line_of_Business__c = Ps.Project_Name__r.Line_Of_Business__c;
            Chart.Healthplan_Account_Manager__c = Ps.Project_Name__r.ChartSecure_Account_Manager__r.Name;
            chart.Healthplan_Requestor__c = Ps.Project_Name__r.Requestor__c;
            chart.Project_End_Date__c = Ps.Project_Name__r.Project_End_Date__c;
            chart.Project_Start_Date__c = Ps.Project_Name__r.Project_Start_Date__c;
            chart.Extended_Project_End_Date__c = Ps.Project_Name__r.Extended_Project_End_Date__c;
            chart.Project_Closed__c = Ps.Project_Name__r.Project_Closed__c;
            chart.Date_Project_Closed__c= Ps.Project_Name__r.Date_Project_Closed__c;
            chart.Copy_Cost__c = Ps.Project_Name__r.Copy_Cost__c;
            chart.Onsite_Threshold__c = Ps.Project_Name__r.Onsite_Threshold__c;
            chart.Reporting_Active__c = Ps.Project_Name__r.Reporting_Active__c;
            Chart_All_Update.add(chart);
        }
        if(Chart_All_Update.size() > 0){
            Update Chart_All_Update;
        }
       
    }  
    global void finish(Database.BatchableContext BC){
        
    }
}
Hi, I am trying to write a trigger to call a btach class if a check box is true, otherwise call the future class. but IDK what is wrong with my code I can't save it. please advise. here is my code:

trigger ProjectSettings_ChartsTrigger on Project_Setting__c (After Insert,After Update){
    
    List<id> ProjectIds = new list<id>();
    List<Project_Setting__c > prj = [select Id, total_check__c from Project_Setting__c where Id In : ProjectIds];
    for(Project_Setting__c PS : Trigger.new){
    if (Project_Setting__c.total_check__c = true) {
      ProjectIds.add(PS.id);   
    }
    ProjectSettings_ChartsBatchClass pro = new ProjectSettings_ChartsBatchClass(); 
              database.executebatch(pro,2000);
} if (Project_Setting__c.total_check__c = false){
     projectSettingsChartClass.ProjectMethods(ProjectIds);
    }
    

Thanks
Hi,
 

I have a batch that when I run I get the too many querry rows:50001 error. the reason I'm using this batch is because som of my parent records has more than 200 thousand childs adn I need to update the. please advise:


global class ProjectSettings_ChartsTriggerBatchClass implements Database.Batchable<sObject>{
    // Start Method
    global Database.QueryLocator start(Database.BatchableContext BC){
        return Database.getQueryLocator([Select Id,Name,Parent_Project_Name__c,Healthplan_Contact__c,PR_Number__c,
        Line_Of_Business__c,ChartSecure_Account_Manager__r.Name,Covering_Account_Manager__r.Name,Requestor__c,
        Project_End_Date__c,Project_Start_Date__c,Extended_Project_End_Date__c,Project_Closed__c,Date_Project_Closed__c,
        Copy_Cost__c,Onsite_Threshold__c,Reporting_Active__c from Project_Setting__c]);
    }
    global void execute(Database.BatchableContext BC, List<Project_Setting__c> scope){
        Set<id> ProjectIds = new Set<id>();
        for(Project_Setting__c PS : scope){
            ProjectIds.add(PS.id);   
        }
        List<charts__c> ChartListFirst = [select id,Project_Name__c,Parent_Project_Name__c,Healthplan_Contact__c,Client_Number__c,Line_of_Business__c,
                                 Healthplan_Account_Manager__c,Healthplan_Requestor__c,Covering_Account_Manager__c,Project_End_Date__c,
                                 Project_Start_Date__c,Extended_Project_End_Date__c,Project_Closed__c,Date_Project_Closed__c,Copy_Cost__c,Onsite_Threshold__c,
                                 Reporting_Active__c from charts__c where Project_Name__c In : ProjectIds limit 50000];
    
        
        set<id> FirstIds = new set<id>();
        for(charts__c c : ChartListFirst){
            FirstIds.add(c.id);
        }
        
        List<charts__c> ChartListSecond = [select id,Project_Name__c,Parent_Project_Name__c,Healthplan_Contact__c,Client_Number__c,Line_of_Business__c,
                                 Healthplan_Account_Manager__c,Healthplan_Requestor__c,Covering_Account_Manager__c,Project_End_Date__c,
                                 Project_Start_Date__c,Extended_Project_End_Date__c,Project_Closed__c,Date_Project_Closed__c,Copy_Cost__c,Onsite_Threshold__c,
                                 Reporting_Active__c from charts__c where Project_Name__c In : ProjectIds and id Not In : FirstIds limit 50000];
    
        
        set<id> SecondIds = new set<id>();
        for(charts__c c : ChartListFirst){
            SecondIds.add(c.id);
        }
        for(charts__c c : ChartListSecond){
            SecondIds.add(c.id);
        }
        
        List<charts__c> ChartListThird = [select id,Project_Name__c,Parent_Project_Name__c,Healthplan_Contact__c,Client_Number__c,Line_of_Business__c,
                                 Healthplan_Account_Manager__c,Healthplan_Requestor__c,Covering_Account_Manager__c,Project_End_Date__c,
                                 Project_Start_Date__c,Extended_Project_End_Date__c,Project_Closed__c,Date_Project_Closed__c,Copy_Cost__c,Onsite_Threshold__c,
                                 Reporting_Active__c from charts__c where Project_Name__c In : ProjectIds and id Not In : SecondIds limit 50000];
    
        List<charts__c> UpdateChartList = new List<charts__c>();
    
        for(Project_Setting__c Ps : scope){
            for(charts__c ch : ChartListFirst){        
                if(ch.Project_Name__c == Ps.id){
                    ch.Parent_Project_Name__c = Ps.Parent_Project_Name__c;
                    Ch.Healthplan_Contact__c = Ps.Healthplan_Contact__c;
                    Ch.Client_Number__c = Ps.PR_Number__c;
                    Ch.Line_of_Business__c = Ps.Line_Of_Business__c;
                    Ch.Healthplan_Account_Manager__c = Ps.ChartSecure_Account_Manager__r.Name;
                    Ch.Healthplan_Requestor__c = Ps.Requestor__c;
                    Ch.Covering_Account_Manager__c = Ps.Covering_Account_Manager__r.Name;
                    Ch.Project_End_Date__c = Ps.Project_End_Date__c;
                    Ch.Project_Start_Date__c = Ps.Project_Start_Date__c;
                    Ch.Extended_Project_End_Date__c = Ps.Extended_Project_End_Date__c;
                    Ch.Project_Closed__c = Ps.Project_Closed__c;
                    Ch.Date_Project_Closed__c= Ps.Date_Project_Closed__c;
                    Ch.Copy_Cost__c = Ps.Copy_Cost__c;
                    Ch.Onsite_Threshold__c = Ps.Onsite_Threshold__c;
                    Ch.Reporting_Active__c = Ps.Reporting_Active__c;
                    UpdateChartList.Add(ch);   
                }
            }    
        }
        
        for(Project_Setting__c Ps : scope){
            for(charts__c ch : ChartListSecond){        
                if(ch.Project_Name__c == Ps.id){
                    ch.Parent_Project_Name__c = Ps.Parent_Project_Name__c;
                    Ch.Healthplan_Contact__c = Ps.Healthplan_Contact__c;
                    Ch.Client_Number__c = Ps.PR_Number__c;
                    Ch.Line_of_Business__c = Ps.Line_Of_Business__c;
                    Ch.Healthplan_Account_Manager__c = Ps.ChartSecure_Account_Manager__r.Name;
                    Ch.Healthplan_Requestor__c = Ps.Requestor__c;
                    Ch.Covering_Account_Manager__c = Ps.Covering_Account_Manager__r.Name;
                    Ch.Project_End_Date__c = Ps.Project_End_Date__c;
                    Ch.Project_Start_Date__c = Ps.Project_Start_Date__c;
                    Ch.Extended_Project_End_Date__c = Ps.Extended_Project_End_Date__c;
                    Ch.Project_Closed__c = Ps.Project_Closed__c;
                    Ch.Date_Project_Closed__c= Ps.Date_Project_Closed__c;
                    Ch.Copy_Cost__c = Ps.Copy_Cost__c;
                    Ch.Onsite_Threshold__c = Ps.Onsite_Threshold__c;
                    Ch.Reporting_Active__c = Ps.Reporting_Active__c;
                    UpdateChartList.Add(ch);   
                }
            }    
        }
        
        for(Project_Setting__c Ps : scope){
            for(charts__c ch : ChartListThird){        
                if(ch.Project_Name__c == Ps.id){
                    ch.Parent_Project_Name__c = Ps.Parent_Project_Name__c;
                    Ch.Healthplan_Contact__c = Ps.Healthplan_Contact__c;
                    Ch.Client_Number__c = Ps.PR_Number__c;
                    Ch.Line_of_Business__c = Ps.Line_Of_Business__c;
                    Ch.Healthplan_Account_Manager__c = Ps.ChartSecure_Account_Manager__r.Name;
                    Ch.Healthplan_Requestor__c = Ps.Requestor__c;
                    Ch.Covering_Account_Manager__c = Ps.Covering_Account_Manager__r.Name;
                    Ch.Project_End_Date__c = Ps.Project_End_Date__c;
                    Ch.Project_Start_Date__c = Ps.Project_Start_Date__c;
                    Ch.Extended_Project_End_Date__c = Ps.Extended_Project_End_Date__c;
                    Ch.Project_Closed__c = Ps.Project_Closed__c;
                    Ch.Date_Project_Closed__c= Ps.Date_Project_Closed__c;
                    Ch.Copy_Cost__c = Ps.Copy_Cost__c;
                    Ch.Onsite_Threshold__c = Ps.Onsite_Threshold__c;
                    Ch.Reporting_Active__c = Ps.Reporting_Active__c;
                    UpdateChartList.Add(ch);   
                }
            }    
        }
        if(UpdateChartList.size() > 0 ){
            Update UpdateChartList;
        }
    }  
    
    global void finish(Database.BatchableContext BC){
        
    }
}

Hi,

 

I need to construct a CSV file with APEX and am a bit new to this cloud computing.

Do you have any sample code I could get started with that, or a resources that you can point me to develop and generate a  CSV File to send through the Email??

 

Can this be achieved in salesforce by any Way?

  • December 29, 2011
  • Like
  • 0