• Victor19
  • NEWBIE
  • 35 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 46
    Questions
  • 70
    Replies
Hi,
I have a controller on my visualforce page and I am not able to build test data to cover for the coverage for the below variables. The data comes in from my visualforce page. Can someone please advise?

public class OppExtension{
    public OppExtension(ApexPages.StandardController controller) {
        std = controller;
        OpptyRec = (Opportunity)std.getRecord();
}

public string s1{get;set;}
    public string s2{get;set;}
    public string s3{get;set;}

public PageReference assignvalue(){
        s1 = s1.replace('North America (%) : ', '');
        s2 = s2.replace('APAC (%) : ', '');
        s3 = s3.replace('LATAM (%)  : ', '');
return null;
}
}
Thanks,
Victor
Hello,

I am working on building a visualforce page to display the hierarchy between accounts through a lookup field.
I would really appreciate if someone could please share some code 

Thanks!
Hi All,

I am working on a requirement to open a visualforce page for a specific record type. For some reason, the page keeps going to the standard page layout. Could you please point out where I am going wrong. Please find my code below:

Visualforce Page:
<apex:page id="TestPage" standardcontroller="Test__c" tabStyle="Test__c" extensions = "TestController" action = "redirect">
</apex:page>

Controller:
public class TestController {
    public ApexPages.StandardController controller{get;set;}
   
    public TestController(ApexPages.StandardController controller) {
        this.controller = controller;
    }
  
    public PageReference redirect() {
        PageReference page = new PageReference('/apex/TestPage');
        String selectedRecordType = ApexPages.currentPage().getParameters().get('RecordType');
        if (selectedRecordType == '01XXXXXXXXX'){
           page.setRedirect(true); 
            return page;            
        }
        else{
            return new PageReference('/a01/e?nooverride=1');
        }        
    }
}

I would really appreciate if someone could suggest a fix to resolve this issue.

Thanks,
Victor
 
Hi, 
I have a javascript which when clicked checks fields 1 and fields 2 and if both the fields are blank or if one of them is blank, an error message
is shown on the page. The issue I am having now is the error messages are getting displayed but they are appearing in 2 different pop ups if both fields are blanks. I would like to display both those error messages in the same popup window.

if ('{!Quote.Field1__c}' == '') {
alert('Field1 cannot be blank');
}
else if ('{!Quote.Field2__c}' == '') {
alert('Field2 cannot be blank');
}
else{
navigateToUrl('/p/process/Submit?retURL=%2F{!Quote.Id}&id={!Quote.Id}');
}



I would really appreciate if someone could please help me out
Hi,

In my controller, I have written some logic for a record to be automatically submitted for approval when certain criteria is met. The issue that I am having now is once the record gets submitted and when it goes to my manager for approval: He/She should be able to update a field value in the record. My approval process in not currently letting my manager update the record.

Currently I get this error: System.DmlException: Process failed. First exception on row 0; first error: ALREADY_IN_PROCESS, Cannot submit object already in process.: [].

I would really appreciate if someone could please help me out!

Thanks!
Hi,

I have a visualforce page with a controller extension. In my save method whenever the user clicks the save button and when the criteria is met the record has to be submitted for approval.

I would really appreciate if someone could please share some sample code for this requirement.

Thanks!
Hi,

I am trying to build a SOQL query and my condition is when Intake date in object 1 is greater than Start date in object 2 and lesser than End date n Object, then I will be getting the id of the record.  Please see my code below:

Object1 obj1 = trigger.new[0];
List<Object2> DateList = [Select id, Start_Date__c, End_Date__c FROM Object2 WHERE obj1.Intake_Date__c > Start_Date__c AND obj1.Intake_Date__c < End_Date__c];

Can someone please suggest a fix to my code?

Thanks!
Hi,

I need to grab only the id from the current page. I am currently using: 
ApexPages.currentPage().geturl();

Is there a way to capture selective parameters from the currentPage url.

I would really appreciate if someone could help me out

Thanks! 

Hi,

 

I am trying to override the view button in custom object with a custom view button. My custom button should dynamically display visualforce pages based on  a field value.

 

