• Manish Anand 10
  • NEWBIE
  • 135 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 26
    Questions
  • 47
    Replies
I have a requirement - Need to create at max 3 opportunity records for any account in a day.
Can someone guide me on on this requirement?
Requirement is- To create a maximum of 3 opportunities, for an account object in a single day.
E.g- User creating 4th opportunity for the same account , in the same day when 1st, 2nd and 3rd opportunities are created, should throw an error.
E.g-If 2 opportunities are created for an account and user trying to import 3 opportunities for the same account, then 1 opportunity should be created and for rest 2, it should throw error.
Hi,

Is there anyway, I can overirde standard logout button in salesforce. My requirement is:-
When a user clicks on Logout button, a pop up should appear confirming, if he wants to de-active his salesforce id.Clicking on 'yes' should de-activate his salesforce id.
Any suggestion is highly appreciated.

Thanks.
1) Which requirement needs to be implemented by using standard workflow instead of Process Builder?
   Choose 2 answers
A.   Create activities at multiple intervals.
B.   Send an outbound message without Apex code.
C.   Copy an account address to its contacts.
D.   Submit a contract for approval.

2)  How can a developer refer to, or instantiate, a PageReference in Apex?
      Choose 2 answers
   A. By using a PageReference with a partial or full URL.
   B. By using the Page object and a Visualforce page name.
   C. By using the ApexPages.Page() method with  a  Visualforce page  name.
   D. By using the PageReference.Page() method with  a  partial  or  full URL.


3)  A developer has a single custom controller class that works with a Visualforce Wizard to support creating and editing multiple sObjects. 
  The wizard accepts data from user inputs across multiple Visualforce pages and from a parameter on the initial URL
   Which statement is unnecessary inside the unit test for the custom controller?

A. public ExtendedController(ApexPages.StandardController cntrl) { )
B. ApexPages.currentPage().getParameters() put(input', 'TestValue).
C.  Test.setCurrentPage(pageRef),
D.  String nextPage = controller.save().getUrl();


4)  Which statement about the Lookup Relationship between a Custom Object and a Standard Object is correct?

A.  The Lookup Relationship on the Custom Object can prevent the deletion of the Standard Object.
C.   The Custom Object will be deleted when the referenced Standard Object is delete
 
1)The Review_c object have a lookup relationship to the job_Application_c object.The job_Application_c object has a master detail relationship up to the
 position_c object.The relationship is based on the auto populated defaults? 
 What is the recommended way to display field data from the related Review _C records a Visualforce page for a single Position_c record?
 
 A.Utilize the Standard Controller for Position_c and cross-object Formula Fields on the Review_c object to display Review_c data.
 B.Utilize the Standard Controller for Position_c and a Controller Extension to query for Review _ C data.
 C.Utilize the Standard Controller for Position_c and expression syntax in the Page to display related Review_c through me Job_Applicacion_c inject.
 D.Utilize the Standard Controller for Position_c and cross-object Formula Fields on the Job_Application c object to display Review_c data.


2)A company has a custom object named Warehouse. Each Warehouse record has a distinct record owner, and is related to a parent Account in Salesforce. 
  Which kind of relationship would a developer use to relate the Account to Warehouse?
 
  A. Lookup
  B. One to Many
  C. Master-Detail
  d. Parent-Child


3)A developer wants to create a custom object to track Customer Invoices. 
  How should Invoices and Accounts be related to ensure that all Invoices are visible to everyone with access to an Account?

A. The Invoice should have a Master-Detail relationship to the Account
B. The Account should have a Master-Detail relationship to the Invoice.

4)What should a developer working in a sandbox use to exercise a new test class before the developer deploys that test class to production? Choose 2 answers
  
 A.The REST API and ApexTestRun method
 B.The Run Tests page in Salesforce Setup
 C.The Apex Test Execution page in Salesforce Setup
 D.The Test menu in the Developer Console
 
1)Which declarative method helps ensure quality data?
  Choose 3 answers

  A.Validation rules
  B.Workflow alerts
  C.Lookup filters
  D.Page Layout


2)A developer creates an Apex helper class to handle complex trigger logic.
  How can the helper class warn users when the trigger exceeds DML governor limits?

  A. By using Messaging.SendEmail() to continue the transaction and send an alert to the user after the number of DML statements is exceeded.
  B. By using ApexMessage.Message() to display an error message after the number of DML statements is exceeded.
  C. By using Limits.getDMLRows() and then displaying an error message before the number of DML statements is exceeded.
  D. By using PageReference.setRedirect() to redirect the user to a custom Visualforce page before the number of DML statements is exceeded.

