• Sarvani
  • SMARTIE
  • 905 Points
  • Member since 2018

  • Chatter
    Feed
  • 31
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 128
    Replies
Hi, my task is to schedule apex to delete all files related to Lead records after 7 days from the file's createddate. 

How would I write that query/ DML? 

Based on the provided SIC code I want to update a field with the respective Industry Title. Since there are too many SIC Codes to work with formula fields (exceeding field limits) I am left with Apex. 

I  have list of SIC Codes and their corresponding Industry Title; 
lets say 

​​​​​​​1 = Industry A
2 = Industry B
3 = Industry C


Can you help with an Apex Class that uses the SWITCH statement to update a text field 'Industry_Title__c' (Text) based on a given value in the field 'SIC_Code__c' (Integer).

And can you help with a Trigger that executes the above class on every field change of 'SIC_Code__c'.
Thanks guys!

I have a apex class for a visualforce page with the soql query that i would like to addition conditions but when i try to add the change i get an error. I'm not sure how my query should be disigned.
"
Error: Compile Error: Expecting ']' but was: 'OR' at line 13 column 227"
 
// Used on the account page updated 1-31-2020
Public Class VF_SiteServicePartnerAllController{
   private Account acc;
   public List<Site_Service_Partner__c> sspList {get;set;}
   
   public VF_SiteServicePartnerAllController(ApexPages.StandardController sp){
       acc = (Account)sp.getRecord();
       sspList = new List<Site_Service_Partner__c>();
       sspList = [SELECT Id,Name,Site_Account__c,Primary_Field_Contact__c,Service_Partner__c,
                  Service_Partner_Owner__c,Service_Partner_Owner_Mobile__c,Service_Partner_Owner_Email__c,
                  Primary_Field_Email__c,Primary_Field_Mobile__c,Service_Partner_Site_Status__c, 
                  Contracted_Services__c,Secondary_Field_Contact__c,Secondary_Field_Email__c,Secondary_Field_Mobile__c,
                  Service_Partner_Start_Date__c,Service_Partner_End_Date__c,Service_Partner_Main_Phone__c,Trade__c,Supported_Trade__c  FROM Site_Service_Partner__c WHERE Site_Account__c =: acc.Id AND Trade__c includes('Land') OR Trade__c includes('Snow') AND Service_Partner_Site_Status__c = 'Active' ];

    
    Set<Id> bidId = new  Set<Id>();  
    for(Site_Service_Partner__c bs:sspList){
       bidId.add(bs.Id);
    }
     
   }

}




 
  • February 07, 2020
  • Like
  • 0
Email to case is set up. Detail comes in to the description: 

First Name: xxxxx
Last Name: Test
Email: test@gmail.com
Phone: xxxxxxxx
Country: US
Comment: Last Test!
TextAlertsOptIn: Yes

I ahve Fields for each option and I need to pass the information in to those fields. the format is the same every time. 

Any suggestions or examples of how this can be done, Trigger? New to apex and any detail is appreciated. 

 
Not having any success creating a Validation Rule on User to prevent the update of the standard User field "Title".
 If amount is greater than 10000 then stage should allow closed won other wise throw an error, on opportunity
I am trying to make a very simple VF page that shows some text and a "Back" button.  I can't figure out the "Back" button.  Can someone help fix this code?  Thanks!
<apex:page standardController="Opportunity">

  
  <h1>You need to create an Opportunity directly from a Contact.</h1>

<apex:form>
<apex:commandButton value="Cancel" oncomplete="doRedirect();"/>                

            <script type="text/javascript">
                function doRedirect(){
                    window.history.back();
                }

            </script>
</apexform>
</apex:page>
I am writing a simple piece of code that will create a record on the detail side of a relationship upon creation of a record on the master side of relationship, if a checkbox is checked.
 
