• Jithin Krishnan 2
  • SMARTIE
  • 578 Points
  • Member since 2015
  • Team Lead
  • Accenture


  • Chatter
    Feed
  • 13
    Best Answers
  • 0
    Likes Received
  • 2
    Likes Given
  • 0
    Questions
  • 60
    Replies
in Apex Basics&Database SOSL Queries
We have challenge to pass the string parameter as input and depend upon that string made sosl query
but in reality how can you make that
searchQuery in SOSL accept text search
syntax as find 'smith' in all fields

So the question is how can we put the variable name in place of string???
Hi everyone!

My validation rule, below, works, but I need to make it possible for this field to be left blank:

IF(Value(fieldname) > Year(TODAY()),true,IF(LEN(fieldname)=4,false,true))

- I think I need to add something but not sure where to start

IF (not(isblank(fieldname)), 
    ????????????,
NULL)


I have not yet go my head around the syntax! 
Why my custom checkbox is always checked when I try to save as uncheck in the account object?

This is happening only when I have a active trigger. The trigger which I wrote is simple one to check whether that checkbox is "checked" or not, then copy the postal code from Billing address to shipping address. 

When that particular trigger is "Inactive" and tried to save the record with that checkbox as "unchecked" it is working good.
Not sure why this trigger is always "checked" the checkbox when I save the record.

This is my trigger:
Trigger AccountAddressTrigger on Account (before insert,before update) {
       for (Account a : Trigger.new)
   {
           if(a.Match_Billing_address__C = True)
       {
         if(a.BillingPostalCode != NULL)
               {
       a.ShippingPostalCode= a.BillingPostalCode;
                  } 
           }
   }
   
}
 
Hi
I am new to Salesforce, trying to understand classes and methods.When I complied the below code it give the below error.