3)In the Lightning Component framework, which resource can be used to fire events?
   2 Answers correct
  
   A.Third-party Javascript code
   B.Javascript controller actions
   C.Third-party web service code.
   D.Visualforce controller actions.
Hi,

I am confused while it comes to order of execution of 'before triggers' and 'validation rules' while saving a record in salesforce. Salesforce document says-1)System Validation 2)Before Triggers 3)Custom Validation. I had this question in my developer exam and 2 options were confusing.
A)Before Triggers  B) Validation Rules,
Options were-1)AB 2)BA 
Which one of above is correct?

 
Hi,
What will be the answer of below query-
when would a developer use a custom controller instead of a controller extension?

1)When a VF Page needs to replace the functionality of a standard controller.
2)When a VF Page doesn't reference a single primary object.
3)When a VF Page shouldn't enforce permissions or field level security.
4)When a VF Page needs to add new actions to a standard controller.

It looks 2 and 3. 
Please correct me.
 
Hi,

I am trying to implememnt a standardsetcontroller. I copy pasted the apex code from saslesforce document example-
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_pages_standardsetcontroller.htm
Below is the code-
public class opportunityList2Con {
    // ApexPages.StandardSetController must be instantiated
    // for standard list controllers
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                    [SELECT Name, CloseDate FROM Opportunity]));
            }
            return setCon;
        }
        set;
    }

    // Initialize setCon and return a list of records
    public List<Opportunity> getOpportunities() {
        return (List<Opportunity>) setCon.getRecords();
    }
}

when I save this I get an error-
Error: Compile Error: Incompatible types since an instance of List<SObject> is never an instance of List<Opportunity> at line 17
column 16


Is something changed or if I am missing something?
 
Hi,

My requirement is to create a button/link on account detail page on the first visualforce page.Clicking on that button should open second visualforce page, which will have Account Name (from First visualforce page) and 'Add New Contact'. button.Clicking on 'Add New Contact' will open third visualforce page, where I can enter Contact's first name and last name and save the contact.
Newly created contact's account name will be same as that of Account name from first visualforce page.

Regards,
Manish
Hi,

I have created a custom button in VF, using commandButton.Clicking on this button should update a custom field.
Though, I have implemented this, I have couple of challenges.
1)How do I add this button on Object Page layout, such that it appears on the Object detail page?
 2)Clicking on the button, updates the field.But the updated value is not shown, until the page is refresh 
    I want, updated value to be shown, when button is clicked and without refreshing the page.
   Below is my controller extension class.
  
public class ControllerEx3
{
   private final Account acct;
   public ControllerEx3(ApexPages.StandardController stdcontroller)
   {
    this.acct = (Account)stdcontroller.getRecord();
   }
   
   Public pagereference Activate()
   {
     string stat;
     Account act;
     act=[Select name, status__c from Account where ID=:acct.ID];
     stat=act.status__c;
     if (stat!='Active')
     {
       act.status__c='Active';
       update act;
      }
     return new PageReference('/'+act.Id);
     
   }
 }

 
Hi,

My requirement is to create a contact , by clicking a button on the account detail page. Button click will open a new vf page with contact fields onto it.Account name field on new vf page must be auto popuated, where as rest of the contact fields can be typed in.
How do I achieve this?
 
How do I call a method from the controller extension to a custom controller?
Below is the controller extension class:-
public with sharing class ControllerEx1
{
   public final Account acct;
   public ControllerEx1(Apexpages.StandardController stdcon) {
   this.acct=(Account)stdcon.getRecord();
   }
   public Account returnAccount()
   { 
     
     return acct;
   }
     public PageReference Add_Con_Or_Opp()
     {
       PageReference pr = new PageReference ('/apex/ContactsOrOpportunity');
       pr.setRedirect(true);
       return pr;
     }
   }

I want to call returnAccount() from above CE to below controller method.
global without sharing class MyController2
{
   public Account acnt{get;set;}
  ControllerEx1 c=new ControllerEx1();
   acnt=c.returnAccount();
}
It throws an Compile Error: unexpected token: '='  at the last line
Hi,

