• Mahatma Vijay
  • NEWBIE
  • 60 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 10
    Replies
Hello folks,

Could someone guide me with this issue. I created a JSON file to use it as a Static resource for one of my VF page. I've uploaded it into my Sandbox as a .json file but after upload it's not showing as a json file. Instead it is showing as an octet-stream. 
​Can some help me with this. Am I missing something here?
Thanks
Hi, 

I have a requirement to create a report of all 30k contact records in the org and saving it on a common folder shared in the company and it should get updated once every week. So basically I tried a few things.
1) Reports cannot hold more than 2000 rows and didn't work.
2) Scheduled a Bulk Apex job and able to generate a report with all the records. But it cannot be save in the destination folder as required so it didn't work.
3) Used Command Line Data Loader Process and created key.txt, contactExtractMap.sdl, process-conf.sml files and able to generate a report and save it on the destination folder as required. It is also able to update the record instead of creating a new record everytime when I run Command line manually.

So my requirement here is, can I automate this report generation instead of doing it manually everytime using command line? Like can I link a schedule job to this command line operation or anything like that?

Any ideas?
Hi, I created a Schedulable class to send a CSV file to an email. While I'm testing it I got this error to my e-mail instead of a CSV file. Can anyone help me with this? I'm attaching the code here.
global class ExporterCSV implements System.Schedulable {
    
	global void execute(SchedulableContext sc) {
	List<Contact> conList = [Select id , Lastname, FirstName , CreatedDate , lastModifiedDate from Contact];
	string header = 'Record Id ,Last Name, First Name , Created Date , Modified Date \n';
	string finalstr = header ;
        
	for(Contact a: conList)
	{
   string recordString = a.id + ',' + a.Lastname+',' + a.FirstName + ',' + a.CreatedDate + ',' + a.LastModifiedDate + '\n';
   finalstr = finalstr + recordString;
	}
        
	Messaging.EmailFileAttachment csvAttc = new Messaging.EmailFileAttachment();
	blob csvBlob = Blob.valueOf(finalstr);
	string csvname= 'Contacts.csv';
	csvAttc.setFileName(csvname);
	csvAttc.setBody(csvBlob);
	Messaging.SingleEmailMessage email =new Messaging.SingleEmailMessage();
	String[] toAddresses = new list<string> {'xxxxxxxxxxxxx@gmail.com'};
	String subject = 'Contacts Report CSV';
	email.setSubject(subject);
	email.setToAddresses( toAddresses );
	email.setPlainTextBody('The Contacts report is attached here.');
	email.setFileAttachments(new Messaging.EmailFileAttachment[]{csvAttc});
        
	//Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
	Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
	//system.debug(r);
  }
}
Error message I got :

Sandbox
 
Apex script unhandled exception by user/organization: xxxxxxxxxxxxx/yyyyyyyyyyyyyy Source organization: zzzzzzzzzzzzzz (null) Scheduled job 'Email Contact test' threw unhandled exception.
 
caused by: System.LimitException: Apex CPU time limit exceeded
 
Class.ExporterCSV.execute: line 14, column 1

 
How can we set field history tracking for an already existing custom field on a custom object? Is it possible?
Hi, 
So we have an object 'Asset' with one of fields as 'Software version number'. We want to track the software version number in Case Object and created a formula field so whenever a client generates a case the software version number will auto-populate the field. So here's the issue- When the software version changes (In asset object) as the client upgrades their software, this version number we have on Case object is also updating. Is there a way to store the old software version in the Case object even after the information in Asset object's 'software version number' field changes? Can someone help me with this? I'm sorry it's a little confusing. Can I do it using workflows and/or process builder or should I go for hardcoding?
Hi, 

So we have an object 'Asset' with one of fields as 'Software version number'. We want to track the software version number in Case Object and created a formula field so whenever a client generates a case the software version number will auto-populate the field. So here's the issue- When the software version changes (In asset object) as the client upgrades their software, this version number we have on Case object is also updating. Is there a way to store the old software version in the Case object even after the information in Asset object's 'software version number' field changes? Can someone help me with this? I'm sorry it's a little confusing. Can I do it using workflows and/or process builder or should I go for hardcoding?
I did a test run on this class and it gave me an error. Can someone guide me as to how I can run this test successfully?
@isTest
private class F8_Test_AssignmentGroupQueue {