For eg: I have two Visualforce Pages: VF1 and VF2 and a picklist - testpick__c = 1;2

 

If the record has testpick__c = 1 --> Display VF1 when custom view button is clicked

If the record has testpick__c = 2 --> Display VF2 when custom view button is clicked

 

It would greatly help me out if someone could share some code or suggest an approach that I could use to implement this functionality.

 

Thanks!

Hi,

 

I am trying to copy the information (Approver, Comments etc) from the Standard Approval Process Related list into custom fields. My debug statements show values but fields are not getting populated with the values. I would really appreciate if someone could suggest a fix to my code.

 

trigger Test_Approval on Test_Obj_1__c (after insert, after update) {
    Set <id> ids = new Set <id>();
        for(Test_Obj_1__c tes1 : Trigger.new){
         ids.add(tes1.id);
System.debug('zz ids: ' + ids);
    }
    
 
    List<Test_Obj_1__c> testlist = [SELECT e.Id, e.Test_Approver__c, e.Comments__c, (Select Id, IsPending, ProcessInstanceId, TargetObjectId, StepStatus, OriginalActorId, ActorId, RemindersSent, Comments, IsDeleted, CreatedDate, CreatedById, SystemModstamp From ProcessSteps)
                                            FROM Test_Obj_1__c e where id=:ids];
    
    if(testlist.size()>0)
    {
        Test_Obj_1__c fund = testlist[0];
 

        for (ProcessInstanceHistory ps : tobj.ProcessSteps)
        {
            tobj.Test_Approver__c = ps.ActorId;
            tobj.Comments__c = ps.Comments;
            System.debug('zz Approver: ' + tobj.Test_Approver__c);
            System.debug('zz Comments:' + tobj.Comments__c);

        }
    }
}

 

Thanks!

Hi,

I am trying to setup a functionality when the user creates a child record from the child related list on the parent page,
some fields in the child record get prepopulated with the details from the parent record. I am having no issues doing this.
However the user should be able to change the parent (lookup field) from the child record and when the user does that I have a button that updates the child record fields with the new parent information.

I keep getting an Attempt to dereference a null object error.

Can someone please point out any corrections that I can do to my code to make it work.


public class Test_Controller {
    public Test_Controller(ApexPages.StandardController controller) {
    Child__c child = (Child__c)controller.getRecord();
        if (child.parent__c != null) {
            Parent__c parent = [select Name__c, TField1__c, FROM Parent__c  
                                                  WHERE id =: child.parent__c limit 1];

            child.parent__c = parent.Id;
            child.Name__c = parent.Name;
            child.TField1__c = parent.TField1__c;

        }
    }
 
    public PageReference UpdateParentInfo(){
        child = (Child__c)std.getRecord();
            List<Parent__c> parent = [SELECT Name__c, TField1__c, FROM Parent__c  
                                                      WHERE id =: child.parent__c];
        
            if(!parent.isEmpty()){
                child.Name__c = parent.get(0).Name;
                child.TField1__c = parent.get(0).TField1__c;
           
            }

    }
}


Hi,

 

I have a requirement where I am trying to update the status of the field (picklist) and also populate a text field with the queue or owner the request is currently in my approval steps. I was thinking of having a trigger but it looks like a trigger cannot be created on the Approvals object. Is there a way to implement my functionality? Any ideas or sample code will greatly help  me out.


Thanks,

 

 

 

Hi,

 

I am trying to setup a trigger that fires whenever the owner is changed in a case and the trigger updates the status field.

For some reason, the trigger does not seem to grab the owner field value. Below is my code:

 

trigger OwnerCaseStatus on Case (after update) {

        for(Case cas: Trigger.new){
                Case oldcase = Trigger.oldMap.get(cas.Id);
        If(cas.Owner != oldcase.Owner){
                    cas.Status = 'Open';
   }
}
}

Can someone please point out if I am missing something.

 

Thanks!

Vic

Hi,

I am trying to copy a look up field value (User__c) from Test_Object_2__c to Test_Object_1__c . Basically based on the lookup field (Test_Object_2__c) in Test_Object_1__c object  I am pulling out the User__c and Group_Name__c field values from Test_Object_2__c to use it in Test_Object_1__c.
I have no issues copying the Group_Name__c as it is a text field,