I am trying to create an input component on VF page that would only allow pre defined formatting to be entered by the user.
First 3 chars should be from A-Z/a-z.Next 3 chars should be from 0-9.Next 3 chars can be alphanumeric.
I have written below 'MyController' and VF pages.
Public class MyController
{
 
  Public Account act {get;set;}
  public Account getaccount()
  {
   act= [Select ID, Name,Description FROM Account
             Where Id= :ApexPages.CurrentPage().getParameters().get('id')];
        if(Pattern.matches('[A-Za-z]{3}[0-9]{3}[a-zA-Z0-9]{3}', act.Description))
        return act;
        else
        {
          ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Invalid Input.');
           ApexPages.addMessage(myMsg);
           return Null;
        }
   }
   
   Public PageReference save() 
   {
     update act;
     return Null;
   }
 }

VisualForce Page-
<apex:page controller="MyController">
<apex:form >
<apex:PageBlock >
<apex:inputField value="{!act.description}" />
<apex:commandButton action="{!Save}" value="Save new description" />
<apex:pageMessages />
</apex:PageBlock>
</apex:form>
</apex:page>
When I execute above VF, through an ID. I get a text field and by entering description, when I try to save it. It give me below error.
Attempt to de-reference a null object. Error is in expression '{!Save}' in component <apex:commandButton> in page scenario4: Class.MyController.save

 
Hi,

How we can implement below validation on VF input field?
Create an input component on VF page that would only allow pre defined formatting to be entered by the user.
First 3 chars should be from A-Z/a-z.Next 3 chars should be from 0-9.Next 3 chars can be alphanumeric.
Is it doable without javascript or HTML5? If yes, How?
 
Hi,
My requirement is -A user shouldn't be able to create opportunites more than worth 100k in a day. I am writing a trigger in the apex class for this.Below is the code.
public class TriggerClass
{
  public void checkOpps(List<Opportunity> ops)
  {
    Double Total_Amount=0;
    for(Opportunity o1: [Select Amount from Opportunity where createdDate=Today AND CreatedByID=:UserInfo.getuserID()])
    {
      Total_Amount += o1.Amount;
    }
     for (opportunity o2:ops)
    {
    Total_Amount+=o2.amount;
    }
    If(Total_Amount>1000000)
    {
     o2.addError('You have exceeded Daily Limits');
     }
     }
     }

It thorws a compile error:  Compile Error: Variable does not exist: Amount 
When I comment the line-Total_Amount += o1.Amount, it gives an error-Loop variable must be an SObject or list of Opportunity  (for the first For loop).
What I am missing here.
Note- I know this can be done in many other ways, but I am interested in knowing reason for these errors in the above code
Hi,
I was trying below trailhead challenge for Bulk Apex Triggers.

To complete this challenge, you need to add a trigger for Opportunity. The trigger will add a task to any opportunity inserted or updated with the stage of 'Closed Won'. The task's subject must be 'Follow Up Test Task'.
The Apex trigger must be called 'ClosedOpportunityTrigger'
With 'ClosedOpportunityTrigger' active, if an opportunity is inserted or updated with a stage of 'Closed Won', it will have a task created with the subject 'Follow Up Test Task'.
To associate the task with the opportunity, fill the 'WhatId' field with the opportunity ID.
This challenge specifically tests 200 records in one operation.

I wrote below code:-
trigger ClosedOpportunityTrigger on Opportunity (after insert, after update) {
   List<Task> taskList = new List<Task>();
    for (Opportunity opp : [SELECT Id, StageName FROM Opportunity WHERE StageName = 'Closed Won' AND Id IN :Trigger.new])
   {
    taskList.add(new Task(Subject = 'Follow Up Test Task',
    WhatId = opp.Id));
    }
   if(taskList.size()>0){
        insert taskList;
        }
    }
It throws an error-Variable Doesn't exist:ID at line 6 (WhatID=opp.ID)
What, I am missing here?

 
Create an Apex trigger for Account that matches Shipping Address Postal Code with Billing Address Postal Code based on a custom field.
I am writing following code:-

trigger AccountAddressTrigger on Account (before insert,before update)
{
    List <Account> act= [Select id,name from Account where BillingPostalCode != NULL and Match_Billing_Address__c='True' ];
        For(Account a:act)
       {
           a.ShippingPostalCode=BillingPostalCode;
            }
}

It gives error-Varibale Doesn't exist:BillingPostalCode. 

What I am missing here?
Note- In the challenge, it's given, ShippingPostalCode and BillingPostalCode are the API name, 
Hi There,

I am writing a trigger to update a opporutnity related record, if any new /updated account doesn't have a one. 