    static testMethod void F8_Test_AssignmentGroupQueue() {
      Assignment_Group__c objAssignmentGroup = new Assignment_Group__c(Name='Test_AG');
      insert objAssignmentGroup;
        
        Group g1 = new Group(Name='group name', type='Queue');
      insert g1;
        QueuesObject q1 = new QueueSObject(QueueID = g1.id, SobjectType = 'Assignment_Group__c');
        insert q1;
        
        Group g2 = new Group(Name='group name2', type='Queue');
      insert g2;
        QueuesObject q2 = new QueueSObject(QueueID = g2.id, SobjectType = 'Assignment_Group__c');        
        insert q2;
        
        Group g3 = new Group(Name='group name3', type='Queue');
      insert g3;
        QueuesObject q3 = new QueueSObject(QueueID = g3.id, SobjectType = 'Assignment_Group__c');        
        insert q3;
        
        Assignment_Group_Queue__c objAssignmentGroupQueue = new Assignment_Group_Queue__c(Name = 'group name', Active__c = 'True', Assignment_Group_Name__c = objAssignmentGroup.Id, QueueId__c = g1.id, Valid_Queue__c = true);
        insert objAssignmentGroupQueue;
                                       
    Assignment_Group_Queue__c objAssignmentGroupQueue2 = new Assignment_Group_Queue__c(Name = 'group name2', Active__c = 'True', Assignment_Group_Name__c = objAssignmentGroup.Id, QueueId__c = g1.id, Valid_Queue__c = true);
        insert objAssignmentGroupQueue2;
        
        objAssignmentGroupQueue.Active__c = 'False';
        update  objAssignmentGroupQueue;
        
        objAssignmentGroupQueue.Name = 'group name3';
        update objAssignmentGroupQueue;
        
        try{
          objAssignmentGroupQueue.Name = 'group name2';
          update objAssignmentGroupQueue;  
        }
        catch(Exception ex){
          system.debug('## Exception is ::' + ex);  
        }
        
        Assignment_Group_Queue__c objAssignmentGroupQueue3 = new Assignment_Group_Queue__c();
        try{
          objAssignmentGroupQueue3 = new Assignment_Group_Queue__c(Name = 'group name2', Active__c = 'True', Assignment_Group_Name__c = objAssignmentGroup.Id, QueueId__c = g1.id, Valid_Queue__c = true);
          insert objAssignmentGroupQueue3;
        }
        catch(Exception ex){
          system.debug('## Exception is ::' + ex);
          System.assertEquals(objAssignmentGroupQueue3.Id, null);    
        }
        
        try{
          objAssignmentGroupQueue3 = new Assignment_Group_Queue__c(Name = 'group name23', Active__c = 'True', Assignment_Group_Name__c = objAssignmentGroup.Id, QueueId__c = g1.id, Valid_Queue__c = true);
          insert objAssignmentGroupQueue3;
        }
        catch(Exception ex){
          system.debug('## Exception is ::' + ex);
          System.assertEquals(objAssignmentGroupQueue3.Id, null);    
        }
        
        try{
          objAssignmentGroupQueue.Name = 'group name23';
          update objAssignmentGroupQueue;  
        }
        catch(Exception ex){
          system.debug('## Exception is ::' + ex);  
        }    
    }
}

Errors:

System.DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): QueueSobject, original object: Assignment_Group__c: []

Stack Trace:

Class.F8_Test_AssignmentGroupQueue.F8_Test_AssignmentGroupQueue: line 32, column 1
 
/**
 * An apex class that keeps updates of a portal user in sync with its corresponding contact.
   Guest users are never able to access this page.
 */
