• Deepak Maheshwari 7
  • SMARTIE
  • 889 Points
  • Member since 2017

  • Chatter
    Feed
  • 28
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 220
    Replies
Senario: when a value is inserted on AMOUNT custom field, COUNTER custom filed should be automatically get incresed.  i'm new to salesforce and please guide me.

Object :  Account
Custom fields : amount,counter
 Thanks in advance
Hello I am Guru , a Freasher..I want to restrict creation of order from quote if a quote name is already present in order ....I mean to avoid multiple order for same quote..Please help me out
These is my code .Please Help me.

trigger RestrictMultipleOrder on Order (before insert)
{
   List<Order> ord=[Select  Quote__c from Order];
    For(Order o:Trigger.New)
    {
          if(o.Quote__c==ord)
        {
           o.addError('Duplicate Order cannot be generated');
        }
    }
}
Hello,

I have trigger that will update a custom field Segment__c on the account based on the owner Role Description. I'm getting this error when I change the owner of the account to someone in the Operations department:
Error: Apex trigger SegmentRulesTrigger caused an unexpected exception, contact your administrator: SegmentRulesTrigger: execution of AfterUpdate

caused by: System.ListException: Duplicate id in list:

Here is the part of the trigger that is not working:
trigger SegmentRulesTrigger on Account (after insert, after update) {
    
    //Create a list of accounts to update 
    List<Account> acctsListToUpdate = new List<Account>(); 
   
   
	//check if trigger is running again
    if(RecursiveTriggerHandler.runOnce()){
    
        for (Account a : Trigger.new) {
         //Query the owner role description
			for(User u : [SELECT id, Role_Description__c FROM User WHERE id = :a.OwnerId]){
				// Check if the account ID is not null 
				// to avoid "referencing null object" error       
				if(a != NULL  && a.ID !=NULL){
				// create a placeholder account a1    
				Account a1  = new Account(Id = a.Id, Name = a.Name, OwnerId = a.OwnerId);
				
					//Map Account ID
					Account oldAcct = Trigger.oldMap.get(a1.Id);
									//Check if Account Owner or Name has changed
								   if (oldAcct.OwnerId != a1.OwnerId || oldAcct.Name != a1.Name){
									//  User u1 = new User(Id= u.Id, Role_Description__c = u.Role_Description__c);
										//Check if Owner role description is Operations
									   if( u.Role_Description__c == 'Operations' )
											 {
											  a1.Segment__c = 'Other';
											  acctsListToUpdate.add(a1); 
										}
											 a1.Segment__c = u.Role_Description__c;
											 acctsListToUpdate.add(a1); 
									 } 
								
				} 
                //Bulkify the update    
                if(acctsListToUpdate.size()>0){
                    update acctsListToUpdate;            
                } 
			}				
		}	
	}
}

Thank you for your help.​
Create a trigger on case that if owner is external community user(profile = customer community user)then the check box "assign using Active assignment rules" should be active.

Thanks
KMK
  • May 03, 2017
  • Like
  • 0
I am trying to query OpportunityContactRole for contacts and poulating the results in a mapwith ContactId as key and OpportunityId as value. I keep on geeting compilation error Incompatible key type Object for Map<Id,Id> in the line where I am polulating mpCtIdOppId. Kindly suggest.
 
Map<Id,Id> mpCtIdOppId = new Map<Id,Id>();
        Map<Id,List<OpportunityContactRole>> mpCtIdOppCtRl = new Map<Id,List<OpportunityContactRole>>();
        List<OpportunityContactRole> lstOppCtRole = [Select OpportunityId, ContactId from OpportunityContactRole where ContactId in: scope];
        System.debug('lstOppCtRole >>>' + lstOppCtRole);
        
        for(OpportunityContactRole oppctrl1: lstOppCtRole){
            System.debug('oppctrl1 contactid >>>' + oppctrl1.get('ContactId'));
            mpCtIdOppId.put(oppctrl1.get('ContactId'), oppctrl1.get('OpportunityId'));
        }

 
