• Sunnyalex
  • NEWBIE
  • 10 Points
  • Member since 2019
  • Som

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 2
    Likes Given
  • 13
    Questions
  • 6
    Replies
Hi,
I Have case object there is a tab called feed and under feed there is option to send email. So when email is getting draft then automatically it is adding 1 in number of email send feild which is present in Matrix tab.
I have tried with unchecking email draft from support setting but i want to increment the number of send mail to the field number of outgoing mail.
How to get that through flow any formula can you please provide for increment after email is send.
Please help me in getting CIBIL score (Credit Report) by PAN (Permanent Account Number) using Apex in Salesforce
 
Apex Class
.........................
public class NewAndExistingController {
    public Case Casea { get; public set; }
    public NewAndExistingController() {
        Id id = ApexPages.currentPage().getParameters().get('id');
        casea = (id == null) ? new Case() : 
            [SELECT AccountId,Description,Status,Subject FROM Case WHERE Id = :id];
    }
    public PageReference save() {
        try {
            insert(Casea);
        } catch(System.DMLException e) {
            ApexPages.addMessages(e);
            return null;
        }
        PageReference redirectSuccess = new ApexPages.StandardController(Casea).view();
        return (redirectSuccess);
    }
     public PageReference cancel() {
        try {
            insert(Casea);
        } catch(System.DMLException e) {
            ApexPages.addMessages(e);
            return null;
        }
        PageReference redirectSuccess = new ApexPages.StandardController(Casea).view();
        return (redirectSuccess);
    }}
...............................................................................................
Test class
..............
@isTest
public class TestClass {
    @isTest
    public static void testMethod1(){

        NewAndExistingController nEC = new NewAndExistingController();
        nEC.save();
        nEC.cancel();
        
        
    }
      
}
Suppose when a account is created then with same name i want to create a folder in google drive through rest api.
Integration with Google drive with salesforce is done but for creating a folder or file in Google drive when account is created how can we achieve.
Hi all,
Need to know how we can send email Template to all 10k  Contacts,
I know there is a limitation in salesforce so i want to send email to 1k next day again 1k like this i want to send how this is possible. 
public class MetadataUtility{

    public static void generateTextField(String objectAPIName, String fieldAPIName, String fieldDescription, String fieldLabel){
        String metadata = '{"Metadata" : {"type" : "Text","description" : "'+fieldDescription+'", "inlineHelpText" : "","precision" : null,"label" : "'+fieldLabel+'","length" : 255,"required" : false}, "FullName" : "'+objectAPIName+'.'+fieldAPIName+'"}';

        String responseBody = createField(metadata);
    }