public with sharing class MyProfilePageController {

    private User user;
    private boolean isEdit = false;

    public User getUser() {
        return user;
    }

    public MyProfilePageController() {
        user = [SELECT id, email, username, usertype, communitynickname, timezonesidkey, languagelocalekey, firstname, lastname, phone, title,
                street, city, countryCode, postalcode, stateCode, localesidkey, mobilephone, extension, fax, contact.email
                FROM User
                WHERE id = :UserInfo.getUserId()];
        // guest users should never be able to access this page
        if (user.usertype == 'GUEST') {
            throw new NoAccessException();
        }
    }

    public Boolean getIsEdit() {
        return isEdit;
    }

    public void edit() {
        isEdit=true;
    }

    public void save() {
        if (user.contact != null) {
            setContactFields(user.contact, user);
        }

        try {
            update user;
            if (user.contact != null) {
                update user.contact;
            }
            isEdit=false;
        } catch(DmlException e) {
            ApexPages.addMessages(e);
        }
    }

    public PageReference changePassword() {
        return Page.ChangePassword;
    }

    public void cancel() {
        isEdit=false;
        user = [SELECT id, email, username, communitynickname, timezonesidkey, languagelocalekey, firstname, lastname, phone, title,
                street, city, countryCode, postalcode, stateCode, localesidkey, mobilephone, extension, fax, contact.email
                FROM User
                WHERE id = :UserInfo.getUserId()];
    }

    public static void setContactFields(Contact c, User u) {
        c.title = u.title;
        c.firstname = u.firstname;
        c.lastname = u.lastname;
        c.email = u.email;
        c.phone = u.phone;
        c.mobilephone = u.mobilephone;
        c.fax = u.fax;
        c.mailingstreet = u.street;
        c.mailingcity = u.city;
        c.mailingstate = u.state;
        c.mailingpostalcode = u.postalcode;
        c.mailingcountry = u.country;
    }
}
Hi, 

So we have an object called 'Asset' with one of fields as 'Software version number'. We want to track the software version number in Case Object. Whenever a client generates a case we want the software version number to auto-populate the field. I thought of creating a field on Case and giving a lookup relationship and/or creating a formula field to pull this information into Case. So here's the issue- When the software version changes (In asset object) as the client upgrades their software, this version number we have on case object is also updating. Is there a way to store the old software version in the case object even after the information in Asset field changes? Can I create a custom field in Asset object to save that information and pull this into Case Object? Can someone help me with this? I'm sorry it's a little confusing
Can someone help me with writing a test class for the following code? This is my first test class and struggling where/how to start. Appreciate any help.

/**
 * An apex class that keeps updates of a portal user in sync with its corresponding contact.
   Guest users are never able to access this page.
 */
public with sharing class MyProfilePageController {

    private User user;
    private boolean isEdit = false;

    public User getUser() {
        return user;
    }

    public MyProfilePageController() {
        user = [SELECT id, email, username, usertype, communitynickname, timezonesidkey, languagelocalekey, firstname, lastname, phone, title,
                street, city, countryCode, postalcode, stateCode, localesidkey, mobilephone, extension, fax, contact.email
                FROM User
                WHERE id = :UserInfo.getUserId()];
        // guest users should never be able to access this page
        if (user.usertype == 'GUEST') {
            throw new NoAccessException();
        }
    }

    public Boolean getIsEdit() {
        return isEdit;
    }

    public void edit() {
        isEdit=true;
    }

    public void save() {
        if (user.contact != null) {
            setContactFields(user.contact, user);
        }

        try {
            update user;
            if (user.contact != null) {
                update user.contact;
            }
            isEdit=false;
        } catch(DmlException e) {
            ApexPages.addMessages(e);
        }
    }

    public PageReference changePassword() {
        return Page.ChangePassword;
    }

    public void cancel() {
        isEdit=false;
        user = [SELECT id, email, username, communitynickname, timezonesidkey, languagelocalekey, firstname, lastname, phone, title,
                street, city, countryCode, postalcode, stateCode, localesidkey, mobilephone, extension, fax, contact.email
                FROM User
                WHERE id = :UserInfo.getUserId()];
    }

    public static void setContactFields(Contact c, User u) {
        c.title = u.title;
        c.firstname = u.firstname;
        c.lastname = u.lastname;
        c.email = u.email;
        c.phone = u.phone;
        c.mobilephone = u.mobilephone;
        c.fax = u.fax;
        c.mailingstreet = u.street;
        c.mailingcity = u.city;
        c.mailingstate = u.state;
        c.mailingpostalcode = u.postalcode;
        c.mailingcountry = u.country;
    }
}
Hello folks,