trigger SilaTrigger on Sila__c (after insert) {
    for(Sila__c a : Trigger.New) {
        if(a.Checkbox__c = true) {
            Dependent__c b = new Dependent__c();
            b.Name = a.Name;
            b.Sila__c = a.Id;
            insert b;
        } else return;
    }
    

}

However I am recieving an error:

SilaTrigger: execution of AfterInsert caused by: System.FinalException: Record is read-only Trigger.SilaTrigger: line 3, column 1

How do I fix this? I think I am supposed to use "after insert" because I need to know the ID of Master record, so I can populate the detail field with the ID of the master.

Thanks alot
Hi, I'm using this validation rule to ensure users type in phone numbers in this format (xxx) xxx-xxxx:
NOT(REGEX(Phone, "\\D*?(\\d\\D*?){10}"))
 
I found this specific vr in Salesforce Help.
This is for Contacts.
Problem I'm having: The validation rule is firing even when the number is inputted in the right format. I tried it in production, developer account and sandbox and it is still doing the same thing.
Thanks.
I have a simple VF page that displays one field from the object. If the field is blank/null, I want the page to display text that says "No notes entered". Is there a way to do this? 

Here is my page so far:

<apex:page standardController="Discharge__c" lightningStylesheets="true">
    <apex:pageblock >
       <apex:repeat value="{!Discharge__c}" var="dc">
                <apex:outputField value="{!dc.Progress_Notes__c}" id="aa"/> 
        </apex:repeat>
        </apex:pageblock>
</apex:page>
trigger TestTrigger on TestObj2__c (after insert) {
    Set<Id> ids = new Set<Id>();
    
    for(TestObj2__c a: Trigger.New) {
        ids.add(a.Account__c);
    }
    Account[] acs = [select Id from Account where Id in :ids];
    for(Account b :acs) {
        b.TestField__c = 'BECOMING A PROGRAMMER';
    }

}

Expectation: After I create a record of object TestObj2__c, a field of it's master object Account will get populated with "BECOMING A PROGRAMMER".

It does not do that though. Even wrote a test method for this, says the same:
 
@isTest
public class TestTestTrigger {
    @isTest static void td(){
        Account a = new Account(Name = 'fun');
        insert a;
        TestObj2__c b = new TestObj2__c();
        b.Name = 'Fun';
        b.Account__c = a.Id;
        insert b;
        
        Account isPopulated = [select TestField__c from Account where id = :b.Account__c];
        System.assertEquals('BECOMING A PROGRAMMER', isPopulated.TestField__c);
    
    }

}
Error Message	System.AssertException: Assertion Failed: Expected: BECOMING A PROGRAMMER, Actual: test
Stack Trace	Class.TestTestTrigger.td: line 12, column 1


Can anyone tell me what's missing in the puzzle?
 
I"m trying to create a validation rule when a change to a record is made but the Employment picklist is blank (aka no values have been selected), the user must make a selection in the picklist before saving. I tried this formula but its not working as intended. Any ideas? Thanks
 
AND(
ISCHANGED(Id),
NOT(ISBLANK(TEXT(Employment__c))))

 
  • January 28, 2020
  • Like
  • 0
public class MessageMaker {
    public static string helloMessage() {
return ('You say "Goodbye," I say "Hello"'); 
        system.debug('You say "Goodbye," I say "Hello"');
    }
    

}
how to call this method in anonymous window???
I have the following validation rule and I want it to only prevent creation of new opportunities if one already exists and is open (what Count of Opportunities is counting). However, I had an account executive unable to Close Won an existing Opportunity which is the only opp on the account because of it.  

AND(
Account.Count_of_Opportunities__c>0,
$User.Title == "Account Executive",
isnew()
)
I have a requirement where in i need to fetch a list of knowledge articles related to a specific data category. Like my data category name is 'How_to__c' here I need to find the number of Knowledge articles linked to this data category.