Thanks

Hi,

 

I have a html tag for a checkbox field that I display on visualforce page. The field will be visible only to certain people, so my requirement is I want this html tag to be visible on the visualforce page only to the people who have access to this checkbox field. How do I achieve this? Does anybody have any suggestions or some sample code that I could use for my page?

 

Thanks!

Vic

 

 

Hi,

I have set up an after update trigger for a dynamic approval process on my custom object (TestObj).
However I am getting a save error:  Initial term of field expression must be a concrete sObject: List<Group> (Highlighted in Red)

trigger Test_ApprovalProcess on TestObj__c (after update) {
    List<String> QNames = new List<String>();
    
    //Retreiving the Queue_Name__c from each TestObj__c record and populating the list
   
    for(TestObj__c test : Trigger.new){
        String QName = test.Queue_Name__c;
         QNames.add(QName);
System.debug('zz QNames: ' + QNames);
    }
    
    Map<Id, Id> groupIDMap = new Map<Id, Id>();
    List<String> idList = new List<String>();
    List<group> gList = [SELECT (select userOrGroupId from groupMembers)
                FROM group
                WHERE name = :QNames];   //use the referenced name field from the EFR_Funding record to make it dynamic
    for (GroupMember gm : gList.groupMembers){
        idList.add(gm.userOrGroupId);
 System.debug('zz ids: ' + idList);   
    }

    //Submit records for approval based on the condition below
    for(TestObj__c test1: Trigger.new){
        if(test1.Approval_Status__c == 'Approved by Manager'){
            Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
            req1.setComments('Submitting request for Approval.');
            req1.setObjectId(ef.id);
            req1.setNextApproverIds(idList);
            Approval.ProcessResult result = Approval.process(req1);
            System.assert(result.isSuccess());
            System.assertEquals('Pending', result.getInstanceStatus(), 'Instance Status'+result.getInstanceStatus());
        }
    }
}

 

Can someone please point out or correct my code.

 

Thanks!

Hi Everyone,

 

I have created 2 Record Types (Record Type A, Record Type B) and I have also setup 2 Permission Sets (Test1 & Test 2).

 

Permission set 1 has Record Type A and gives the user access to all the fields in a Custom Object (Object1)

Permission set 2 has Record Type B and gives the user access to only certain fields in the Custom Object (Object 1).

 

Now when I assign both these Permission Sets (1&2) to the same user, the user is able to see all the fields in both the record types. Because of permission set 1 the user is able to see all the fields in both the record types. I want the user to see the fields in the record type based on the field permissions setup in the permission set.

 

Am I missing out something or Is it a Salesforce issue when it comes to Permission sets and Record Types?

 

Any help or suggestions would greatly help me out!

 

Thanks!

Hi,

 

I am trying to setup a dynamic Approval Process. I would like to reference the different queues that I have created in my org for my custom approval process. Can someone please help me out on how to get this started.

 

Any suggestions or sample code would greatly help me out.

 

Thanks!

 

 

Hi,

 

I am working on a requirement in which I am trying to insert a child record while creating the parent record.

 

My parent object is the Case Object and my child object is a Custom Object called People__c. Through the use of a Custom button, I would like to create a People__c record. Basically, when the user clicks the button on the case record, the user will be taken to the People__c object, all the necessary details can be filled in and once the people record is saved, the user will be redirected back to the case record that has not still been saved to the database.

 

I have never worked on a requirement like this before. Any suggestions or sample code would greatly help me out.

 

Thanks!

Hi Everyone,

We have a requirement where I am trying to setup an approval process and use it to dynamically assign to different queues based on field (queue) values in the record. Basically my record has the group name that it has to be assigned to. Is there a way to set up just one approval process on the field (queue) that is populated in the record.

It would greatly help me out if someone could give me their feedback or suggestions.

 

Thanks!

 

Hi,
I have a controller on my visualforce page and I am not able to build test data to cover for the coverage for the below variables. The data comes in from my visualforce page. Can someone please advise?