Could someone guide me with this issue. I created a JSON file to use it as a Static resource for one of my VF page. I've uploaded it into my Sandbox as a .json file but after upload it's not showing as a json file. Instead it is showing as an octet-stream. 
​Can some help me with this. Am I missing something here?
Thanks
Hi, I created a Schedulable class to send a CSV file to an email. While I'm testing it I got this error to my e-mail instead of a CSV file. Can anyone help me with this? I'm attaching the code here.
global class ExporterCSV implements System.Schedulable {
    
	global void execute(SchedulableContext sc) {
	List<Contact> conList = [Select id , Lastname, FirstName , CreatedDate , lastModifiedDate from Contact];
	string header = 'Record Id ,Last Name, First Name , Created Date , Modified Date \n';
	string finalstr = header ;
        
	for(Contact a: conList)
	{
   string recordString = a.id + ',' + a.Lastname+',' + a.FirstName + ',' + a.CreatedDate + ',' + a.LastModifiedDate + '\n';
   finalstr = finalstr + recordString;
	}
        
	Messaging.EmailFileAttachment csvAttc = new Messaging.EmailFileAttachment();
	blob csvBlob = Blob.valueOf(finalstr);
	string csvname= 'Contacts.csv';
	csvAttc.setFileName(csvname);
	csvAttc.setBody(csvBlob);
	Messaging.SingleEmailMessage email =new Messaging.SingleEmailMessage();
	String[] toAddresses = new list<string> {'xxxxxxxxxxxxx@gmail.com'};
	String subject = 'Contacts Report CSV';
	email.setSubject(subject);
	email.setToAddresses( toAddresses );
	email.setPlainTextBody('The Contacts report is attached here.');
	email.setFileAttachments(new Messaging.EmailFileAttachment[]{csvAttc});
        
	//Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
	Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
	//system.debug(r);
  }
}
Error message I got :

Sandbox
 
Apex script unhandled exception by user/organization: xxxxxxxxxxxxx/yyyyyyyyyyyyyy Source organization: zzzzzzzzzzzzzz (null) Scheduled job 'Email Contact test' threw unhandled exception.
 
caused by: System.LimitException: Apex CPU time limit exceeded
 
Class.ExporterCSV.execute: line 14, column 1

 
How can we set field history tracking for an already existing custom field on a custom object? Is it possible?
Hi, 

So we have an object 'Asset' with one of fields as 'Software version number'. We want to track the software version number in Case Object and created a formula field so whenever a client generates a case the software version number will auto-populate the field. So here's the issue- When the software version changes (In asset object) as the client upgrades their software, this version number we have on Case object is also updating. Is there a way to store the old software version in the Case object even after the information in Asset object's 'software version number' field changes? Can someone help me with this? I'm sorry it's a little confusing. Can I do it using workflows and/or process builder or should I go for hardcoding?
I did a test run on this class and it gave me an error. Can someone guide me as to how I can run this test successfully?
@isTest
private class F8_Test_AssignmentGroupQueue {