public class Myhelloworld
{
    public static void applyDiscount(Book__c[] books)
    {
        for(list<Book__c[]> b:Books)
    {
    b.Price__c *=0.9;
    }
  
Error: Compile Error: Initial term of field expression must be a concrete SObject: List<List<Book__c>> at line 7 column 5

Thanks
K.Kogila
Challenge Question:
Assume a company needs a user whose job is to solely review existing accounts and report on them, but does not require the ability to edit the records. They should only see records from the Account object. Create the correct profile for this user.The profile must be named 'Account Reviewer'.
The 'Account Reviewer' profile should use the 'Salesforce' user license type.
Any user assigned to the 'Account Reviewer' profile should only have read access to the Account object (and no access to any other object in the Org).


I did every thing as tiralhead instructed but i am getting this error.

Challenge not yet complete... here's what's wrong:
The 'Account Reviewer' profile does not work as expected
in this challenge Your Developer Edition comes with a System Administrator user. Create a new user using the System Administrator profile and then deactivate that user to preserve the licenses in your org.The new user must use the System Administrator Profile.
The username for the new user must include 'guestadmin' somewhere in it.
The new user must be inactive
.

I am getting this error "Error: Duplicate Username.
The username already exists in this or another Salesforce organization. Usernames must be unique across all Salesforce organizations. To resolve, use a different username (it doesn't need to match the user's email address).
While trying below FORMULA TRAILHEAD (https://developer.salesforce.com/trailhead/point_click_business_logic/formula_fields), getting error while saving FORMULA. Any help

Formula Object - CASE
FORMULA Return- number of days between the account’s Last Activity Date and today
Formula Code- 
Account.LastModifiedDate  -    TODAY()
Error -  Error: Incorrect parameter type for operator '-'. Expected Number, DateTime, received Date

If I change TODAY() to NOW() the compilation error gets resolved but challenge evaluation fails with following errors

Challenge not yet complete... here's what's wrong: 
The 'Days_Since_Last_Update__c' formula field did not return the correct number of days between an Account’s Last Activity Date and today

Thanks
Priya
I don't know why I can't seem to "get" this. I've tried so many things and can't seem to logically think through it today.
I have a field Check_Out_Date__c
If this field is completed I need this field Expected_Check_In_Date__c to be required.
I know this is simple but I can't seem to get it today.
Thanks so much!!
Kel
Here is my controller:
public class NewCaseListController {
    public static List<Case> getNewCases() {
        List<Case> results = [SELECT Id, CaseNumber FROM Case WHERE Status ='New'];
        return results;
    }
}
Here is my page:
<apex:page controller="NewCaseListController">
    <apex:repeat value="{! newCases }" var="case">
        <li><apex:outputLink value="/{!case.Id}">{!case.CaseNumber}</apex:outputLink></li>
    </apex:repeat>
</apex:page>
Here is the result:
User-added image
But when I verify the challenge I get:
"Challenge not yet complete... here's what's wrong:
Case records were not returned upon calling 'getNewCases'. Either the method does not exist, or it does not return the expected list of cases."
I'm new to coding. On https://developer.salesforce.com/trailhead/apex_database/apex_database_sobjects, it says "creating an sObject doesn’t persist it as a record in the database. To save the sObject as a record, and do other things with it, you’ll need to use DML." I'm trying to understanding why and whether this is something specific to sObject (i.e. SFDC), or is this common with other programming languages too?
Hi, i want to create a contact when a new user is created. I tried process builder and trigger but get the following error (trigger):

MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa):Contact, original object: User: []: Trigger.NewContactOnUser: line 19, column 1

Here is the code:

trigger NewContactOnUser on User (before insert) {
    List<Contact> contacts = new List<Contact>();
    for (User u: trigger.new){
        Contact c = new Contact();
        c.FirstName = u.FirstName;
        c.LastName = u.LastName;
        c.Email = u.Email;
        c.MailingStreet = u.Street;
        c.MailingCity = u.City;
        c.MailingState = u.State;
        c.MailingCountry = u.Country;
        c.MailingPostalCode = u.PostalCode;
        c.Title = u.Title;
        c.Phone = u.Phone;
        c.AccountID = '001W000000JgPzp';       
        
        contacts.add(c);       
    }
    insert contacts;


Can anyone help fix this or any ideas to create a contact from a user record?

Thanks!
 
  • September 22, 2015
  • Like
  • 0
I have tried this process builder challenge several times and different ways and still get an error message.  Here are the screenshots of what I am trying:
User-added image
User-added image
User-added image
When I test the process it works, however, I get the following error message from the trailhead:
Challenge not yet complete... here's what's wrong: 
An update to an account record failed to update the mailing address fields of all child contact records. Make sure that the process is correct and that it is activated.

Can you please tell me where I have gone wrong?
 
Hi,

I am working on a query where I have to count distinct values from inside query in related object using Group By and Having and use that value in main query.

For example :

select Firstname from Contact where Account.Name in (
SELECT Name
FROM Account
GROUP BY Name
HAVING Count(Id) = 1)

This query is throwing error : "Unknown error parsing query"
string ratingValue = 'Hot';
public List<Account> lstAccount{get;set;}
string strQuery = 'select id, name, rating, industry,( select id, firstname, lastname, phone, fax from contacts) from account where rating =: ratingValue';
lstAccount = Database.Query(strQuery);
    if(lstAccount.size()!= 0)
    {
    for(Account acc : lstAccount)
    {
        system.debug(acc.id + ' ----> '+ acc.name + ' ----> '+acc.rating + ' ----> '+ acc.industry );
        
        system.debug('Contact Records Information.');
        system.debug('Contact Count ....: '+ acc.contacts.size());
        
        if(acc.contacts.size() > 0)
        {
            for(contact con : acc.contacts)
            {
                system.debug(con.id + ' ---> ' + con.firstname + ' ----> ' + con.lastname);
            }
        }
        else
            system.debug ('No Contacts for this Account');
    }
}
else
{
    system.debug('Account Record Not Found.');
}
  
  • October 08, 2015
  • Like
  • 0
I mentioned my return type as Contact in my method
until you specify that Contact record with DML statement it won't save to database
and if you won't specify systm.debug , we can't see the output in debug log
But if you are not using the DML statment and system.debug
How &&Where can you use the returned values from any method in apex class???????
Hi,
I am having one field called start date which is of type date field  i need to update the field based on the conditiotn and add days  to start date

Like This if(x=y)
{ start date = (today()- end date)}
but iam getting an error due to conversion type, can some help  me to choose any function avl to do this..

thanks..
Is it possible to enable multi-currency in a developer org? I know this requires sending a case, but since this is not an option within the developer instances I didn't know if there was another way to accomplish this. 

I have two field :::
1. model number (field type :::test) = pc896 (selected value)
2.pc/Dc Exception (field type: checlbox) = marked (set the velue)
i want to create one validation rule that if i entered the model number = pc896 for that checkbox will automatically marked..
Please help me developer
 

 

  • October 08, 2015
  • Like
  • 0
in Apex Basics&Database SOSL Queries
We have challenge to pass the string parameter as input and depend upon that string made sosl query
but in reality how can you make that
searchQuery in SOSL accept text search
syntax as find 'smith' in all fields

So the question is how can we put the variable name in place of string???
Hi

We have a custom visualforce page that has it's content pulled to it by different Apex Classes.
In short, the records pulled are determined by their record type + a certain field entry. 

Right now the Apex Class pulls in RecordTypeA results. 
I can edit it (and the Test Class) to pull in RecordTypeB results.

However, when I use the 'OR' expression to have both of the RecordType results show up, only RecordTypeA results are shown up.

This is the code piece (syntax gave no errors)
 
for(recordtype rt:[select id from recordtype where (name=:'1893 Ambassador Request' OR name=:'WebAMB Request') and Sobjecttype =: 'Case' limit 1]) caserecordtype=rt.id; for(recordtype rt:[select id from recordtype where name=: 'CustomerUK' and Sobjecttype =: 'Account' limit 1]) accountrecordtype=rt.id;

Is there something else that needs to be added to the code for it to process both record type results? 

Thank you
Hi everyone!

My validation rule, below, works, but I need to make it possible for this field to be left blank:

IF(Value(fieldname) > Year(TODAY()),true,IF(LEN(fieldname)=4,false,true))

- I think I need to add something but not sure where to start

IF (not(isblank(fieldname)), 
    ????????????,
NULL)


I have not yet go my head around the syntax! 
I am passing a person ID to a function that creates opportunities.
I am completely stumped because the Account ID equals null.
If it makes any difference, the account is a person account
below is the code:

static void CreateServices(Account a)
    {
        system.debug(a.FirstName+'firstname'+a.Id);  //when I do this the names print but not the ID. What is going on?
        List<RecordType> opRecordType = [SELECT id, Name FROM RecordType WHERE SobjectType = 'Opportunity'];
        For (RecordType rt: opRecordType)
        {
               
            Opportunity newOpp= new opportunity();
            newOpp.Name='test' +i;
            newOpp.RecordTypeId=rt.ID;
            i++;
            newOpp.AccountId= a.Id;
            system.debug('account ID'+a.Id);
            ... //code adds more details to the opportunity.
            createdServices.add(newOpp);
        }
        
    }
Why my custom checkbox is always checked when I try to save as uncheck in the account object?

This is happening only when I have a active trigger. The trigger which I wrote is simple one to check whether that checkbox is "checked" or not, then copy the postal code from Billing address to shipping address. 

When that particular trigger is "Inactive" and tried to save the record with that checkbox as "unchecked" it is working good.
Not sure why this trigger is always "checked" the checkbox when I save the record.

This is my trigger:
Trigger AccountAddressTrigger on Account (before insert,before update) {
       for (Account a : Trigger.new)
   {
           if(a.Match_Billing_address__C = True)
       {
         if(a.BillingPostalCode != NULL)
               {
       a.ShippingPostalCode= a.BillingPostalCode;
                  } 
           }
   }
   
}
 
Hi
I am new to Salesforce, trying to understand classes and methods.When I complied the below code it give the below error.

public class Myhelloworld
{
    public static void applyDiscount(Book__c[] books)
    {
        for(list<Book__c[]> b:Books)
    {
    b.Price__c *=0.9;
    }
  
Error: Compile Error: Initial term of field expression must be a concrete SObject: List<List<Book__c>> at line 7 column 5

Thanks
K.Kogila
In reference to the follwoing Challenge.

This challenge requires you to create a custom object with a few custom fields. This object will describe trail information for a park and hence will need to track name, distance and the last date it was inspected.Create a custom object with 'Trail' as the Label and Object Name. The resulting API name will need to be 'Trail__c'.
The Name field for Trail must be a Text type (not Auto Number).
Add a custom field to Trail of the 'Text Area (Long)' type, which has the field name and label 'Description' and a resulting API name of 'Description__c'. The field should have the default character length of 32,768.
Add a custom field to Trail of the 'Number' type (length of 3 and 0 decimal places), which has the field name and label 'Distance' and a resulting API name of 'Distance__c'.
Add a custom field to Trail of the 'Date' (not 'Date/Time') type, which has the field label 'Last Inspection Date' and name 'Last_Inspection_Date' and a resulting API name of 'Last_Inspection_Date__c'.Completed this challenge but I keep getting an error message.

I've completed the challeng but I keep getting the error message that it can't find the object. I've double checked the spelling and relaunched/ reconnected my developer and still no success.
I am having 2 scenario something like this :
1. I have created one custom field named "lookup realtion" on standard object Account.. I want to fire trigger in such a way that when ever new account is inserted with the same name contact is being created and the custom field on Account which i have created should get populated with the contact name. and 
2. is on the account and contact I had created the custom field named "Checkbox" which is of checkbox type... and while insertion if account checkbox is checked the checkbox field on contact  should also be get checked and later on when i uncheck the checkbox on account the contact field checkbox also be get unchecked. I had written the code which perfectly well for creating the contact when ever new account is being created.. but I am facing problem in implementin these two above mentioned logics.. plz edit my code and suggest me your innovative Ideas..
public class CreateAccountContact 
{
 trigger CreateAccountContact on Account (after insert, after update){

if(Trigger.isInsert){

    List<Contact> ct = new List <Contact>();   
    for(Account acc : trigger.new){    
        Contact c = new Contact();       
                    c.LastName = acc.name;
                    c.AccountId=acc.id;
                    c.Fax=acc.Fax;
                    c.MailingStreet=acc.BillingStreet;
                    c.MailingCity=acc.BillingCity;
                    c.MailingState=acc.BillingState;              
                    c.MailingPostalCode=acc.BillingPostalCode;
                    c.MailingCountry=acc.BillingCountry;
                    c.Phone=acc.Phone;        
        ct.add(c);      
    }
   
    insert ct; 
}
}
}
Hi guys, I would asign the old value of "stock_actuel__c" to the new field when a record is created. I develop this trigger. The problem is that when I insert a record I have an exception nullpointer:
MyTigger:
trigger InvoiceStock on Tissus__c (after insert, after update, after delete) {
   for(Tissus__c tnew : Trigger.New)
       for(Tissus__c told : Trigger.Old){
           if(tnew.Name == told.Name)
               tnew.stock_actuel__c = told.stock_actuel__c ;
       }
}
the Exception:
Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger InvoiceStock caused an unexpected exception, contact your administrator: InvoiceStock: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.InvoiceStock: line 3, column 1
 
Challenge Question:
Assume a company needs a user whose job is to solely review existing accounts and report on them, but does not require the ability to edit the records. They should only see records from the Account object. Create the correct profile for this user.The profile must be named 'Account Reviewer'.
The 'Account Reviewer' profile should use the 'Salesforce' user license type.
Any user assigned to the 'Account Reviewer' profile should only have read access to the Account object (and no access to any other object in the Org).


I did every thing as tiralhead instructed but i am getting this error.

Challenge not yet complete... here's what's wrong:
The 'Account Reviewer' profile does not work as expected
Hi folks,
Found something interesting while researching regarding another posted bug:
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000BYt2

I've got a trigger and a test class for it. The trigger basically takes a related list of values and concatenates it, saving it as part of the Account object. My test cases all fail, showing the following error:
Class.TMCR_testAccountInterestList.test_addInterest: line 51, column 1
14:18:05.697 (6697124228)|FATAL_ERROR|System.AssertException: Assertion Failed: Expected: foo
Interest0
Interest1
Interest2
, Actual: foo
Interest0
Interest1
Interest2

The data looks identical. Just to be sure, I put the strings through a hex conversion to compare their hex values and they are indeed different.

My question is what gives? Why are they different? The data going in should be the same.

For reference, here are is the Trigger:
trigger Account_UpdateAccountInterestsList on Interest__c (after delete, after insert, after undelete, 
after update) {
	Interest__c[] interests;
    if (Trigger.isDelete) 
        interests = Trigger.old;
    else
        interests = Trigger.new;
	Set<ID> affected_accounts = new Set<ID>();
	Map<ID, Set<String>> account_interests = new Map<ID, Set<String>>();
	for(Interest__c interest: interests){
		affected_accounts.add(interest.Account__c);
		account_interests.put(interest.Account__c, new Set<String>());
	}

	List<Interest__c> all_interests = [
		SELECT Id, Account__c, Interest__r.Name
		FROM Interest__c
		WHERE Account__c IN :affected_accounts
		ORDER BY Interest__r.Name
	];
	List<Account> accounts_to_update = [
		SELECT Id, Account_Interests_List__c
		FROM Account
		WHERE Id IN :affected_accounts
	];
	
	for(Interest__c interest: all_interests){
		account_interests.get(interest.Account__c).add(interest.Interest__r.Name);
	}
	for(Account account: accounts_to_update){
		account.Account_Interests_List__c = Util_TMCR.combineList(account_interests.get(account.Id));
	}
	
	update accounts_to_update;
}
Here is the test class:
@isTest
private class TMCR_testAccountInterestList {
	static Account getAccount(){
		Util_TMCR_DataFactory.accounts account = new Util_TMCR_DataFactory.accounts();
		Account acc = [
			SELECT Id, Account_Interests_List__c
			FROM Account WHERE Name = :account.get('name')
		];
		return acc;
	}
	static Interests__c addInterest(String name){
		Interests__c new_interest = new Interests__c(Name = name);
		insert new_interest;
		return new_interest;
	}
	static Interest__c addToAccount(Account acc, Interests__c interest){
		Interest__c acc_interest = new Interest__c(Interest__c = interest.Id, Account__c = acc.Id);
		insert acc_interest;
		return acc_interest;
	}
	
	@testSetup
	static void setup(){
		List<Interests__c> interests = new List<Interests__c>();
		List<Interest__c> account_interests = new List<Interest__c>();
		for(Integer i=0; i<3;i++){
			interests.add(addInterest('Interest' + i));
		}
		Util_TMCR_DataFactory.accounts account = new Util_TMCR_DataFactory.accounts();
		Account acc = account.generate();
		for(Interests__c interest: interests){
			account_interests.add(addToAccount(acc, interest));
		}
	}
	
    static testMethod void test_addInterest() {
		test.startTest();
		Account account = getAccount();
		Interests__c interest = addInterest('foo');
		Interest__c acc_interest = addToAccount(account, interest);
		test.stopTest();
		
		String concat = Util_TMCR.combineList(new List<String>{'foo', 'Interest0', 'Interest1', 'Interest2'});
		Account acc = getAccount();
		System.assertEquals(concat, acc.Account_Interests_List__c);
    }
    static testMethod void test_changeInterest() {
    	test.startTest();
		Interests__c interest = addInterest('foo');
		Interest__c acc_interest = [SELECT Id, Interest__c from Interest__c WHERE Interest__r.Name = 'Interest0' LIMIT 1];
		acc_interest.Interest__c = interest.Id;
		update acc_interest;
    	test.stopTest();
    	List<String> mylist = new List<String>{'foo', 'Interest1', 'Interest2'};
    	String concat = Util_TMCR.combineList(mylist);
    	Account acc = getAccount();
    	System.assertEquals(concat, acc.Account_Interests_List__c);
    }
    static testMethod void test_deleteInterest(){
    	test.startTest();
		Interests__c interest = [SELECT Id, Name FROM Interests__c WHERE Name = 'Interest0' LIMIT 1];
		delete interest;
    	test.stopTest();
    	List<String> mylist = new List<String>{'Interest1', 'Interest2'};
    	String concat = Util_TMCR.combineList(mylist);
    	Account acc = getAccount();
    	System.assertEquals(concat, acc.Account_Interests_List__c);
    }
    static testMethod void test_undeleteInterest(){
    	test.startTest();
		Interests__c interest = [SELECT Id, Name FROM Interests__c WHERE Name = 'Interest0' LIMIT 1];
		delete interest;
		undelete interest;
    	test.stopTest();
    	List<String> mylist = new List<String>{'Interest0', 'Interest1', 'Interest2'};
    	String concat = Util_TMCR.combineList(mylist);
    	Account acc = getAccount();
    	System.assertEquals(concat, acc.Account_Interests_List__c);
    }
}
Finally, here is the function that concatenates both the expected list and the actual list:
public static String combineList(List<String> items){
        String out = '';
        String delimiter = '\n';
        for(String val : items){
        	out = out + val;
        	if(val.right(1) != delimiter){
        		out = out + delimiter;
        	}
        }
        return out;
    }





 

When someone takes the time/effort to repspond to your question, you should take the time/effort to either mark the question as "Solved", or post a Follow-Up with addtional information.  

 

That way people with a similar question can find the Solution without having to re-post the same question again and again. And the people who reply to your post know that the issue has been resolved and they can stop working on it.