public class OppExtension{
    public OppExtension(ApexPages.StandardController controller) {
        std = controller;
        OpptyRec = (Opportunity)std.getRecord();
}

public string s1{get;set;}
    public string s2{get;set;}
    public string s3{get;set;}

public PageReference assignvalue(){
        s1 = s1.replace('North America (%) : ', '');
        s2 = s2.replace('APAC (%) : ', '');
        s3 = s3.replace('LATAM (%)  : ', '');
return null;
}
}
Thanks,
Victor
Hi All,

I am working on a requirement to open a visualforce page for a specific record type. For some reason, the page keeps going to the standard page layout. Could you please point out where I am going wrong. Please find my code below:

Visualforce Page:
<apex:page id="TestPage" standardcontroller="Test__c" tabStyle="Test__c" extensions = "TestController" action = "redirect">
</apex:page>

Controller:
public class TestController {
    public ApexPages.StandardController controller{get;set;}
   
    public TestController(ApexPages.StandardController controller) {
        this.controller = controller;
    }
  
    public PageReference redirect() {
        PageReference page = new PageReference('/apex/TestPage');
        String selectedRecordType = ApexPages.currentPage().getParameters().get('RecordType');
        if (selectedRecordType == '01XXXXXXXXX'){
           page.setRedirect(true); 
            return page;            
        }
        else{
            return new PageReference('/a01/e?nooverride=1');
        }        
    }
}

I would really appreciate if someone could suggest a fix to resolve this issue.

Thanks,
Victor
 
Hi,

I am trying to build a SOQL query and my condition is when Intake date in object 1 is greater than Start date in object 2 and lesser than End date n Object, then I will be getting the id of the record.  Please see my code below:

Object1 obj1 = trigger.new[0];
List<Object2> DateList = [Select id, Start_Date__c, End_Date__c FROM Object2 WHERE obj1.Intake_Date__c > Start_Date__c AND obj1.Intake_Date__c < End_Date__c];

Can someone please suggest a fix to my code?

Thanks!
Hi,

I need to grab only the id from the current page. I am currently using: 
ApexPages.currentPage().geturl();

Is there a way to capture selective parameters from the currentPage url.

I would really appreciate if someone could help me out

Thanks! 

Hi,

 

I am trying to copy the information (Approver, Comments etc) from the Standard Approval Process Related list into custom fields. My debug statements show values but fields are not getting populated with the values. I would really appreciate if someone could suggest a fix to my code.

 

trigger Test_Approval on Test_Obj_1__c (after insert, after update) {
    Set <id> ids = new Set <id>();
        for(Test_Obj_1__c tes1 : Trigger.new){
         ids.add(tes1.id);
System.debug('zz ids: ' + ids);
    }
    
 
    List<Test_Obj_1__c> testlist = [SELECT e.Id, e.Test_Approver__c, e.Comments__c, (Select Id, IsPending, ProcessInstanceId, TargetObjectId, StepStatus, OriginalActorId, ActorId, RemindersSent, Comments, IsDeleted, CreatedDate, CreatedById, SystemModstamp From ProcessSteps)
                                            FROM Test_Obj_1__c e where id=:ids];
    
    if(testlist.size()>0)
    {
        Test_Obj_1__c fund = testlist[0];
 

        for (ProcessInstanceHistory ps : tobj.ProcessSteps)
        {
            tobj.Test_Approver__c = ps.ActorId;
            tobj.Comments__c = ps.Comments;
            System.debug('zz Approver: ' + tobj.Test_Approver__c);
            System.debug('zz Comments:' + tobj.Comments__c);

        }
    }
}

 

Thanks!

Hi,

I am trying to setup a functionality when the user creates a child record from the child related list on the parent page,
some fields in the child record get prepopulated with the details from the parent record. I am having no issues doing this.
However the user should be able to change the parent (lookup field) from the child record and when the user does that I have a button that updates the child record fields with the new parent information.

I keep getting an Attempt to dereference a null object error.

Can someone please point out any corrections that I can do to my code to make it work.


