• Foram Rana R
  • NEWBIE
  • 285 Points
  • Member since 2019


  • Chatter
    Feed
  • 8
    Best Answers
  • 1
    Likes Received
  • 5
    Likes Given
  • 3
    Questions
  • 68
    Replies
V.f page:
<apex:page controller="Passingvaluestocntroller">
<apex:form >

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
  
  $(document).ready(function(){
  
 $("#click").click(function(){
 
 debugger;
   alert("hello");
     var name ="Deepika";
   alert(name);
   var branch="Salesforce";
   alert(branch);
   debugger;
   var test = {"Empname":name,"Empbranch":branch};
   alert(test);
   method1();
  });
  
  });
  </script>

 
  <apex:actionFunction name="method1" action="{!method1()}"/>

<input type="button" value="test" id="click"/>
</apex:form>
</apex:page>

Controller:

 
public class Passingvaluestocntroller {


  public void method1(string name, string branch){
   system.debug('salesforce testing');
   system.debug(name);
   system.debug(branch);
  }
  
  
 
  
}

​​​​​​need to pass the javascript varible to the Apex method in salesforce.. 

Thanks D
Deepika
"lookup relationship can to span multiple layer deep" - What it means?

Hi there!

I'm very new to visualforce / apex and there's one thing I can't get to work:

I have a simple vf page with two columns of checkboxes and I have to create a button which once being clicked ticks all the checkboxes from unchecked to checked or vise versa.

This is my current code:
<apex:page standardController="Rahmenvertrag_OptIn__c" recordSetVar="rv" standardStylesheets="true">
    
    
    <div class="container1">
        <apex:pageBlock >
        <h1>Rahmenvertrag Teilnehmer-Liste</h1>
        <apex:form id="form1">
            
            
            
            <apex:pageBlockTable value="{! rv }" var="rvt" id="table1">
                
                <apex:column value="{! rvt.KD_TN_EKP__c}" headerClass="tableheader" headerValue="EKP"/>
                <apex:column value="{! rvt.KD_TN_Name__c}" headerClass="tableheader" headerValue="Rahmenvertrag Teilnehmer"/>
                <apex:column value="{! rvt.KD_TN_Adresse__c}" headerClass="tableheader" headerValue="Adresse"/>
                <apex:column>
                    <apex:facet name="header"><span class="tableheader">Einwilligung<br/>Datenaustausch</span></apex:facet>
                    <apex:inputCheckbox value="{! rvt.Datenaustausch__c}"  />
                </apex:column>
                <apex:column >
                    <apex:facet name="header"><span class="tableheader">Einwilligung<br/>Werbliche Ansprache</span></apex:facet>
                    <apex:inputField value="{! rvt.Werbeansprache__c}"  />
                </apex:column>
            </apex:pageBlockTable>
            
            
            
            <br/>
            <table>
                <tr>
                <td ><apex:commandButton action="{!save}" value="Zwischenspeichern"/></td>
                <td><apex:commandButton action="{!save}" value="Änderungen bestätigen" /></td>
                </tr>                    
            </table>
        </apex:form>
    </apex:pageBlock>
        </div>
</apex:page>

Any help would be much appreciated! 
Thanks in advance

I have created a class that links a case with the case comment for a visualforce page but for the life of me I cannot remember how I write a test class for the apex class.

The class I require tests for is:

public class Caselinktocomment
{
    public CaseComment comment { get; set; }
    public String commentText {get; set;}
    public String PublicPrivateAction {get; set;}


    public Caselinktocomment(ApexPages.StandardController stdController) 
    {
        this.comment = new CaseComment(ParentId = stdController.getId());
    }

    public PageReference saveComment()
    {
        insert comment;
        return null;
    }
}

The test Class I have written is:
@istest

Private class Caselinktocommenttests {
    

    static testmethod void createtestdata() {
    Id RecordId = Schema.SObjectType.Case.getRecordTypeInfosByDeveloperName().get('Service_Desk').getRecordTypeId();
        Case tcase = new Case();
        tCase.Status = 'New';
        tCase.Description = 'This ticket has been created as a test';
        tCase.Subject = 'Test Case';
        tCase.RecordTypeId = RecordId;
        tCase.Reason = 'Access Requests';
        tCase.Origin = '';Phone
        
        INSERT tCase;
        
        CaseComment tComment = new CaseComment();
        tComment.ParentId = tCase.Id;
        tComment.CommentBody = 'Test Comment';
        tComment.IsPublished = FALSE;
        tComment.IsNotificationSelected= FALSE;
        Test.startTest();
        INSERT tComment;
        Test.stopTest();
        system.assertEquals(1, [SELECT count() From CaseComment], 'Test Comment');
        }   
}