Any help will be really appreciated
Hello ALl,
I have a controller for a VF page where I am returing fileds from a parent and multiple child records.
Here is the code in the controller
Accountres = [Select Id,(select Amount__c,Fee_Type__c,Invoice__c from Customer__r where Invoice__c = null) from Account where id=:acctId];

The issue I am having is that the criteria for the Customer__r is not working.  If I have 3 customer and 2 of them have an invoice I want only 1 record returned but  Instead I get all 3.  
Thanks,
P
Please help with the following error. Thank you! 
User-added imageUser-added image
I would like to query the account history where I am excluding certain account record types.

I am developing the query in Workbench and am currently using the Workbench SOQL query tab.

As a first step I tried to get the Account.RecordTypeId, but neither of the following worked (after allowing for querying parent-child relationships in settings):
 
SELECT AccountId.RecordTypeId FROM AccountHistory LIMIT 10
Fails with: "Didn't understand relationship 'AccountId' in field path."
 
SELECT AccountId__r.RecordTypeId FROM AccountHistory LIMIT 10
Fails with: "Didn't understand relationship 'AccountId__r' in field path."
 
SELECT AccountId.RecordTypeId__r FROM AccountHistory LIMIT 10
Fails with: "Didn't understand relationship 'AccountId' in field path."

Ultimately I am using the query to get data via the python package Simple Salesforce. Alternative approaches are also welcome.






 
I'm trying to achieve a 100% coverage but I'm only getting 71%. Lines 7-8 on the AccountProcessor class are uncovered by my test class. Any ideas?.

AccountProcessor Class
public class AccountProcessor {
    @future
    public static void countContacts(List<Id> accountIds) {
        List<Account> acctsToUpdate = new List<Account>();
        for (Account a : [SELECT Id, (SELECT Id FROM Contacts) FROM Account
                        WHERE Id IN: accountIds]){
            a.Number_of_Contacts__c = a.Contacts.size();
            acctsToUpdate.add(a);                                            
        }
        update acctsToUpdate;
    }
}
AccountProcessor Test Class
@isTest
public class AccountProcessorTest {
    @isTest 
    public static void testCountOfContacts() {
        List<Account> newAccts = new List<Account>();
        List<Contact> newConts = new List<Contact>();
        
        for(Integer x=0;x>5;x++) {
            newAccts.add(new Account(Name='New Account '+x));
        }
        insert newAccts;

        for(Account a:newAccts) {
            for(Integer y=0;y>2;y++){
                newConts.add(new Contact(LastName=a.Name+y,
                                         AccountId=a.Id));
            }
        }
        insert newConts;

        List<Id> accountIds = new List<Id>(new Map<Id,Account>(newAccts).keySet());

        Test.startTest();
            AccountProcessor.countContacts(accountIds);
        Test.stopTest();
        
        for(Account a: [SELECT Id, Number_of_Contacts__c FROM Account
                        WHERE Id IN: accountIds]){
        System.assertEquals(2, a.Number_of_Contacts__c);
        }
    }
}

 
I am not new to SQL, but I am new to SOQL.  I have a custom field in the user object that I cannot reach with owner.<custom field>

I've been researching how to do this, and I still have yet to figure out a solution.  Is there no way for me to access it in a query?  

An example query I need to work is this:

SELECT id, name, owern.name, owner.<custom field> FROM lead WHERE id = <my value>

Can anyone tell me the correct syntax, or confirm it is "impossible" with SOQL?  Is there an alternative using SOSL if so?



 
Hi,
I am new to Web components and When ever i am trying to insert a record in Contact Object it was saving with only FirstName,Lastname,Physical Attributes but i am getting Input of all other fields  in Js but in debug Logs it was showing only data of FirstName,Lastname, not Physical Attributes in ApexClass why?? Can i Know the  reason Why??

.HTML:

<template>
    <lightning-card title="Insert Contact" icon-name="standard:contact">
            <div class="slds-p-around_x-small">
                <lightning-input label="FirstName" value={rec.FirstName} onchange={handleFirstNameChange}></lightning-input>
                <lightning-input label="LastName" value={rec.LastName} onchange={handleLastNameChange}></lightning-input>
                <lightning-input type="text" label="PhysicalAttributes" value={rec.PhysicalAttributes} onchange={handlePhysicalAttributesChange}></lightning-input><br/>
                <lightning-button label="Save" onclick={handleClick}></lightning-button>
            </div>
        </lightning-card>
</template>

Js File:

import { LightningElement,track } from 'lwc';
import createContact from '@salesforce/apex/insertContactApexWeb.saveContactRecord';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';
import FIRSTNAME_FIELD from '@salesforce/schema/Contact.FirstName__c';
import LASTNAME_FIELD from '@salesforce/schema/Contact.LastName__c';
import PHYSICALATTRIBUTES_FIELD from '@salesforce/schema/Contact.Physical_Attributes__c';
export default class InsertContact extends LightningElement {
    @track firstname = FIRSTNAME_FIELD;
    @track lastname = LASTNAME_FIELD;
    @track physicalattributes = PHYSICALATTRIBUTES_FIELD;
    rec = {
        FirstName : this.firstname,
        LastName : this.lastname,
        PhysicalAttributes : this.physicalattributes
    }
    handleFirstNameChange(event) {
        this.rec.FirstName = event.target.value;
        window.console.log("FirstName", this.rec.FirstName);
    }
    
    handleLastNameChange(event) {
        this.rec.LastName = event.target.value;
        window.console.log("LastName", this.rec.LastName);
    }
    
    handlePhysicalAttributesChange(event) {
        this.rec.PhysicalAttributes = event.target.value;
        window.console.log("PhysicalAttributes", this.rec.PhysicalAttributes);
    }
    handleClick() {
        createContact({ con : this.rec })
            .then(result => {
                this.message = result;
                this.error = undefined;
                if(this.message !== undefined) {
                    this.rec.Name = '';
                    this.rec.Industry = '';
                    this.rec.Phone = '';
                    this.dispatchEvent(
                        new ShowToastEvent({
                            title: 'Success',
                            message: 'Account created',
                            variant: 'success',
                        }),
                    );
                }
                
                window.console.log(JSON.stringify(result));
                window.console.log("result", this.message);
            })
            .catch(error => {
                this.message = undefined;
                this.error = error;
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Error creating record',
                        message: error.body.message,
                        variant: 'error',
                    }),
                );
                window.console.log("error", JSON.stringify(this.error));
            });
    }
    
}

Apex Class:

public with sharing class insertContactApexWeb {
   
    @AuraEnabled
    public static void saveContactRecord(Contact con){
        System.debug('acc--'+con);
        try{
            insert con;
        }
        catch(Exception ex) {
            throw new AuraHandledException(ex.getMessage());
        }
    }
}

 
Hi, my task is to schedule apex to delete all files related to Lead records after 7 days from the file's createddate. 

How would I write that query/ DML? 
@istest
private class Accountupdate {
    @istest
    static void tetslead(){
        List<Account> l= new List<Account>();
        Account a= new Account();
        a.Name='surya';
        a.Phone='123';
        l.add(a);
        insert l;
   
    Test.startTest();
    Accountupdate ap= new Accountupdate();
    Id jobid= Database.executeBatch(ap);
    Test.stopTest();
    }
}

class

global class Accountupdate implements Database.Batchable<sObject>
{

    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query = 'SELECT Id,Name,Phone FROM Account ';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<Account> scope)
    {
        for ( Account a : scope)
        {
           a.Phone='123';
        }
        update scope;
    }  
    global void finish(Database.BatchableContext BC)
    {
    }
}

I am getting below error

User-added image
Hello everyone,

I am trying to build an automated task using process builder when opportunity is on the specific stage. However, I have a problem with field picker. I want to assign this task to opportunity owner / the person created that opportunity.