Dear All,
I have the below fields on Quote object ( parent) , Named Driver ( Child object). I have set up certain fields ( through formula and apex) which will take the minimum age driver from the list of driver records.
The extreme below field , takes the min driver number ID, and the first one is the hyperlink formula on that.
The first one is set as the formula,
HYPERLINK( Youngest_DriverT__c , Name_of_Driver__c )

User-added image

Now i want that, which ever record number being set here, The account name * 2nd field) and the birthday from the NamedDriver will show here. I tried to create a PB , but its not working. Can you plz suggest how to goahead, thanks

Below is my PB i tried,

Criteria :
User-added image

Action :
User-added image

 
Hello,

I want to make the "First name" of "Contact" mandatory for certain profiles.

How can i acheive it ?

thanks for suggestion ! 
  • April 26, 2017
  • Like
  • 0

Hi Guys,

I want to display only those contacts that are related to the selected account. I have 2 custome lookup field on opportunity object, one is the referrer account and another one is referrer contact. When we select the lookup account and save it then need to display only related contacts. I have created a lookup filter but its not display contacts by default when click on the contact lookup, see the lookup filter as below

 

 

 

 

 

User-added image

Please help on it

Thanks


 

Hi all,
Could someone help me to create a validation rule, if a user tick the check box on custom object should remain ticked.
My scenario, On Opportunity, I have a custom check box object. when user ticks that check box, system user is unticking the checkbox. could someone help me on how to solve the issue
Hi All,

I have three objects obj1, obj2, obj3 where obj2 is junction object for obj1 and obj2.

now my requirement is i have to retrive obj1 name from obj3 through query.

Please help me with sample query for the same. Thansk


Best Regards,
Mohammad Yaseen
 
Hello,

In my process builder, i want to execute a action on create and other on update but the problem is the entry criteria for processbuilder 
"when a record is created or edited"
contradicts to
"only when a record is created"
How can i check in my decision, to by pass if it is create ?

thanks for sugestion !
  • April 24, 2017
  • Like
  • 0
one more thing , if i have a stock object in one custom object and if stock is 0 then available checkbox should become false otherwise it should be true... How it can be done , whether by validation rules or workflow rules???
I want to trigger a WF if a lookup contact field is blank in a record. There are a few other conditions as well. THe start transaction (date field), buyer selling agent and listing agent (both lookup contact fields) must not be blank and it has to be broker represenation Seller or Double sided which are picklist values both, I get an Extra , error when checking the syntax 

AND( 
NOT(ISBLANK(Start_Transaction__c)), 
NOT(ISBLANK(Buyer_Selling_Agent__c)), 
NOT(ISBLANK(Listing_Agent__c )), 
ISBLANK(Title_Contact__c)),

OR(

ISPICKVAL( rethink3__Broker_Representation__c, "SELLER"),

ISPICKVAL( rethink3__Broker_Representation__c,  "Double sided"))
 The logic is when we create Customer Project(Custom obj) for an Opportunity(Standard obj) with the Status=Active(Picklist value), then Active Customer project check box on the Opportunity detail page is automatically checked.
wherein there is lookup between Customer Project and Opportunity..!
 
how to write avlidation rule for these ..please help

if book price is greater than 500 then Author name and his date of birth is mandatory
Hi Experts,
What will be the test class for following trigger?

trigger UpdateSADeclined on Task (before insert,before update) {

for(Task x: Trigger.new)

If (x.Declined_by__c!=null || x.Date_Time_Declined__c!=null || x.Declined_Reason__c!=null)
 { 
  
  x.SA_Declined__c=true;

else
 { x.SA_Declined__c=false;
 
 }
 }
 }


Please help.
Hi All,

In my org I have three object obj1, obj2, obj3 and obj2 is junction object between obj1 and obj3. My requirement is i want a rollup summary field on obj1 which will calculate the minimim value of related obj3 field. 