public class Test_Controller {
    public Test_Controller(ApexPages.StandardController controller) {
    Child__c child = (Child__c)controller.getRecord();
        if (child.parent__c != null) {
            Parent__c parent = [select Name__c, TField1__c, FROM Parent__c  
                                                  WHERE id =: child.parent__c limit 1];

            child.parent__c = parent.Id;
            child.Name__c = parent.Name;
            child.TField1__c = parent.TField1__c;

        }
    }
 
    public PageReference UpdateParentInfo(){
        child = (Child__c)std.getRecord();
            List<Parent__c> parent = [SELECT Name__c, TField1__c, FROM Parent__c  
                                                      WHERE id =: child.parent__c];
        
            if(!parent.isEmpty()){
                child.Name__c = parent.get(0).Name;
                child.TField1__c = parent.get(0).TField1__c;
           
            }

    }
}


Hi,

 

I am trying to setup a trigger that fires whenever the owner is changed in a case and the trigger updates the status field.

For some reason, the trigger does not seem to grab the owner field value. Below is my code:

 

trigger OwnerCaseStatus on Case (after update) {

        for(Case cas: Trigger.new){
                Case oldcase = Trigger.oldMap.get(cas.Id);
        If(cas.Owner != oldcase.Owner){
                    cas.Status = 'Open';
   }
}
}

Can someone please point out if I am missing something.

 

Thanks!

Vic

Hi,

 

I am trying to add the Notes and Attachments Section on my Visualforce Page and I keep getting the error as below:


'NotesAndAttachments' is not a valid child relationship name for entity Test Object

 

I used   <apex:relatedList subject="{!Test_Object__c}" list="NotesAndAttachments"/>

 

Can someone please suggest or point out my mistake.

 

Thanks!

When developing a Visualforce page for overiding view page for any object, one problem that creeps up is to display the History details of a record. The standard related list Component doesn't works for History.

 