User-added image
hi there 
Concerning a mail - to case.the mail is coming from a specific email address off course.
When such a case is created I need to update the account on this case.
It seems I cannot use a simple workflow because account is not available in the drop down (go only knows why, this could be to easy....).
Anyone got a clue how to do so without writing any apex code ?
thank you
Jeffrey

Based on the provided SIC code I want to update a field with the respective Industry Title. Since there are too many SIC Codes to work with formula fields (exceeding field limits) I am left with Apex. 

I  have list of SIC Codes and their corresponding Industry Title; 
lets say 

​​​​​​​1 = Industry A
2 = Industry B
3 = Industry C


Can you help with an Apex Class that uses the SWITCH statement to update a text field 'Industry_Title__c' (Text) based on a given value in the field 'SIC_Code__c' (Integer).

And can you help with a Trigger that executes the above class on every field change of 'SIC_Code__c'.
Thanks guys!

I have a apex class for a visualforce page with the soql query that i would like to addition conditions but when i try to add the change i get an error. I'm not sure how my query should be disigned.
"
Error: Compile Error: Expecting ']' but was: 'OR' at line 13 column 227"
 
// Used on the account page updated 1-31-2020
Public Class VF_SiteServicePartnerAllController{
   private Account acc;
   public List<Site_Service_Partner__c> sspList {get;set;}
   
   public VF_SiteServicePartnerAllController(ApexPages.StandardController sp){
       acc = (Account)sp.getRecord();
       sspList = new List<Site_Service_Partner__c>();
       sspList = [SELECT Id,Name,Site_Account__c,Primary_Field_Contact__c,Service_Partner__c,
                  Service_Partner_Owner__c,Service_Partner_Owner_Mobile__c,Service_Partner_Owner_Email__c,
                  Primary_Field_Email__c,Primary_Field_Mobile__c,Service_Partner_Site_Status__c, 
                  Contracted_Services__c,Secondary_Field_Contact__c,Secondary_Field_Email__c,Secondary_Field_Mobile__c,
                  Service_Partner_Start_Date__c,Service_Partner_End_Date__c,Service_Partner_Main_Phone__c,Trade__c,Supported_Trade__c  FROM Site_Service_Partner__c WHERE Site_Account__c =: acc.Id AND Trade__c includes('Land') OR Trade__c includes('Snow') AND Service_Partner_Site_Status__c = 'Active' ];

    
    Set<Id> bidId = new  Set<Id>();  
    for(Site_Service_Partner__c bs:sspList){
       bidId.add(bs.Id);
    }
     
   }

}




 
  • February 07, 2020
  • Like
  • 0
Hi I am trying to write a Apex class to create an account and return the record name and i am getting the below error:
Static method cannot be referenced from a non static context: String
Here is my Code:
public class AccountHandler {
      public static String insertNewAccount(String strNames)
      {
          try
          {
          Account acct = new Account();
            acct.Name = strNames;
            acct.Phone = '(415)555-1212';
            acct.NumberOfEmployees = 100;
        insert acct;
        ID acctID = acct.Id;
// Display this ID in the debug log
System.debug('ID = ' + acctID);
              return strNames;
          }
          catch(Exception ex)
          {
              return 'NULL';
          }
      }

}
Need to check to see if the first character of the first name is capitalized. The extra part is if there is a non-alpha character before the first letter, like *tim. In this case I want to check to see if the first letter is capitalized. This is what I have, but it is not working... This is for a workflow to check before running.
This is a validation rule I need it to evaluate to true if the first letter is not capitalized or if there is a non-alpha character, the second letter is not capitalized. Any help would be appreciated.
Email to case is set up. Detail comes in to the description: 

First Name: xxxxx
Last Name: Test
Email: test@gmail.com
Phone: xxxxxxxx
Country: US
Comment: Last Test!
TextAlertsOptIn: Yes

I ahve Fields for each option and I need to pass the information in to those fields. the format is the same every time. 