trigger AddRelatedRecord on Account (after insert,after update) {
    List<Opportunity> oppList = new List<Opportunity>();
    
    // Get the related opportunities for the accounts in this trigger
    Map<Id,Account> acctsWithOpps = new Map<Id,Account>(
        [SELECT Id,(SELECT Id FROM Opportunities) FROM Account WHERE Id IN :Trigger.New]);
    
    // Add an opportunity for each account if it doesn't already have one.
    // Iterate through each account.
    for(Account a : Trigger.New) {
        System.debug('acctsWithOpps.get(a.Id).Opportunities.size()=' + acctsWithOpps.get(a.Id).Opportunities.size());
        // Check if the account already has a related opportunity.
        if (acctsWithOpps.get(a.Id).Opportunities.size() == 0) {
            // If it doesn't, add a default opportunity
            oppList.add(Name=a.Account + ' Opportunity',
                                       StageName='Prospecting',
                                       CloseDate=System.today().addMonths(1),AccountId=a.Id);
        }           
    }

    if (oppList.size() > 0) {
        insert oppList;
    }

}

It throws an error in line 15: Variable doesn't exist:Name.

What I am missing here?
Hi,

I am trying to display all accounts, and for each account, the first and the last name of each contact associated with that account.
I am trying below APEX code.
List <Account> Res = [Select Account.Name, (Select Contact.FirstName,Contact.LastName from Account.contacts) from Account];
For(Account a:Res) {
//System.debug('Account Name:' +a.name);
//System.debug('Contact FirstName:' +contact.firstname); 
//System.debug('Contact Last Name:' +contact.LastName);  
}
 It displays the account name perfectly fine. But for Contact FirstName, it displays: FirstName , similarly for lastname it displays:LastName.
What, I am missing, here?
I have a requirement - Need to create at max 3 opportunity records for any account in a day.
Can someone guide me on on this requirement?
I keep getting this error when I try to save the following code...any idea what I've got wrong? 

Error: Compile Error: Illegal assignment from List<Proposal__c> to Id at line 13 column 3


public with sharing class AnotherController
{
 private ApexPages.StandardController stdCtrl;
  
 public AnotherController(ApexPages.StandardController std)
 {
  stdCtrl=std;
 }
  
 public void PopulateProject()
 {
  Project__c proj=(Project__c) stdCtrl.getRecord();
  proj.Proposal__c=[select Scope_of_Work__c from Proposal__c where Id=:proj.Proposal__c];
  proj.Scope_of_Work__c=proj.Proposal__c.Scope_of_Work__c;
 }
}
1)The Review_c object have a lookup relationship to the job_Application_c object.The job_Application_c object has a master detail relationship up to the
 position_c object.The relationship is based on the auto populated defaults? 
 What is the recommended way to display field data from the related Review _C records a Visualforce page for a single Position_c record?
 
 A.Utilize the Standard Controller for Position_c and cross-object Formula Fields on the Review_c object to display Review_c data.
 B.Utilize the Standard Controller for Position_c and a Controller Extension to query for Review _ C data.
 C.Utilize the Standard Controller for Position_c and expression syntax in the Page to display related Review_c through me Job_Applicacion_c inject.
 D.Utilize the Standard Controller for Position_c and cross-object Formula Fields on the Job_Application c object to display Review_c data.


2)A company has a custom object named Warehouse. Each Warehouse record has a distinct record owner, and is related to a parent Account in Salesforce. 
  Which kind of relationship would a developer use to relate the Account to Warehouse?
 
  A. Lookup
  B. One to Many
  C. Master-Detail
  d. Parent-Child


3)A developer wants to create a custom object to track Customer Invoices. 
  How should Invoices and Accounts be related to ensure that all Invoices are visible to everyone with access to an Account?

A. The Invoice should have a Master-Detail relationship to the Account
B. The Account should have a Master-Detail relationship to the Invoice.

4)What should a developer working in a sandbox use to exercise a new test class before the developer deploys that test class to production? Choose 2 answers
  
 A.The REST API and ApexTestRun method
 B.The Run Tests page in Salesforce Setup
 C.The Apex Test Execution page in Salesforce Setup
 D.The Test menu in the Developer Console
 
1)Which declarative method helps ensure quality data?
  Choose 3 answers

  A.Validation rules
  B.Workflow alerts
  C.Lookup filters
  D.Page Layout


2)A developer creates an Apex helper class to handle complex trigger logic.
  How can the helper class warn users when the trigger exceeds DML governor limits?

  A. By using Messaging.SendEmail() to continue the transaction and send an alert to the user after the number of DML statements is exceeded.
  B. By using ApexMessage.Message() to display an error message after the number of DML statements is exceeded.
  C. By using Limits.getDMLRows() and then displaying an error message before the number of DML statements is exceeded.
  D. By using PageReference.setRedirect() to redirect the user to a custom Visualforce page before the number of DML statements is exceeded.