    public static void generateFormulaField(String objectAPIName, String fieldAPIName, String fieldDescription, String fieldLabel, String retrunType, String validFormula){
        
        String metadata = '{"Metadata" : {"type" : "'+retrunType+'","description" : "'+fieldDescription+'", "formula" : "'+String.escapeSingleQuotes(validFormula)+'","formulaTreatBlanksAs" : "BlankAsZero","label" : "'+fieldLabel+'"}, "FullName" : "'+objectAPIName+'.'+fieldAPIName+'"}';
        String responseBody = createField(metadata);
        system.debug(responseBody);
    }
    
    
    public static String createField(String metadata) {
        HttpRequest request = new HttpRequest();
        request.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
        request.setHeader('Content-Type', 'application/json');
        request.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/v46.0/tooling/sobjects/CustomField');
        request.setMethod('POST');
        
        request.setBody(metadata);
        
        Http http = new Http();
        HTTPResponse res = http.send(request);
        return res.getBody();
    }
}
...............................................................................................................
with this methods i am only able to create Text field and Formula field how to write methods  for phone,Date,Email,Number,Picklist etc
String.isnotBlank(rr.r.Receipt_status__c) && 
                    rr.r.Receipt_status__c.equalsIgnoreCase('Processed for industry') && 
                    String.isNotBlank(rr.rCloned.Ranking__c) &&
                    rr.rCloned.Banking__c.equalsIgnoreCase('Payment') && 
                    String.isNotBlank(rr.r.Currency__c) &&
                    !(rr.r.Currency__c.equalsIgnoreCase('Indian') || rr.r.Currency__c.equalsIgnoreCase('RUPEES')) &&
                    rr.rCloned.Forex__c == null
                ) {
                    rr.style2 = 'error';
                    error = true;


if(tempList1.size() > 0)
draft.createNewId(tempList1);


i have a code in apex like this how can i use createNewId to create test class

public with sharing class adpContactUsController {

    public String personalizedMessage1 {get; set;}
    public String personalizedMessage2 {get; set;}
    public String personalizedMessage3 {get; set;}
    
    public adpContactUsController (){
        User u = [Select Id, ContactId from User where Id =: UserInfo.getUserId()];
        
        List<Contact> conlist = [Select Id, Advocacy_Staff_Partner__c,Advocacy_Staff_Partner__r.X18_ID__c from Contact where id =: u.ContactId]; 
                
        if(conlist.size() > 0){
            if(conlist[0].Advocacy_Staff_Partner__c == null) {
                personalizedMessage1 = defaultMessage();
            }
            else {
            ADP_StaffData__c adpStaffData = ADP_StaffData__c.getValues(conlist[0].Advocacy_Staff_Partner__c);
            if(adpStaffData != null) {
                personalizedMessage1 = adpStaffData.Personal_Message1__c;
                personalizedMessage2 = adpStaffData.Personal_Message2__c;
                personalizedMessage3 = adpStaffData.Personal_Message3__c;
            }
            
           }
        } else {
            personalizedMessage1 = defaultMessage();
        }
        
    }
    
    private String defaultMessage(){
        List<ADP_StaffData__c> adpStaffDatalist = ADP_StaffData__c.getAll().values();
            String defMsg = '';
            for(ADP_StaffData__c adpDefMsg : adpStaffDatalist){
                if(adpDefMsg.Default_Message__c) {
                   defMsg = adpDefMsg.Personal_Message1__c + ' ' + adpDefMsg.Personal_Message2__c + ' ' + adpDefMsg.Personal_Message3__c;
                   break;                 
                }
            }
            return defMsg.replaceAll('null', '');
    }
    
    public PageReference SeeAllAdvocates(){
        
        PageReference pageRef = new PageReference('/apex/AdvocatesListView');
        pageRef.setRedirect(true);
        return pageRef;
        
    }
    
    public PageReference EmailNewAdvocates(){
        
        PageReference pageRef = new PageReference('/apex/AdvocatesListView?type=new');
        pageRef.setRedirect(true);
        return pageRef;
        
    }
    
    public PageReference EmailAllAdvocates(){
        
        PageReference pageRef = new PageReference('/apex/AdvocatesListView?type=all');
        pageRef.setRedirect(true);
        return pageRef;
        
    }
    
    public PageReference createNewHouseholdContact(){
         Contact con = New Contact();
         Id Contact_HRTypeID = Schema.sObjectType.Contact.getRecordTypeInfosByName().get('Household Contact').getRecordTypeId();
         PageReference contactDetailsPage = new PageReference('/003/e');
         contactDetailsPage.getParameters().put('RecordType',Contact_HRTypeID);
         String returnURL = '/'+Page.adpHomeNew.getUrl().right(10);
         contactDetailsPage.getParameters().put('retURL', returnURL.escapeHtml3());
         contactDetailsPage.setRedirect(true);
         return contactDetailsPage;
    }
}
//////////////////////////////////////////
@isTest
public class adpContactUsControllerTest {
    
    @testSetup static void setup() {
        
        Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator'];

        fF_Location__c defaultLocation = new fF_Location__c(Name = 'Default Location', Is_Default_Unknown_Location__c = true);
        insert defaultLocation; 
        
        User u = new User(Alias = 't3stUser', Email='testUser@testkeyimpact.com', EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
                          LocaleSidKey='en_US', ProfileId = p.Id, TimeZoneSidKey='America/Los_Angeles', UserName='testusertest@keyimpact.com');
        
        INSERT u;
        Id RecordTypeIdContact = Schema.SObjectType.Contact.getRecordTypeInfosByName().get('Organization Contact').getRecordTypeId();
        Id RecordTypeIdAccount = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Household').getRecordTypeId();
        Account acc = new Account();
        acc.Name = 'test account';
        acc.recordtypeid = RecordTypeIdAccount;
        insert acc;
        contact con = new contact();
        con.recordtypeid = RecordTypeIdContact;
        con.AccountId = acc.id;
        con.LastName = 'test con';
        con.Email = 'test0@test.com';
        insert con;
        
        contact con1 = new contact();
        con1.Advocacy_Staff_Partner__c = con.id; 
        con1.recordtypeid = RecordTypeIdContact;
        con1.LastName = 'test con1';
        con1.Email = 'test1@test.com';
        insert con1;
    }
    static testmethod void loginTest(){ 
        adpContactUsController adpCon =  new adpContactUsController();
        adpCon.SeeAllAdvocates();
        adpCon.EmailNewAdvocates();
        adpCon.createNewHouseholdContact();
        PageReference pageRef = adpCon.EmailAllAdvocates();
        System.assertNotEquals (null,pageRef);
    }
}
public class AllocationListController {

    @AuraEnabled
    public static Allocation__c getAllocation(Id Allocation) {
        System.debug('Allocationid'+Allocation);
        
        List<Allocation__c> AllocationList = [SELECT id,Name,Amount_Allocated__c,Amount_Pending_Allocation__c     FROM Allocation__c where Id=:Allocation];
        System.debug('AllocationList'+AllocationList);
        return AllocationList [0];
    }
       @AuraEnabled
    public static List<npsp__General_Accounting_Unit__c> getGau() {
        List<npsp__General_Accounting_Unit__c> GauList = [SELECT Id,Name FROM npsp__General_Accounting_Unit__c];
        System.debug('General Accounting Units'+GauList);
        return GauList;
    }
   
    @AuraEnabled
    public static string doAllocate(List<npsp__Allocation__c> lstSelectedRecords, Allocation__c allocationrecord){
        //list<npsp__Allocation__c>= new list<npsp__Allocation__c>();
       // List<npsp__Allocation__c> npspList = new List<npsp__Allocation__c>();
        system.debug('lstSelectedRecords ' +lstSelectedRecords + 'allocationrecord ' +allocationrecord);
        decimal total=0;
        list<Fund_Allocation__c> lstFundAllocation= new list<Fund_Allocation__c>();
        for(npsp__Allocation__c var: lstselectedrecords ){
            lstFundAllocation.add(new Fund_Allocation__c(
                Amount_Donated__c = var.Amount_Pending_Allocation__c,
                GAU_Allocation__c = var.id,
                Patient_Id__c = allocationrecord.id, 
                Name = allocationrecord.Name
            ) );
            var.Amount_Allocated__c+=var.Amount_Pending_Allocation__c;
            total+= var.Amount_Pending_Allocation__c;
        }
        if(!lstselectedrecords.isempty()){
            update lstselectedrecords;
            insert lstFundAllocation;
            system.debug('total'+total);
            if (total <> null){
                 allocationrecord.Amount_Allocated__c += total;
            }
           // allocationrecord.Amount_Allocated__c+=total;
          //update allocationrecord;
         try{
                update allocationrecord;
            }
            catch (Exception e){
           // throw new AuraHandledException('Amount Pending Allocation Should not be greater than Amount'+e.getMessage());  
           //throw new AuraHandledException( ' Amount Pending Allocation Should not be greater than Amount ==>');    
           throw new AuraHandledException(e.getMessage().substringBetween('FIELD_CUSTOM_VALIDATION_EXCEPTION, ',': ') );  
             
                
            }
        }
        
        return null;
    }
    
    @AuraEnabled
    public static Fund_Allocation__c getfunding (Id funding) {
        System.debug('fundingid'+funding);
  
        List<Fund_Allocation__c> fundingList = [SELECT Id,Name,Amount_Required__c FROM Fund_Allocation__c where Id=:funding];
        System.debug('fundingList'+fundingList);
        return fundingList[0];
    }
    
    
    
    
    @AuraEnabled
    public static List<npsp__Allocation__c> getgauallocations(String Gau) {
        system.debug(Gau);
       Gau= Gau.remove('.');
         system.debug(Gau);
        List<npsp__Allocation__c> allList = [SELECT Id,npsp__General_Accounting_Unit__c,Amount_Allocated__c,Donor_Name__c,
                                             Name,Amount_Pending_Allocation__c,npsp__Amount__c 
                                             FROM npsp__Allocation__c 
                                             where Amount_Pending_Allocation__c>0  
                                             and npsp__General_Accounting_Unit__c =:Gau 
                                             ORDER BY
                                             Amount_Pending_Allocation__c ASC];
       system.debug(allList);
        return allList;
    } 
}
One will need to create an event in the activity section in recieved response stage  to log a meeting date before moving to meeting Schedule. How can I restrict that user to go to another stage from moving to another stage.
I have to force that user to fill the form which is present in the new event part. Without filling he cannot move to another stage.
I have restricted the fields but still not working
Hello everyone,
i have got one requirement please help me in solving this requirement.
When an Account’s BillingPostalCode (Zip Code), is changed,
Change the Account Owner to the sales representative assigned to the new zip code
Change the Owner field of all the Account’s Contacts to the same sales rep 
Change the Owner field of all the Account’s Open Opportunities to the same sales rep.

1:The logic should run only when the Account’s zip code is changed or populated for the first time
2:If no matching Territories are found, do nothing



Thanks and Regards
Raj Sourav 
Hello everyone,
i have got one requirement please help me in solving this requirement.
When an Account’s BillingPostalCode (Zip Code), is changed,
Change the Account Owner to the sales representative assigned to the new zip code
Change the Owner field of all the Account’s Contacts to the same sales rep 
Change the Owner field of all the Account’s Open Opportunities to the same sales rep.

1:The logic should run only when the Account’s zip code is changed or populated for the first time
2:If no matching Territories are found, do nothing



Thanks and Regards
Apex Class
.........................
public class NewAndExistingController {
    public Case Casea { get; public set; }
    public NewAndExistingController() {
        Id id = ApexPages.currentPage().getParameters().get('id');
        casea = (id == null) ? new Case() : 
            [SELECT AccountId,Description,Status,Subject FROM Case WHERE Id = :id];
    }
    public PageReference save() {
        try {
            insert(Casea);
        } catch(System.DMLException e) {
            ApexPages.addMessages(e);
            return null;
        }
        PageReference redirectSuccess = new ApexPages.StandardController(Casea).view();
        return (redirectSuccess);
    }
     public PageReference cancel() {
        try {
            insert(Casea);
        } catch(System.DMLException e) {
            ApexPages.addMessages(e);
            return null;
        }
        PageReference redirectSuccess = new ApexPages.StandardController(Casea).view();
        return (redirectSuccess);
    }}
...............................................................................................
Test class
..............
@isTest
public class TestClass {
    @isTest
    public static void testMethod1(){

        NewAndExistingController nEC = new NewAndExistingController();
        nEC.save();
        nEC.cancel();
        
        
    }
      
}
Hi all,
Need to know how we can send email Template to all 10k  Contacts,
I know there is a limitation in salesforce so i want to send email to 1k next day again 1k like this i want to send how this is possible. 
public class MetadataUtility{

    public static void generateTextField(String objectAPIName, String fieldAPIName, String fieldDescription, String fieldLabel){
        String metadata = '{"Metadata" : {"type" : "Text","description" : "'+fieldDescription+'", "inlineHelpText" : "","precision" : null,"label" : "'+fieldLabel+'","length" : 255,"required" : false}, "FullName" : "'+objectAPIName+'.'+fieldAPIName+'"}';

        String responseBody = createField(metadata);
    }

    public static void generateFormulaField(String objectAPIName, String fieldAPIName, String fieldDescription, String fieldLabel, String retrunType, String validFormula){
        
        String metadata = '{"Metadata" : {"type" : "'+retrunType+'","description" : "'+fieldDescription+'", "formula" : "'+String.escapeSingleQuotes(validFormula)+'","formulaTreatBlanksAs" : "BlankAsZero","label" : "'+fieldLabel+'"}, "FullName" : "'+objectAPIName+'.'+fieldAPIName+'"}';
        String responseBody = createField(metadata);
        system.debug(responseBody);
    }
    
    
    public static String createField(String metadata) {
        HttpRequest request = new HttpRequest();
        request.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
        request.setHeader('Content-Type', 'application/json');
        request.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/v46.0/tooling/sobjects/CustomField');
        request.setMethod('POST');
        
        request.setBody(metadata);
        
        Http http = new Http();
        HTTPResponse res = http.send(request);
        return res.getBody();
    }
}
...............................................................................................................
with this methods i am only able to create Text field and Formula field how to write methods  for phone,Date,Email,Number,Picklist etc
public class AllocationListController {

    @AuraEnabled
    public static Allocation__c getAllocation(Id Allocation) {
        System.debug('Allocationid'+Allocation);
        
        List<Allocation__c> AllocationList = [SELECT id,Name,Amount_Allocated__c,Amount_Pending_Allocation__c     FROM Allocation__c where Id=:Allocation];
        System.debug('AllocationList'+AllocationList);
        return AllocationList [0];
    }
       @AuraEnabled
    public static List<npsp__General_Accounting_Unit__c> getGau() {
        List<npsp__General_Accounting_Unit__c> GauList = [SELECT Id,Name FROM npsp__General_Accounting_Unit__c];
        System.debug('General Accounting Units'+GauList);
        return GauList;
    }
   
    @AuraEnabled
    public static string doAllocate(List<npsp__Allocation__c> lstSelectedRecords, Allocation__c allocationrecord){
        //list<npsp__Allocation__c>= new list<npsp__Allocation__c>();
       // List<npsp__Allocation__c> npspList = new List<npsp__Allocation__c>();
        system.debug('lstSelectedRecords ' +lstSelectedRecords + 'allocationrecord ' +allocationrecord);
        decimal total=0;
        list<Fund_Allocation__c> lstFundAllocation= new list<Fund_Allocation__c>();
        for(npsp__Allocation__c var: lstselectedrecords ){
            lstFundAllocation.add(new Fund_Allocation__c(
                Amount_Donated__c = var.Amount_Pending_Allocation__c,
                GAU_Allocation__c = var.id,
                Patient_Id__c = allocationrecord.id, 
                Name = allocationrecord.Name
            ) );
            var.Amount_Allocated__c+=var.Amount_Pending_Allocation__c;
            total+= var.Amount_Pending_Allocation__c;
        }
        if(!lstselectedrecords.isempty()){
            update lstselectedrecords;
            insert lstFundAllocation;
            system.debug('total'+total);
            if (total <> null){
                 allocationrecord.Amount_Allocated__c += total;
            }
           // allocationrecord.Amount_Allocated__c+=total;
          //update allocationrecord;
         try{
                update allocationrecord;
            }
            catch (Exception e){
           // throw new AuraHandledException('Amount Pending Allocation Should not be greater than Amount'+e.getMessage());  
           //throw new AuraHandledException( ' Amount Pending Allocation Should not be greater than Amount ==>');    
           throw new AuraHandledException(e.getMessage().substringBetween('FIELD_CUSTOM_VALIDATION_EXCEPTION, ',': ') );  
             
                
            }
        }
        
        return null;
    }
    
    @AuraEnabled
    public static Fund_Allocation__c getfunding (Id funding) {
        System.debug('fundingid'+funding);
  
        List<Fund_Allocation__c> fundingList = [SELECT Id,Name,Amount_Required__c FROM Fund_Allocation__c where Id=:funding];
        System.debug('fundingList'+fundingList);
        return fundingList[0];
    }
    
    
    
    
    @AuraEnabled
    public static List<npsp__Allocation__c> getgauallocations(String Gau) {
        system.debug(Gau);
       Gau= Gau.remove('.');
         system.debug(Gau);
        List<npsp__Allocation__c> allList = [SELECT Id,npsp__General_Accounting_Unit__c,Amount_Allocated__c,Donor_Name__c,
                                             Name,Amount_Pending_Allocation__c,npsp__Amount__c 
                                             FROM npsp__Allocation__c 
                                             where Amount_Pending_Allocation__c>0  
                                             and npsp__General_Accounting_Unit__c =:Gau 
                                             ORDER BY
                                             Amount_Pending_Allocation__c ASC];
       system.debug(allList);
        return allList;
    } 
}
Hello I want to make trigger for If a Territory__c record’s sales representative is changed (and only when it is changed), repeat Requirement #2’s logic for all Accounts associated with the Territory.
Here is requirement 2:
Requirement #2: When an Account’s BillingPostalCode (aka Zip Code), is changed,           
1. Change the Account Owner to the sales representative assigned to the new zip code          
2. Change the Owner field of all the Account’s Contacts to the same sales rep           
3. Change the Owner field of all the Account’s Open Opportunities to the same sales rep    
Hi I want to perform this scenario Multiple sales representatives can be assigned to the same zip code territory. If this is the case, use a random function to select one of the assigned sales representatives  Object is Territory__c
Inside this object : 
Records  
Zip CodeSales Representative
91000Blake
91001Blake
91002Blake
91002Jacqueline
91010Jacqueline
91020Jacqueline
92010Denise
92020Aaron
           Can anyone please help me out??
I have a requirement to login to multiple Salesforce orgs from the master org. One way is to use the SSO, are there any other ways to do it without SSO?
Hi,

I need to implement a "login on behalf" feature.

Let's say 2 user profiles exist: Customer and Customer Care.
A Customer Care user would authenticate as any Customer user, in order to perform actions on behalf of this Customer user.

What seems the most logic to me is that the Customer Care user initiates a, OAuth 2.0 JWT Bearer Flow, by providing the Customer user's email in the JWT payload, which he certainly knows about.

According to you, which approach(es) would be suitable for this kind of use case?

Thank you