Any suggestions or examples of how this can be done, Trigger? New to apex and any detail is appreciated. 

 
Not having any success creating a Validation Rule on User to prevent the update of the standard User field "Title".
Hi, I'm using this validation rule to ensure users type in phone numbers in this format (xxx) xxx-xxxx:
NOT(REGEX(Phone, "\\D*?(\\d\\D*?){10}"))
 
I found this specific vr in Salesforce Help.
This is for Contacts.
Problem I'm having: The validation rule is firing even when the number is inputted in the right format. I tried it in production, developer account and sandbox and it is still doing the same thing.
Thanks.
Hi,
I am new to Web components and When ever i am trying to insert a record in Contact Object it was saving with only FirstName,Lastname,Physical Attributes but i am getting Input of all other fields  in Js but in debug Logs it was showing only data of FirstName,Lastname, not Physical Attributes in ApexClass why?? Can i Know the  reason Why??

.HTML:

<template>
    <lightning-card title="Insert Contact" icon-name="standard:contact">
            <div class="slds-p-around_x-small">
                <lightning-input label="FirstName" value={rec.FirstName} onchange={handleFirstNameChange}></lightning-input>
                <lightning-input label="LastName" value={rec.LastName} onchange={handleLastNameChange}></lightning-input>
                <lightning-input type="text" label="PhysicalAttributes" value={rec.PhysicalAttributes} onchange={handlePhysicalAttributesChange}></lightning-input><br/>
                <lightning-button label="Save" onclick={handleClick}></lightning-button>
            </div>
        </lightning-card>
</template>

Js File:

import { LightningElement,track } from 'lwc';
import createContact from '@salesforce/apex/insertContactApexWeb.saveContactRecord';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';
import FIRSTNAME_FIELD from '@salesforce/schema/Contact.FirstName__c';
import LASTNAME_FIELD from '@salesforce/schema/Contact.LastName__c';
import PHYSICALATTRIBUTES_FIELD from '@salesforce/schema/Contact.Physical_Attributes__c';
export default class InsertContact extends LightningElement {
    @track firstname = FIRSTNAME_FIELD;
    @track lastname = LASTNAME_FIELD;
    @track physicalattributes = PHYSICALATTRIBUTES_FIELD;
    rec = {
        FirstName : this.firstname,
        LastName : this.lastname,
        PhysicalAttributes : this.physicalattributes
    }
    handleFirstNameChange(event) {
        this.rec.FirstName = event.target.value;
        window.console.log("FirstName", this.rec.FirstName);
    }
    
    handleLastNameChange(event) {
        this.rec.LastName = event.target.value;
        window.console.log("LastName", this.rec.LastName);
    }
    
    handlePhysicalAttributesChange(event) {
        this.rec.PhysicalAttributes = event.target.value;
        window.console.log("PhysicalAttributes", this.rec.PhysicalAttributes);
    }
    handleClick() {
        createContact({ con : this.rec })
            .then(result => {
                this.message = result;
                this.error = undefined;
                if(this.message !== undefined) {
                    this.rec.Name = '';
                    this.rec.Industry = '';
                    this.rec.Phone = '';
                    this.dispatchEvent(
                        new ShowToastEvent({
                            title: 'Success',
                            message: 'Account created',
                            variant: 'success',
                        }),
                    );
                }
                
                window.console.log(JSON.stringify(result));
                window.console.log("result", this.message);
            })
            .catch(error => {
                this.message = undefined;
                this.error = error;
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Error creating record',
                        message: error.body.message,
                        variant: 'error',
                    }),
                );
                window.console.log("error", JSON.stringify(this.error));
            });
    }
    
}

Apex Class:

public with sharing class insertContactApexWeb {
   
    @AuraEnabled
    public static void saveContactRecord(Contact con){
        System.debug('acc--'+con);
        try{
            insert con;
        }
        catch(Exception ex) {
            throw new AuraHandledException(ex.getMessage());
        }
    }
}