    static testMethod void F8_Test_AssignmentGroupQueue() {
      Assignment_Group__c objAssignmentGroup = new Assignment_Group__c(Name='Test_AG');
      insert objAssignmentGroup;
        
        Group g1 = new Group(Name='group name', type='Queue');
      insert g1;
        QueuesObject q1 = new QueueSObject(QueueID = g1.id, SobjectType = 'Assignment_Group__c');
        insert q1;
        
        Group g2 = new Group(Name='group name2', type='Queue');
      insert g2;
        QueuesObject q2 = new QueueSObject(QueueID = g2.id, SobjectType = 'Assignment_Group__c');        
        insert q2;
        
        Group g3 = new Group(Name='group name3', type='Queue');
      insert g3;
        QueuesObject q3 = new QueueSObject(QueueID = g3.id, SobjectType = 'Assignment_Group__c');        
        insert q3;
        
        Assignment_Group_Queue__c objAssignmentGroupQueue = new Assignment_Group_Queue__c(Name = 'group name', Active__c = 'True', Assignment_Group_Name__c = objAssignmentGroup.Id, QueueId__c = g1.id, Valid_Queue__c = true);
        insert objAssignmentGroupQueue;
                                       
    Assignment_Group_Queue__c objAssignmentGroupQueue2 = new Assignment_Group_Queue__c(Name = 'group name2', Active__c = 'True', Assignment_Group_Name__c = objAssignmentGroup.Id, QueueId__c = g1.id, Valid_Queue__c = true);
        insert objAssignmentGroupQueue2;
        
        objAssignmentGroupQueue.Active__c = 'False';
        update  objAssignmentGroupQueue;
        
        objAssignmentGroupQueue.Name = 'group name3';
        update objAssignmentGroupQueue;
        
        try{
          objAssignmentGroupQueue.Name = 'group name2';
          update objAssignmentGroupQueue;  
        }
        catch(Exception ex){
          system.debug('## Exception is ::' + ex);  
        }
        
        Assignment_Group_Queue__c objAssignmentGroupQueue3 = new Assignment_Group_Queue__c();
        try{
          objAssignmentGroupQueue3 = new Assignment_Group_Queue__c(Name = 'group name2', Active__c = 'True', Assignment_Group_Name__c = objAssignmentGroup.Id, QueueId__c = g1.id, Valid_Queue__c = true);
          insert objAssignmentGroupQueue3;
        }
        catch(Exception ex){
          system.debug('## Exception is ::' + ex);
          System.assertEquals(objAssignmentGroupQueue3.Id, null);    
        }
        
        try{
          objAssignmentGroupQueue3 = new Assignment_Group_Queue__c(Name = 'group name23', Active__c = 'True', Assignment_Group_Name__c = objAssignmentGroup.Id, QueueId__c = g1.id, Valid_Queue__c = true);
          insert objAssignmentGroupQueue3;
        }
        catch(Exception ex){
          system.debug('## Exception is ::' + ex);
          System.assertEquals(objAssignmentGroupQueue3.Id, null);    
        }
        
        try{
          objAssignmentGroupQueue.Name = 'group name23';
          update objAssignmentGroupQueue;  
        }
        catch(Exception ex){
          system.debug('## Exception is ::' + ex);  
        }    
    }
}

Errors:

System.DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): QueueSobject, original object: Assignment_Group__c: []

Stack Trace:

Class.F8_Test_AssignmentGroupQueue.F8_Test_AssignmentGroupQueue: line 32, column 1
 
/**
 * An apex class that keeps updates of a portal user in sync with its corresponding contact.
   Guest users are never able to access this page.
 */
public with sharing class MyProfilePageController {

    private User user;
    private boolean isEdit = false;

    public User getUser() {
        return user;
    }

    public MyProfilePageController() {
        user = [SELECT id, email, username, usertype, communitynickname, timezonesidkey, languagelocalekey, firstname, lastname, phone, title,
                street, city, countryCode, postalcode, stateCode, localesidkey, mobilephone, extension, fax, contact.email
                FROM User
                WHERE id = :UserInfo.getUserId()];
        // guest users should never be able to access this page
        if (user.usertype == 'GUEST') {
            throw new NoAccessException();
        }
    }

    public Boolean getIsEdit() {
        return isEdit;
    }

    public void edit() {
        isEdit=true;
    }

    public void save() {
        if (user.contact != null) {
            setContactFields(user.contact, user);
        }

        try {
            update user;
            if (user.contact != null) {
                update user.contact;
            }
            isEdit=false;
        } catch(DmlException e) {
            ApexPages.addMessages(e);
        }
    }

    public PageReference changePassword() {
        return Page.ChangePassword;
    }

    public void cancel() {
        isEdit=false;
        user = [SELECT id, email, username, communitynickname, timezonesidkey, languagelocalekey, firstname, lastname, phone, title,
                street, city, countryCode, postalcode, stateCode, localesidkey, mobilephone, extension, fax, contact.email
                FROM User
                WHERE id = :UserInfo.getUserId()];
    }

    public static void setContactFields(Contact c, User u) {
        c.title = u.title;
        c.firstname = u.firstname;
        c.lastname = u.lastname;
        c.email = u.email;
        c.phone = u.phone;
        c.mobilephone = u.mobilephone;
        c.fax = u.fax;
        c.mailingstreet = u.street;
        c.mailingcity = u.city;
        c.mailingstate = u.state;
        c.mailingpostalcode = u.postalcode;
        c.mailingcountry = u.country;
    }
}