The code coverage does not seem to increase. Can anyone advise where I have gone wrong. 
Im getting the Error : System.ListException: List index out of bounds: 0
Candidate__c(Master object) and Job_Application__c(child object). 
I want to fetch child records.

List<Candidate__c> candList=[Select id,name,City__c, (select Position__c,Status__c from Job_Applications__r) from Candidate__c Where Name='Shaun smith'];
System.debug('List is' +candList);
List<Job_Application__c> jobList=candList[0].Job_Applications__r;
System.debug('List of job are' +jobList);

Please help with this.

 
Hello All,
Hopeone someone can steer me in the right direction here.  I am saving a record from a user entered VF page. What I need to do is generate a PDF of the newly created record and attach it to the record.  I have a new VF page using (renderAs= PDF) and an Apex Class to grab the data to populate the VF but I need to make sure that the data has been saved first  before generating the PDF.  Also, how can I save it to the new record?  Is there a better way to do do this or am I on the right track?
Thanks,
P
Dear Team ,

Please clarify me about Sandbox , Roles and Profile , Batch APEX Class in easy words . These are the most frequently asked question in interviews .

Thanks & Regards
Sachin Bhalerao
User-added image
While clicking on button called Visualforce page.
Hello Everyone,

I want to extract the Zip file in the Apex class.
Zip may contain at least 20 doc or pdf files.
Let me know the solution.