Please help me how shalll i proceed in this case. Thanks

BEst Regards,
Mohammad Yaseen
Dear All,
In my Quote object, i have a related list called " Named Driver" , as per below,
I want to create a field in Quote, which will show me the youngest driver i.e in this case 21. If less one say 18 added later, it will change to 18.  Can you plz suggest how to create such field, It would be a look up or text ( if text should be a hyperlink) to go inside the record.
Or if apex trigger needed, any sample code writing suggestions.
Thnx

User-added image
Hi,

I am trying o do a record count on a specific criteria which i have working. However the issue I have is I dont know how to write a test class for it. Ive mainly worked with lists up until now which i can write a test class for. I have attached the apex class below would someone be able to give me some direction on what i need to put in the test class.
 
public class UnitCount {

    public Integer getC2630Counter(){
    	return [SELECT count()
                FROM Unit_Value__c
                WHERE Unit_Type__c =: 'LMU-2630' AND Stock_Status__c =: 'OFFICE' AND Account__c = '0010E00000DHfef' AND Status__c =: 'New Stock'
                ];
	}
}

 
Field                API Name          Datatype
Contact           Contact__c         LookUp        //field from Opportunity
Awesome        Awesome__C    CheckBox    //field from Contact
global class BatchAwesomeContact implements Database.Batchable<sObject>{
    Map<Id, Contact> conts = new Map<Id, Contact>();
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String Query = 'SELECT Id, Contact__c, Amount, (SELECT Id, FirstName, LastName, Awesome__c FROM Contact) FROM Opportunity WHERE Id IN :conts.keySet()';
        return Database.getQueryLocator(Query);
    }
    
    global void execute(Database.BatchableContext BC, List<Opportunity> scope) {
        for (Opportunity s : scope) {
            if (s.Contact__c != null) {
                if (s.Amount >= 500 && !conts.containsKey(s.Contact__c)) {
                    conts.put(s.Contact__c, new Contact(Id = s.Contact__c, Awesome__c = true));
                }
            }
        }
        update conts.values();
    }
    
    global void finish(Database.BatchableContext BC) {
        
    }
}
We have two large picklist fields - Hospital Sector and Main skill pick list (MSPL)   MSPL is much larger.  I'm trying to have our searching easier, so...say we have Financials which encompasses like 15 MSPL items.  I'm trying to get it set ukp to where each module correlates with a module.  so we would only have to look up "Financials" and not all of the items.  

