Forum Replies Created

Page 1 of 2
    • Web server flow (In OAuth spec terms, Authorization Code Grant) tends to be used for web applications where server-side code needs to interact with Force.com APIs on the user's behalf, for example DocuSign:Tokens are sent directly from the Authorization Server to the OAuth Client app, providing a high level of security.
    • Username-Password flow (Resource Owner Password Credentials Grant) can be used for testing, or for apps that operate non-interactively, such as legacy integrations, without a user to actively give authorization:

      $ curl -d 'grant_type=password&client_id=3MV_CLIENT_ID&client_secret=1234&[email protected]&password=password' \
      https://login.salesforce.com/services/oauth2/token

      {
      "id":"https://login.salesforce.com/id/ORG_ID/USER_ID",
      "issued_at":"1385271368428",
      "instance_url":"https://na15.salesforce.com",
      "signature":"Vcz4TlGBQJCwJzNtH3AHT/kUFLM4N/sFrJODX2ZNuyE=",
      "access_token":"00D_ACCESS_TOKEN"
      }

      Username-password is generally discouraged and should be used only where no other alternative is available, due to the inherent problems with passwords.

    • User-Agent flow (Implicit Grant) tends to be used for mobile or desktop applications, for example Salesforce1 or Mobile SDK apps:Tokens are returned to the Client app via a 'hash fragment' on a URL.
  • Shaharyar

    Member
    September 6, 2017 at 5:49 am in reply to: What is the use of Metadata API in Salesforce?

     

    Use of Metadata API in Salesforce:

    • You can read, create, update, delete following components in a Salesforce organization.
    1. Custom Objects/Fields.
    2. Visualforce pages.
    3. Page Layouts.
    4. Validation rules.
    5. Apex.
    6. Workflows.
    7. Approval processes.
    8. Profiles.
    9. Reports etc.
    10. Security.
      You can configure a Salesforce organization just by running a piece of code. It means that you can create Objects,Fields,Validation,Workflows, Profiles, Reports for a particular client organization just by running the piece of code so that you need not do all the customisation settings manually which will consume time if you have to do that several times for different clients for the same configuration settings. You can also take the backup of your organization customisation settings just by fetching the metadata WSDL from your Salesforce org. For this You need to click setup>type API-Click on API >Click Generate metadata WSDL and download the xml file.

    Hope this may help You.If yes ,then don't forget to click Like!!!

  • Shaharyar

    Member
    September 5, 2017 at 11:58 am in reply to: what are the change set limitations in Salesforce?

    Hi Uday,

    • Following are the main limitations that you encounter with change sets:
    1. We cannot deploy all the types of metadata components in one shot.
    2. We can deploy only sandbox to sandbox or sandbox to production.
    3. Either deploy or rollback all the components on any failure.There is no way to deploy successful components and ignore the failed components.
    4. Salesforce Change sets do not support all types of metadata components.
    5. It’s not feasible to integrate Salesforce Change sets with any version control system.
    6. For any deployment, you need to upload Change sets and deploy them to the target organization. This greatly increases the deployment time.
    7. Any developer can make any modification to another organization if they have permissions to make changes to it. The auditor cannot track who made the changes to the organization.
  • Shaharyar

    Member
    August 29, 2017 at 5:26 am in reply to: What is the difference between WhoId and WhatId?

    WhatId: ID of a related Account, Opportunity, Campaign, Case, or custom object. Labelis Opportunity/Account ID.
    WhoId: ID of a related Contact or Lead. If the WhoId refers to a lead, then the WhatId field must be empty. Label is Contact/Lead ID. If Shared Activities is enabled, this is the ID of a related Lead or primary Contact.

    whoid & whatid

  • Shaharyar

    Member
    August 29, 2017 at 5:21 am in reply to: I am new to salesforce. i want to send email with attachment

     

    public class EmailStaticResource {

    public void StaticresourceDataAsEmail(){

    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

    email.setUseSignature(false);

    email.setSaveAsActivity(true);

    email.setSubject(‘Send Email using staticResource as body of mail ‘);

    String[] toAddresses = new String[] {‘[email protected]’};

    email.setToAddresses(toAddresses);

    email.setHtmlBody(‘<html><body>Dear devoplers<b>See the code for Email service</b></body></html>’);

    StaticResourcesr = [Select  Name, Id, Body From StaticResource where Name = ‘Document’];

    Blob tempBlob = sr.Body;

    Messaging.EmailFileAttachmentefa = new Messaging.EmailFileAttachment();

    efa.setBody(tempBlob);

    efa.setFileName(‘attachment.pdf’);

    email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});

    Messaging.SingleEmailMessage[] emailList = new Messaging.SingleEmailMessage[] {email};

    Messaging.sendEmail(emailList);

    }

    }

  •  

    Hi Aman,

    First make a field on account object with name "OppAmount" and then use this code:

    #Trigger
    trigger calAmount on Opportunity (after insert, after update, after delete) {
    Map<Id, List<Opportunity>> acctIdOpptyListMap = new Map<Id, List<Opportunity>>();
    Set<Id> acctIds = new Set<Id>();
    List<Opportunity> opptyList = new List<Opportunity>();
    if(trigger.isUpdate || trigger.isInsert){
    for(Opportunity oppty : trigger.New){
    if(oppty.AccountId != null){
    acctIds.add(oppty.AccountId);
    }
    }
    }
    if(trigger.isDelete){
    for(Opportunity oppty : trigger.old){
    if(oppty.AccountId != null){
    acctIds.add(oppty.AccountId);
    }
    }
    }
    if(acctIds.size() > 0){
    opptyList = [SELECT Amount, AccountId FROM Opportunity WHERE AccountId IN : acctIds];
    for(Opportunity oppty : opptyList){
    if(!acctIdOpptyListMap.containsKey(oppty.AccountId)){
    acctIdOpptyListMap.put(oppty.AccountId, new List<Opportunity>());
    }
    acctIdOpptyListMap.get(oppty.AccountId).add(oppty);
    }
    List<Account> acctList = new List<Account>();
    acctList = [SELECT OppAmount__c FROM Account WHERE Id IN: acctIds];
    for(Account acct : acctList){
    List<Opportunity> tempOpptyList = new List<Opportunity>();
    tempOpptyList = acctIdOpptyListMap.get(acct.Id);
    Double OppAmount = 0;
    for(Opportunity oppty : tempOpptyList){
    if(oppty.Amount != null){
    OppAmount += oppty.Amount;
    }
    }
    acct.OppAmount__c = OppAmount;
    }
    update acctList;
    }
    }

     

    Hope this may help u.

  • Answer-

    There could be few reasons

    1.      The “API Only User” perm has been set at the profile level, for the only Sys Admin profile in an org

    2.      A Permission Set has been assigned at the User level, to the only Sys Admin user in an org.

    3.      Make sure that you are login to right environment like there is sandbox or production.

  • Shaharyar

    Member
    August 22, 2017 at 10:35 am in reply to: How i can delete selected list value on button click in Salesforce?

    hi Shariq, Shubham

    Thanks for your response.

    I have some more requirements, i want to create 1 more button to update the selected value.

    the form should be opened on the same page .

  • Shaharyar

    Member
    August 21, 2017 at 11:00 am in reply to: How to retrieve related List of Objects which exist in Salesforce?

    Hello Shubham,

    Thanks for your answer but My question is different Suppose i don't know the name of related list which exist.Then how i can get the name of all related list.

     

    I have found this code while searching on net. But it is not working.

    Plese check it if u can make it correct:

    public class getRelatedList {

    public static map<string,string> getRelatedObjects(string Account){

    map<string,string> relatedObjectsMap = new map<string,string>();
    list<Schema.Childrelationship> relatedObjectsList = Schema.getGlobalDescribe().get(Account).getdescribe().getChildRelationships();
    for (Schema.Childrelationship relatedObject : relatedObjectsList) {
    if(relatedObject.getChildSObject().getDescribe().isUpdateable()
    &&
    relatedObject.getChildSObject().getDescribe().getKeyPrefix()!=null
    &&
    !relatedObject.getChildSObject().getDescribe().isCustomSetting()
    &&
    relatedObject.getChildSObject().getDescribe().isCreateable()
    )
    relatedObjectsMap.put(relatedObject.getChildSObject().getDescribe().getName(),relatedObject.getChildSObject().getDescribe().getLabel());
    }
    return relatedObjectsMap;
    }
    }

  • @Saloni

    Want more clarification?

    What if, both the organization have same environment??

  • trigger preventDeletionAccount on Account (before delete) {
    List<Account> acc=new List<Account>();
    for(Account acc:trigger.old)
    {
    if(acc.Rating=='Hot'){
    acc.addError('Prevents Deletion');
    }
    }
    }

  • Hi Radakrishna,

    Use this

    Select Id, Name from Account where ID NOT IN (Select AccountId from Contact) AND ID NOT IN (Select AccountId from Opportunity)

  • Shaharyar

    Member
    August 19, 2017 at 7:14 am in reply to: what is salesforce lifecycle?

    Salesforce Lifecycle is the steps from Requirement to completion Phase:

    Typical development lifecycle:

    1-Plan functional requirements.
    2-Develop using Salesforce Web tools, using profiles to hide your changes until they’re ready to deploy.
    3-Update profiles to reveal your changes to the appropriate users.
    4-Notify end users of changes.

  • Hi Raghav,

    Thanks for showing your interest in asking question on this platform.

    Make your Question clear so that i can assist you?

    If you are asking for difference between APEX & JAVA then here is your answer.

    Apex classes and Java classes work in similar ways, but there are some significant differences.
    These are the major differences between Apex classes and Java classes:
    Inner classes and interfaces can only be declared one level deep inside an outer class.
    Static methods and variables can only be declared in a top-level class definition, not in an inner class.
    An inner class behaves like a static Java inner class, but doesn’t require the static keyword. An inner class can have instance member variables like an outer class, but there is no implicit pointer to an instance of the outer class (using the this keyword).
    The private access modifier is the default, and means that the method or variable is accessible only within the Apex class in which it is defined. If you do not specify an access modifier, the method or variable is private.
    Specifying no access modifier for a method or variable and the private access modifier are synonymous.
    The public access modifier means the method or variable can be used by any Apex in this application or namespace.
    The global access modifier means the method or variable can be used by any Apex code that has access to the class, not just the Apex code in the same application. This access modifier should be used for any method that needs to be referenced outside of the application, either in the SOAP API or by other Apex code. If you declare a method or variable as global, you must also declare the class that contains it as global.
    Methods and classes are final by default.
    The virtual definition modifier allows extension and overrides.
    The override keyword must be used explicitly on methods that override base class methods.
    Interface methods have no modifiers—they are always global.
    Exception classes must extend either exception or another user-defined exception.
    Their names must end with the word exception.
    Exception classes have four implicit constructors that are built-in, although you can add others.
    Classes and interfaces can be defined in triggers and anonymous blocks, but only as local.

  • Shaharyar

    Member
    August 16, 2017 at 4:16 am in reply to: I need the formula for a workflow in Salesforce

    Hello Radhakrishna,

    Workflow Rules

    Setup > Workflow Rules > New Rule > Object Product > Enter Rule Name > Select created in Evaluation Criteria > In Rule Criteria enter Product: Product Record Type > Operator equal > Select needed record type in Value field > Save & next

    Add Workflow Action > Field update > Select checkbox that should pe checked > Set Checkbox Options = True > Save > Activate

    If this solves your questions please like it otherwise you have to use process builder.

    process builder:

    Setup > Process Builder > New > Enter name > Starts when record changes > Save
    Add object > Product (select it from the list, do not enter it manually) > Start only when a record is created > Save
    Add criteria > Enter criteria name > Formula evaluates to true > [Product2].RecordType.DeveloperName = "XYZ" > Save
    Add immediate action > Update records > Record type : Select the Product2 record that started your process > Select checkbox field = True

    • This reply was modified 7 years, 3 months ago by  Shaharyar.
    • This reply was modified 7 years, 3 months ago by  Shaharyar.
  • Shaharyar

    Member
    August 15, 2017 at 7:26 pm in reply to: How to access map on visualforce page?

    Visiting the following link may help you to understand...
    developer.salesforce.com/forums/?id=906F0000000971EIAQ

    • This reply was modified 7 years, 3 months ago by  Shaharyar.
  • Hello Saloni,

    #Static Method :

    Static methods are methods that act globally and not in the context of a particular object of a class. Being global, static methods only have access to its provided inputs and other static (global) variables.

    This example illustrates static vs. non-static methods
    public class LightJedi {
    public void slashLightsaber() {
    // Vooooom!
    }

    public static String getJediCode() {
    String code = 'There is no emotion, there is peace.';
    code += 'There is no ignorance, there is knowledge.';
    code += 'There is no passion, there is serenity.';
    code += 'There is no death, there is the Force.';
    return code;
    }

    public static String describeRank(String rank) {
    String description;
    if (rank == 'Initiate') {
    description = 'Jedi hopeful';
    } else if (rank == 'Padawan') {
    description = 'Apprentice of a Jedi Knight';
    } else if (rank == 'Knight') {
    description = 'Completed the Jedi Trials';
    } else if (rank == 'Master') {
    description = 'David Liu';
    }
    return description;
    }
    }

    // Elsewhere...
    LightJedi davidLiu = new LightJedi();

    // Non-static methods require an object for context
    davidLiu.slashLightsaber();

    // Static methods aren't related to a particular object
    LightJedi.getJediCode();

    // You don't even use an object to call a static method!
    System.debug(LightJedi.describeRank('Master')); // David Liu

    Other examples of static methods could be convert millimeters to centimeters, subtract two numbers, and convert String to uppercase.

  • Shaharyar

    Member
    August 12, 2017 at 3:24 am in reply to: What are salesforce instances?

    Hello Shariq,

    An instance of Salesforce is the specific configuration that you see when you log into Salesforce. So my instance of Salesforce is what I see when I log in which is different from your instance when you log in which is different from what everyone else sees when they log in.

    for eg:-
    https://ap1.salesforce.com/003/o

    Here, ap1 is the instance of Salesforce I am using.

    Hope this may help u.

  • Shaharyar

    Member
    August 12, 2017 at 3:19 am in reply to: What is @TestSetup annotation?

    Hello Shubham,

    As you know that, Initially we had to create test data in every test method, because every test method is considered a different transaction with its own governor limits. But Salesforce has introduced @TestSetUp annotation for test class method. You can write a method in test class, with @TestSetUp annotation applied, and create all your common test data in this method.

    Few key points about TestSetUp methods:

    • Method marked with @TestSetUp annotation executes before any testMethod.
    • Data created in this method doesn’t need to be created again and again, and it is by default available for all test methods.
    • There can be only one setup method per test class.
    • Test setup methods are supported only with the default data isolation mode for a test class. If the test class or a test method has access to organization data by using the @isTest(SeeAllData=true) annotation, test setup methods aren’t supported in this class.
    • Test setup methods are available for 24.0 or later versions only.
    • Every test method will get unchanged version of the test data created in setup method, doesn’t matter if any other test method has modified the data. I will show this in testMethod2 of below example.

    @isTest
    private class TestSetupMethodExample {
    //Below is a method with @testsetup annotation, the name can be anything like setup(), oneTimeData(), etc.
    @testSetup static void setup() {
    // Create common test accounts
    List<Account> testAccts = new List<Account>();
    for(Integer i=0;i<2;i++) {
    testAccts.add(new Account(Name = 'TestAcct'+i));
    }
    insert testAccts;
    }

    @isTest static void testMethod1() {
    // Here, we will see if test data created in setup method is available or not, Get the first test account by using a SOQL query
    Account acct = [SELECT Id FROM Account WHERE Name='TestAcct0' LIMIT 1];
    // Modify first account
    acct.Phone = '555-1212';
    // This update is local to this test method only.
    update acct;

    // Delete second account
    Account acct2 = [SELECT Id FROM Account WHERE Name='TestAcct1' LIMIT 1];
    // This deletion is local to this test method only.
    delete acct2;

    // Perform some testing
    }

    @isTest static void testMethod2() {
    // The changes made by testMethod1() are rolled back and
    // are not visible to this test method.
    // Get the first account by using a SOQL query
    Account acct = [SELECT Phone FROM Account WHERE Name='TestAcct0' LIMIT 1];
    // Verify that test account created by test setup method is unaltered.
    System.assertEquals(null, acct.Phone);

    // Get the second account by using a SOQL query
    Account acct2 = [SELECT Id FROM Account WHERE Name='TestAcct1' LIMIT 1];
    // Verify test account created by test setup method is unaltered.
    System.assertNotEquals(null, acct2);

    // Perform some testing
    }

    }

     

  • Shaharyar

    Member
    August 12, 2017 at 3:10 am in reply to: What is TestVisible Annotation in Salesforce?

    @TestVisible Annotation.

    This annotation enables a more permissive access level for running tests only. TestVisible annotation allow test methods to access private or protected members of another class outside the test class. These members include methods, member variables, and inner classes.

    • This example shows how to annotate a private class member variable and private method with TestVisible.

    public class TestVisibleExample {
    @TestVisible private static Integer recordNumber = 1;
    @TestVisible private static void updateRecord(String name) {
    }
    }

    • This is the test class that uses the previous class. It contains the test method that accesses the annotated member variable and method.

    @isTest
    private class TestVisibleExampleTest {
    @isTest static void test1() {
    // Access private variable annotated with TestVisible
    Integer i = TestVisibleExample.recordNumber;
    System.assertEquals(1, i);

    // Access private method annotated with TestVisible
    TestVisibleExample.updateRecord('RecordName');
    // Perform some verification
    }
    }

  • Thanks!!!

  • Shaharyar

    Member
    August 10, 2017 at 5:12 am in reply to: SOQL Query ( Accounts and Contacts ) in Salesforce

    Hello Rahul,

    #Apex Class

    public class AccountAndContacts {

    public static void displayContacts(){
    List<Account> acc=[Select Id,Name from Account];
    for(Account a:acc){
    List<Contact> con=[Select LastName from contact where AccountId=:a.id];
    for(Contact c:con){
    if(con.size()>1){
    System.debug('AccountName '+''+a.Name+'RelatedContacts '+''+c.LastName);
    }}}}}

     

     

    #Anonymous Window

    AccountAndContacts.displayContacts();

     

    #Check the output in debugger log...

    Hope it will help you.

    Note:I have written it in simple understandable ,way you can optimize code by using nested query.

  • Shaharyar

    Member
    August 9, 2017 at 4:09 pm in reply to: What is wrapper class in Salesforce?

    Hello Aman,

    Wrapper we can understand as the outer part of any kind of things (object like custom, standard, checkbox etc)that is wrapped with some kind of material.

    A wrapper is a class or container whose instance is a collection of other objects.

    The best example is when you apply for any jobs in websites the page looks like checkbox, job description, apply button, there are different objects but all of them displayed in a single page that is wrapper class

    example..
    public class MyClassContainer{ //main class
    public List<wrapClass> new List<wrapClass>(); //instance of wrapper class
    public class wrapClass{ //wrapper class
    List<Account> acct{get;set;}
    List<Opportunity> oppt{get;set;}
    List<contact> cnct{get;set;}
    public wrapClass(Account acct , Contact cnct , Opportunity oppt){
    acct = new List<Account>();
    oppt = new List<Opportunity>();
    cnct = new List<contact>();
    this.acct = acct;
    this.cnct = cnct;
    this.oppt = oppt;
    }
    }
    }

    Here my class "MyClassContainer" contain three different collection object which is (List of Account, contact and Opportunity).

    if we want to display three object which is Account, contact and Opportunity on one page then we make the instance of "MyClassContainer"
    here the wrapper class comes into the picture.

  • Shaharyar

    Member
    August 9, 2017 at 12:18 pm in reply to: How to restrict tab/view/Object in salesforce other than Profile?

    Hi Tanu,

    Profiles define your basic level of access. Anything not present at the profile level can be granted using permission sets.

    However when to use a new profile vs a permission set depends on the number of users you anticipate.

    When 10 out 100 users need additional permission it is feasible to create a base profile with minimal permissions and create a permission set with additional access ans assign it to the 10 users.

    However, when the number of users exceeds a manageble count of around 1-30 it is advisable to have separate profiles and assign it to applicable users

    1. Profile A (with the base permission)

    2. Profile B (Profile A permissions  + additional permissions)

    There is not other way in Salesforce to grant access over profiles

Page 1 of 2