3)In the Lightning Component framework, which resource can be used to fire events?
   2 Answers correct
  
   A.Third-party Javascript code
   B.Javascript controller actions
   C.Third-party web service code.
   D.Visualforce controller actions.
Hi,

I am confused while it comes to order of execution of 'before triggers' and 'validation rules' while saving a record in salesforce. Salesforce document says-1)System Validation 2)Before Triggers 3)Custom Validation. I had this question in my developer exam and 2 options were confusing.
A)Before Triggers  B) Validation Rules,
Options were-1)AB 2)BA 
Which one of above is correct?

 
Hi,

I am trying to implememnt a standardsetcontroller. I copy pasted the apex code from saslesforce document example-
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_pages_standardsetcontroller.htm
Below is the code-
public class opportunityList2Con {
    // ApexPages.StandardSetController must be instantiated
    // for standard list controllers
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                    [SELECT Name, CloseDate FROM Opportunity]));
            }
            return setCon;
        }
        set;
    }

    // Initialize setCon and return a list of records
    public List<Opportunity> getOpportunities() {
        return (List<Opportunity>) setCon.getRecords();
    }
}

when I save this I get an error-
Error: Compile Error: Incompatible types since an instance of List<SObject> is never an instance of List<Opportunity> at line 17
column 16


Is something changed or if I am missing something?
 
Hi,

I have created a custom button in VF, using commandButton.Clicking on this button should update a custom field.
Though, I have implemented this, I have couple of challenges.
1)How do I add this button on Object Page layout, such that it appears on the Object detail page?
 2)Clicking on the button, updates the field.But the updated value is not shown, until the page is refresh 
    I want, updated value to be shown, when button is clicked and without refreshing the page.
   Below is my controller extension class.
  
public class ControllerEx3
{
   private final Account acct;
   public ControllerEx3(ApexPages.StandardController stdcontroller)
   {
    this.acct = (Account)stdcontroller.getRecord();
   }
   
   Public pagereference Activate()
   {
     string stat;
     Account act;
     act=[Select name, status__c from Account where ID=:acct.ID];
     stat=act.status__c;
     if (stat!='Active')
     {
       act.status__c='Active';
       update act;
      }
     return new PageReference('/'+act.Id);
     
   }
 }

 
Hi,

My requirement is to create a contact , by clicking a button on the account detail page. Button click will open a new vf page with contact fields onto it.Account name field on new vf page must be auto popuated, where as rest of the contact fields can be typed in.
How do I achieve this?
 
Hi,

I am trying to create an input component on VF page that would only allow pre defined formatting to be entered by the user.
First 3 chars should be from A-Z/a-z.Next 3 chars should be from 0-9.Next 3 chars can be alphanumeric.
I have written below 'MyController' and VF pages.
Public class MyController
{
 
  Public Account act {get;set;}
  public Account getaccount()
  {
   act= [Select ID, Name,Description FROM Account
             Where Id= :ApexPages.CurrentPage().getParameters().get('id')];
        if(Pattern.matches('[A-Za-z]{3}[0-9]{3}[a-zA-Z0-9]{3}', act.Description))
        return act;
        else
        {
          ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Invalid Input.');
           ApexPages.addMessage(myMsg);
           return Null;
        }
   }
   
   Public PageReference save() 
   {
     update act;
     return Null;
   }
 }

VisualForce Page-
<apex:page controller="MyController">
<apex:form >
<apex:PageBlock >
<apex:inputField value="{!act.description}" />
<apex:commandButton action="{!Save}" value="Save new description" />
<apex:pageMessages />
</apex:PageBlock>
</apex:form>
</apex:page>
When I execute above VF, through an ID. I get a text field and by entering description, when I try to save it. It give me below error.
Attempt to de-reference a null object. Error is in expression '{!Save}' in component <apex:commandButton> in page scenario4: Class.MyController.save

 
Hi,
I am trying to execute below SOSL query in Apexcode:

List<List<Sobject>> searchlist=[FIND 'Pencil*' IN ALL FIELDS RETURNING Merchandise__c (Id,Name), Invoice_Statement__c];
Merchandise__c[] merList = ((List<Merchandise__c>) searchList[0]);
Invoice_Statement__c[] invList = ((List<Invoice_Statement__c) searchList[1]);
System.debug('Found' + merList.size() + 'merchandise items.'); 
System.debug('Found' + invList.size() + 'invoice statements.');

I get an error message- Unexpected Token: 'List'
What could be the reason?