It would have to be a "Contains" field.  Like, IF MSPL Contains PharmNet, Hospital Sector shows Pharmacy,  There is a ton of these.  Probably 300+ in MSPL and 30+ in the Hospital Sector. And each MSPL can be with more than one sector. (but that is in rare cases, and i could change if necessary.    I've got it all drawn out....just don't know where to go next.  I'm worried the coding for this is going to be nuts.

Any suggestions?
Hi,

How can i create a new oppournity automatically when lead status is active ?
how can i acheive it ?
 
Hi,
How can i create web to oppournity creation from my website contact form ?

 
Apex trigger is -->

trigger UpdateEmail on Account (after insert, after update) {
 
    set<Id> acctIds = new set<Id>();
    map<Id, Account> mapAccount = new map<Id, Account>();
    List<Contact> conList = new List<Contact>();
  
   
    for(Account acct : trigger.new) {
        acctIds.add(acct.Id);
        mapAccount.put(acct.Id, acct);
    }
   
    conList = [SELECT Email, AccountId FROM Contact WHERE AccountId IN : acctIds];
    Try{
    if(conList.size()!=null) {
        for(Contact con : conList) {
            con.Email = mapAccount.get(con.AccountId).Email__c;
           }
        update conList;
    }
}
    Catch(DMLException e){
       
    }
}

Test class is -->


@istest
public class testtriggeremail
    {
        static TestMethod void testtriggermail()
            {
                 Account acc = [select Name, Email__c from Account where Name='Demo1' ];
                 acc.Email__c='sharma1@deloitte.com';
                 Test.StartTest();
                 update acc;
                 Test.StopTest();
                
                 List<Contact> con = [select Email from Contact where Account.Name='Demo1'];
                
                 for(Contact c :con)
                     {
                         system.assertequals('sharma@deloitte.com',c.Email);
                     }
                       
            }
    }
Hi Guys,

I need to send Email alert for today created contacts list . 
Contact records are inserted through automation. Manager expecting in single mail to fetch list of contact records creted by today .
Can you please guide me , how to i achive this ? 


Ex:Email template 

HI Manger,
Today Contact records listed below .

ID   name         mail                        phone    createddate
001  sasi         sasi@gmail.com       123         today
002   sachin     sacina@gmai.com    234         today
003  sehwag     sehwag@gmail.com  345        today

Thanks& Regards,
Sasidhar



















  
 
trigger ClosedOpportunityTrigge on Opportunity (after update, after insert) {

		list<task> tasklist = new list<task>();
    	list<opportunity> opplist = new list<opportunity>();
    
    	opplist = [select id,stagename from opportunity where stagename = 'Closed Won' and id in :trigger.newmap.keyset()];

    		for (opportunity opp : opplist){
            	if(opp.stagename == 'Closed Won'){
						task addtask = new task();
            			addtask.subject = 'Follow Up Test Task';
						addtask.WhatId = opp.Id;
						tasklist.add(addtask);
				}
		}
		update tasklist;
}


Hi,

The challenge is 

To complete this challenge, you need to add a trigger for Opportunity. The trigger will add a task to any opportunity inserted or updated with the stage of 'Closed Won'. The task's subject must be 'Follow Up Test Task'.

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

 

I feel the logic is right, but it is showing me error as : 

Challenge Not yet complete... here's what's wrong:
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Account name is required: []

 

Is there something i am doing wrong, please point out if i made any mistakes.

also. i have just started with salesforce and apex 2 weeks ago, if i am missing anythin please give explaination, it would help me alot in understanding.

 

Thanks,

Nitin 

Hi All,

I want to add 5 days to today's date.
Example : Suppose i have a date field Collection_date__c which is having a date of 24th may 2017 and I am quering it today(19th May 2017). It should display this 24th Mau record.

Select Id, Collection_date__c from Custom_Object__c where Collection_date__c = today + 5;

Please Help

Thanks 
RD
  • May 19, 2017
  • Like
  • 0
I have parent object plan__c when i update name field in plan__c, trigger it will update child object process__c fields ,the tigger is below ,it's not working properly.....,
trigger trgr_plan on plan__c (after insert) {

{
    List<process__c> prcList = new List<process__c>();

    for(plan__c pcc:Trigger.newMap.Values())
    {
    process__c prc=new process__c ();
      prc.name=pcc.name;
      prc.processnewname__c=pcc.name;
        prcList .add(prc);
    }
   if(prcList .size()>0)
    {
        insert prcList ;
    }
}
}
Senario: when a value is inserted on AMOUNT custom field, COUNTER custom filed should be automatically get incresed.  i'm new to salesforce and please guide me.

Object :  Account
Custom fields : amount,counter
 Thanks in advance
1.Implement trigger in store__c custom object , trigger will only execute when Default Address is true
  1. Create 2 fields in  Place__c  custom object, City and Country.
  2. Fetch Stock__c custom object City and country with help of Store__c id, Stock__c and Store__c Relation ship (One to Many)
  3. Update Palce__c address field City and Country
Hello I am Guru , a Freasher..I want to restrict creation of order from quote if a quote name is already present in order ....I mean to avoid multiple order for same quote..Please help me out
These is my code .Please Help me.

trigger RestrictMultipleOrder on Order (before insert)
{
   List<Order> ord=[Select  Quote__c from Order];
    For(Order o:Trigger.New)
    {
          if(o.Quote__c==ord)
        {
           o.addError('Duplicate Order cannot be generated');
        }
    }
}