With the help of some code from Community ( I now can't find the link to it :( ), I wrote my own code  then to display the history of an object. It mimics the standard list as far as possible.  

 

Heres the code. It is for the Case object but it can be used for any other object.

 1.Component Code

 

<apex:component controller="CaseHistoriesComponentController">
<!-- Attribute Definition -->
<apex:attribute name="CaseId" description="Salesforce Id of the Case whose Case History needs to be rendered" type="Id" required="true" assignTo="{!caseId}" />

<!-- Case History Related List -->
<apex:pageBlock title="Case History">
<apex:pageBlockTable value="{!histories}" var="History" >
<apex:column headerValue="Date" value="{!History.thedate}"/>
<apex:column headerValue="User"> <apex:outputLink value="/{!History.userId}"> {!History.who} </apex:outputLink></apex:column>
<apex:column headerValue="Action"><apex:outputText escape="false" value="{!History.action}"/></apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:component>

 

 

 

 

2. Apex Code

 

public class CaseHistoriesComponentController {

public Id caseId {get; set;}
public cHistories[] histories;

// Variables
public Static final Map<String, Schema.SObjectField> CaseFieldmap = Schema.SObjectType.Case.fields.getMap();
public Static final List<Schema.PicklistEntry> fieldPicklistValues = CaseHistory.Field.getDescribe().getPicklistValues();

public List<cHistories> getHistories()
{
list<cHistories> histories = new list<cHistories>();
String prevDate = '';
for(CaseHistory cHistory : [Select CreatedDate, CreatedBy.Name, CreatedBy.Id, Field, NewValue, OldValue from CaseHistory where CaseId = :caseId order by CreatedDate desc])
{
if((cHistory.newValue == null && cHistory.oldValue == null)
|| (cHistory.newValue != null && !(string.valueOf(cHistory.newValue).startsWith('005') || string.valueOf(cHistory.newValue).startsWith('00G')))
|| (cHistory.oldValue != null && !(string.valueOf(cHistory.oldValue).startsWith('005') || string.valueOf(cHistory.oldValue).startsWith('00G'))))
{
cHistories tempHistory = new cHistories();
// Set the Date and who performed the action
if(String.valueOf(cHistory.CreatedDate) != prevDate)
{
tempHistory.theDate = String.valueOf(cHistory.CreatedDate);
tempHistory.who = cHistory.CreatedBy.Name;
tempHistory.userId = cHistory.CreatedBy.Id;
}
else
{
tempHistory.theDate = '';
tempHistory.who = '';
tempHistory.userId = cHistory.CreatedBy.Id;
}
prevDate = String.valueOf(cHistory.CreatedDate);

// Get the field label
String fieldLabel = CaseHistoriesComponentController.returnFieldLabel(String.valueOf(cHistory.Field));

// Set the Action value
if (String.valueOf(cHistory.Field) == 'created') { // on Creation
tempHistory.action = 'Created.';
}
else if(cHistory.OldValue != null && cHistory.NewValue == null){ // when deleting a value from a field
// Format the Date and if there's an error, catch it and re
try {
tempHistory.action = 'Deleted ' + Date.valueOf(cHistory.OldValue).format() + ' in <b>' + fieldLabel + '</b>.';
} catch (Exception e){
tempHistory.action = 'Deleted ' + String.valueOf(cHistory.OldValue) + ' in <b>' + fieldLabel + '</b>.';
}
}
else{ // all other scenarios
String fromText = '';
if (cHistory.OldValue != null) {
try {
fromText = ' from ' + Date.valueOf(cHistory.OldValue).format();
} catch (Exception e) {
fromText = ' from ' + String.valueOf(cHistory.OldValue);
}
}

String toText = '';
if (cHistory.OldValue != null) {
try {
toText = Date.valueOf(cHistory.NewValue).format();
} catch (Exception e) {
toText = String.valueOf(cHistory.NewValue);
}
}
if(toText != '')
tempHistory.action = 'Changed <b>' + fieldLabel + '</b>' + fromText + ' to <b>' + toText + '</b>.';
else
tempHistory.action = 'Changed <b>' + fieldLabel;
}

// Add to the list
histories.add(tempHistory);
}
}

return histories;
}

// Function to return Field Label of a Case field given a Field API name
public Static String returnFieldLabel(String fieldName)
{
if(CaseHistoriesComponentController.CaseFieldmap.containsKey(fieldName))
return CaseHistoriesComponentController.CaseFieldmap.get(fieldName).getDescribe().getLabel();
else
{
for(Schema.PicklistEntry pickList : fieldPicklistValues)
{
if(pickList.getValue() == fieldName)
{
if(pickList.getLabel() != null)
return pickList.getLabel();
else
return pickList.getValue();
}
}
}
return '';
}
// Inner Class to store the detail of the case histories
public class cHistories {

public String theDate {get; set;}
public String who {get; set;}
public Id userId {get; set;}
public String action {get; set;}
}
}

  Let me know your views on the code or if you have any questions

 

Hi, I'm trying to perform an approval action through APEX code, in an extended controller.  

First I do a Submit for Approval, overwriting the standard one with a visualforce custom button. Here is the code in my extended controller:

 

public PageReference submitApproval() { // Create an approval request for the account Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest(); req1.setComments('Submitting request for approval.'); req1.setObjectId(purchaseRequisitionObj.id); // Submit the approval request for the account Approval.ProcessResult result = Approval.process(req1); return Page.PR_Detail_VF; }

After that event, the object left in "Pending" approval state. Then in my detail visualforce page, for specific cases, I have a "Direct Approval" button. That button should perform the instance approval changing its state to "Approved". Here is where I'm stuck, because I can not find the way to get the WorkitemId of the request. I mean the workitemId of the instance I asynchronously approved before. This is the code:

 

public PageReference directApproval() { // Instantiate the new ProcessWorkitemRequest object and populate it Approval.ProcessWorkitemRequest req2 = new Approval.ProcessWorkitemRequest(); req2.setComments('Direct approval by requester'); req2.setAction('Approve'); req2.setNextApproverIds(new Id[] {UserInfo.getUserId()}); req2.setWorkitemId("FROM WHERE I CAN GET THIS ID??"); // Submit the request for approval Approval.ProcessResult result2 = Approval.process(req2); return Page.PR_Detail_VF; }

 

Any cue will be highly appreciated. Many thanks in advance Fernando.-

 

  • July 14, 2009
  • Like
  • 0