Thanks,
Foram Rana
Got Issue In Below Code.
if((
                   Schema.SObjectType.Custom_Setting__c.isCreateable() &&
                   Schema.SObjectType.Custom_Setting__c.fields.Name.isCreateable() &&
                   Schema.SObjectType.Custom_Setting__c.fields.UserName__c.isCreateable() &&
                   Schema.SObjectType.Custom_Setting__c.fields.Password__c.isCreateable() ) ||
                                      
                   (Schema.sObjectType.Custom_Setting__c.isUpdateable() &&
                   Schema.SObjectType.Custom_Setting__c.fields.Name.isUpdateable()  ) {
                   
                   
                    Custom_Setting__c cs = new Custom_Setting__c(UserName__c = username, Password__c = password, Name = usr.Name);
                    upsert cs Name;
                   
                   }
Got Issue In Below Code.
if((
                   Schema.SObjectType.Custom_Setting__c.isCreateable() &&
                   Schema.SObjectType.Custom_Setting__c.fields.Name.isCreateable() &&
                   Schema.SObjectType.Custom_Setting__c.fields.UserName__c.isCreateable() &&
                   Schema.SObjectType.Custom_Setting__c.fields.Password__c.isCreateable() ) ||
                                      
                   (Schema.sObjectType.Custom_Setting__c.isUpdateable() &&
                   Schema.SObjectType.Custom_Setting__c.fields.Name.isUpdateable()  ) {
                   
                   
                    Custom_Setting__c cs = new Custom_Setting__c(UserName__c = username, Password__c = password, Name = usr.Name);
                    upsert cs Name;
                   
                   }
Please provide the lightning web component interview questions.
Thanks.
Hi,

I've created multiple checkbox fields. for each field, there's a corresponding completion date field that populates with TODAY() once the checkbox = true. 

User-added image

So far I've created a WorkFlow Rule and a WF Action to update the date field, but that means I'll have to create individual WF Rules per each date filed. Is there a way to aggregate it somehow to a single bulk action? 

Thanks.
I need help developers
I have json data that I need to parse

Structure is this

I only need bold array value


Please help
{
    "id": "5BS9022******",
    "intent": "CAPTURE",
    "purchase_units": [
        {
            "reference_id": "default",
            "amount": {
                "currency_code": "USD",
                "value": "10.00"
            },
            "payee": {
                "email_address": "Busyaccount@exmaple.com",
                "merchant_id": "ZJCWA********"
            },
            "soft_descriptor": "PAYPAL *JOHNDOESTES",
            "shipping": {
                "name": {
                    "full_name": "Buyer Name"
                },
                "address": {
                    "address_line_1": "Buyer address",
                    "admin_area_2": "",
                    "admin_area_1": "GA",
                    "postal_code": "123456",
                    "country_code": "US"
                }
            },
            "payments": {
                "captures": [
                    {
                        "id": "31349714C********",
                        "status": "COMPLETED",
                        "amount": {
                            "currency_code": "USD",
                            "value": "10.00"
                        },
                        "final_capture": true,
                        "seller_protection": {
                            "status": "ELIGIBLE",
                            "dispute_categories": [
                                "ITEM_NOT_RECEIVED",
                                "UNAUTHORIZED_TRANSACTION"
                            ]
                        },
                        "seller_receivable_breakdown": {
                            "gross_amount": {
                                "currency_code": "USD",
                                "value": "10.00"
                            },
                            "paypal_fee": {
                                "currency_code": "USD",
                                "value": "0.59"
                            },
                            "net_amount": {
                                "currency_code": "USD",
                                "value": "9.41"
                            }
                        },
                        "links": [
  
                        ],
                        "create_time": "2020-02-06T04:00:56Z",
                        "update_time": "2020-02-06T04:00:56Z"
                    }
                ]
            }
        }
    ],
    "payer": {
        "name": {
            "given_name": "buyer Name",
            "surname": "Name"
        },
        "email_address": "testbuyer@example.com",
        "payer_id": "A8******",
        "address": {
            "country_code": "US"
        }
    },
    "create_time": "2020-02-06T03:59:18Z",
    "update_time": "2020-02-06T04:00:56Z",
    "links": [

    ],
    "status": "COMPLETED"
}


 
Hello,
I have a VF page where I want to add a button to allow the user to open the print dialog to print the VF page as a PDF.  I am using slds and unsure how to use use the slds action button.
Any suggestions would be appreciated.
P
Hi,

I have an order object, it has 2 childs, NPS and Cases

On NPS, I have a lookup to cases. but both gets filled seperately

What I really want is, When  NPS rating is "4" on NPS. It should set the status close on all cases with "Type" NPS 4 

Point to remember is there can be multiple cases with this type

NPS rating --- > 4

Cases - type -(NPS4) ---- > Status = Closed

Can somebody help me in writting trigger and test class for the same
I want to delete my question 
https://developer.salesforce.com/forums/ForumsMain?id=9062I000000XquPQAS how to delete it
I have a custom Borrow, Item and Employee object. The following code has the purpose of taking in the autonumber Employee ID and string Barcode ID from the user and as soon as user presses enter key, it should save the record in the Borrow database. I tested the controller code seprately in the execute anonymous code wiindow, it is able to create the record in the database. And the visualforce page is running fine too, as its displaying the barcodeId in the output text field 
<apex:outputText id="out" value="{!barcodeId}"></apex:outputText> 
once user inputs the Barcode ID in the text field and presses the enter key. If the apex method was not called properly then this output text field would have not populated as it is getting populated from {!barcodeId} (apex controller field). But its giving me an query exception.
System.QueryException: List has no rows for assignment to SObject
Error is in expression '{!createBorrowRecord}' in page checkoutitems: Class.BorrowController.createBorrowRecord: line 9, column 1
Class.BorrowController.createBorrowRecord: line 9, column 1

which is the query for retrieving employee record.
I'm unsure where can the problem be ? 
Your help will be highly appreciated.

Controller
public class BorrowController {
    
    public String barcodeId {get; set;}
    public String employeeId {get; set;}
    
    public void createBorrowRecord() {
        try {
            Item__c item = [SELECT Id, Item_ID__c, Barcode_ID__c FROM Item__c WHERE Barcode_ID__c =:barcodeId LIMIT 1];
            Employee__c emp = [SELECT Id, Name, Employee_ID__c FROM Employee__c WHERE Employee_ID__c =:employeeId LIMIT 1];
            Borrow__c b = new Borrow__c();
            b.Name = item.Name + 'Borrow';
            b.Item_Name__c = item.Id;
            b.Employee_Name__c = emp.Id;
        
            insert b;
        }
        catch(DmlException e) {
            System.debug('The following error has occured'+ e.getMessage());
        }
        
    }
}

Visualforce Page
<apex:page controller="BorrowController" showHeader="false" applyHtmlTag="false" applyBodyTag="false" docType="Html-5.0">  
    <apex:form >
        <apex:actionFunction action="{!createBorrowRecord}" name="createBorrow" reRender="out">
            <apex:param name="barcode" value="" assignTo="{!barcodeId}"/>
            <apex:param name="employee" value="" assignTo="{!employeeId}"/>
        </apex:actionFunction>
    </apex:form>
    <apex:outputText id="out" value="{!barcodeId}"></apex:outputText>
    <apex:outputText id="out1" value="{!employeeId}"></apex:outputText>
    
    <html>
        <head>
            <title>Checkout Items</title>
        </head>
        <body>
            <br />
            <label for = "employeeId">Employee ID: </label>
            <input type = "text" id = "employeeId" />
            <br />
            <br />
            <label for = "barcodeText">Enter Barcode ID: </label>
            <input type = "text" id = "barcodeText" />
            <br />
            <span id = "addedItems"/>
            
            <script type = "text/javascript">
                var barcodeText = document.getElementById("barcodeText");
                var empId = document.getElementById("employeeId")
                var items = document.getElementById("addedItems");
                var completeText = "";
                barcodeText.addEventListener("keydown", function(e) {
                    if(e.which != 13) {
                        if(e.which >= 48 && e.which <= 57 || e.which >= 65 && e.which <= 90) {
                        console.log("Inside If-Block");
                        completeText = completeText + e.key;   
                        }
                        else {
                        console.log("Invalid Key");
                        outputText.innerHTML = "Invalid Key Pressed"; 
                        barcodeText.value = "";
                        }
                  }
                    else {
                        console.log("Inside Else-Block");
                        items.innerHTML = completeText;
                        console.log("Calling Apex Method:");
                        createBorrow(completeText, empId);
                        console.log("Done calling apex method:");
                        barcodeText.value = "";
                        completeText = "";
                    }
                });
            </script>
        </body>
    </html>

Regards,
Gill
I have written test class to sync quote. Test class failed. Below is the error

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [OpportunityId__c]: [OpportunityId__c]


@isTest
public class QuoteLineItemTestClass {

@TestSetup private static void setUpData(){

        Quotes__c a = New Quotes__c(Name='Test');
        insert a;

        Opportunities__c o = New Opportunities__c(Stage__c = 'prospecting',Close_Date__c = date.today(),Name = 'test');

        insert o;

        //....Create Products, pricebookentries, etc needed for the QLI and the OLI

        OpportunityLineItem__c oli = New OpportunityLineItem__c();

        insert oli;

        Quotes__c q = New Quotes__c();

        insert q;

        QuoteLineitem__c qli = New QuoteLineitem__c();

        insert qli;

    }

    static testMethod void  basicTest() {

         QuoteLineitem__c qli = [Select Id,Name,QuotesId__c From QuoteLineitem__c]; //We know we created one and only one

        qli.QuotesId__c = 'Test2'; //This is what your code looks to compare if it should run;

        update qli; //This should fire your code

        //Query for OLI and assert the field was updated appropriatly
        OpportunityLineItem__c oli = [Select Name,OpportunityId__c From OpportunityLineItem__c];

        system.assertEquals('check',oli.Product2Id__c, 'The field was not updated when it should have been');

    }

    static testMethod void  basicTest_NoProductMatch() {
        //Negative Use case
        //Create a QLI that does not have a corresponding OLI with same product
        QuoteLineitem__c qli = New  QuoteLineitem__c();
        insert qli;

        qli.QuotesId__c = 'Test2'; //This is what your code looks to compare if it should run;

        update qli; //This should fire your code

        //Query for OLI and assert the field was NOT updated since Product match was not found (quoery requirement in your code)
        OpportunityLineItem__c oli = [Select Name,OpportunityId__c From OpportunityLineItem__c];

        system.assertNotEquals('True',oli.Name,'The field was updated when the product did not match the updated QLI');

    }


}
for adress object if i am changing city automatically street is also getting change

 
I'm trying to call 2 methods from my controller within the VF apex code. Having no end of issues.

Here's my code:

   
<apex:page standardController="Account" extensions="AccountController" action="{!SendEnvelope}">
        <apex:form >
             
            <apex:actionFunction action="{!SendEnvelope}" name="SendEnvelope" oncomplete="EmbeddedSign();" />        
            <apex:actionFunction action="{!EmbeddedSign}" name="EmbeddedSign"/>    
            <apex:pageMessages />            
        </apex:form>
               <script>
                  EmbeddedSign();    //oncomplete="EmbeddedSign();"
            </script>   
    </apex:page>


    
I get that having *action="{!SendEnvelope}"* in the root page level will negate my actionFunction, but that's the only way i could get it working.

I've tried the following and failed:

ERROR: 'Attempt to de-reference a null object'
 
<script>           
          SendEnvelope();            
          EmbeddedSign();
    </script>



Or simply having a 'main' function within my controller that in call in apex. 

ERROR: You have uncommitted work pending. Please commit or rollback before calling out

   
public PageReference Main() {
      SendEnvelope();
      EmbeddedSign();
  }



So my assumption based on researching is that i need two separate transactions (callout ordering issues). That's why i have two functions that i need to call separately.

The above code actually gets it working, but it just keeps on reloading and reloading. i'm guessing it's because i'm missing 'rerender', but i couldn't get them working.

I briefly tried @future - that could be my solution, but i needed to return PageReference for the redirect to work in the second function (EmbeddedSign). Although am open to alternatives for sure.

I've hit a wall here, been trying to debug this for way too long. If anyone can please take a look at my code and provide suggestions that would be amazing. Thanks!
Hello,

I have a validation rule setup to check if a given picklist value is empty. I have tried following ways but the rule does not trigger:

#Type 1:
NOT(ISBLANK(TEXT(text_field))) 
&& 
ISBLANK(TEXT(picklist ))
&& 
(RecordType.Name = "name1" 
|| 
RecordType.Name = "name2" 
|| 
RecordType.Name = "name3" 
)

#Type 2:

AND(ISPICKVAL(Picklist , ""), NOT(ISBLANK(TEXT(Text_Field))),OR(RecordType.Name = "name1", RecordType.Name = "name2", RecordType.Name = "name3" ))

Please let me know why this doesn't work. Thanks a lot
Hi,
I am getting error...below code:

     map<string,set<id>> contactIdAndProgramCode=new map<string,set<id>>();
        for(string c:programEnrollmentAndProgramMap.values()){
            for(id i:termModuleofferingModuleConnectionMap.keySet()){
            contactIdAndProgramCode.put(c,termModuleofferingModuleConnectionMap.get(i));// Program code and ContactIds
             }
        }
        
    Error---Invalid loop variable type expected Set<String> was String
I had a validation rule for which i was using to restrict as

If LOI Approval Status picklist value = Approved then only update the IsRenewed Chechbox = True.
*******************
If LOI Approved Status picklist value = (Rejected or Submitted) we don't want to make the IsRenewed checkbox to true.

*******************
Validation Rule:

 ISPICKVAL(LOI_Approval_Status__c, Approved) 

Please give me a solution for this 

Thanks and Regards,
Azar Khasim.

Hello,

I need help writing class to update child record fields when parent field is updated. For example if the start date is updated on the parent record I want to update the start date on the all of the child records. if the enddate is updated on the parent record I want to update the enddate on the all of the child records.  I have several date fields.
Thanks,
P

Hi.. here iam using the apex:include page functionaliy, one page is included in the another page with common controller..

Vfpage1:
<apex:page controller="testingcontroller">
  <apex:form >
  Entername<apex:inputText value="{!testwrap.name}"/>
  </apex:form>
</apex:page>
Vfpage2: Vfpage1 included in the Vfpage2.
<apex:page controller="testingcontroller" id="pg">
  <apex:include pageName="Vfpage1" id="pge"/>
    <apex:form >
    <apex:commandButton value="test" action="{!test}" reRender="t" />
    <apex:outputLabel id="t">{!message}</apex:outputLabel>
    </apex:form>
</apex:page>

Commoncontroller:
 
public class testingcontroller {

 public string message{get;set;}
 public testwrapper testwrap{get;set;}
 public  testingcontroller(){
 testwrap = new testwrapper();
 }
   public void test(){
    message ='Hi hello'+testwrap.name;
   system.debug('testwrap.name=======>'+testwrap.name);
   }
   
    public class testwrapper{
    
      public string name{get;set;}
      public testwrapper(){
        this.name ='';
        }
    }
}

On clicking on the button the data should have to pass to the Common controller. any solution how it can be achived.. thanks in advance..!

 
Hi Everyone,

When i am writting Pd1 maintance exam i got error 


When executed, the BatchLeadConvertTest test class has test failures. All tests should pass.

Thank you
For me if I go to settings it is showing like below how to create a namespace there is no edit 

Please check below image help me how I can create it 
User-added image
There is no Edit option that is what is showing for me in my org account
Hi folks,
How to send email alert / notificaiton from Case object to '''SLA Custom object ---> Peer reviwer ''' through APex class.
Can you some one pls provide code for this requirement 
Thanks
Sekhar
 
I have case object firstname and lastname and city multiselect picklist i need to auto populate combination of above 3 fields.