+ Start a Discussion
Aarush SharmaAarush Sharma 
Create object : Candidate__c
Fields : (All Text fields)
First Name
Last Name
Email
Brokerage
Manage Brokerage
Candidate Status (Webinar - Attended , Webinar -Not Attended)
User Created ( checkbox)


On insert:
1. Create Account if Brokerage !=null
2. Create another account if Manage Brokerage != null and set parentId = Brokerage account id (created in 1 point)
3. Create new contact record and set accountId = Manage Brokerage account id (created in 2 point)
   create new field candidate__c(lookup) on contact and fill it with Condidate__c record id
4. Create task record for contact record (created in point 3)
Task.WhoId = contactId
Task.WhatId = Candidate__c
Task.Subject = 'Portal Contact Setup';
 
Best Answer chosen by Aarush Sharma
Akshay_DhimanAkshay_Dhiman
Hi Aarush,

Just Try this one out,
There is one line commented in Task creation of whatId, That should Non - commented only when the 
Candidate object is the child object of Account.
 
trigger TriggerCandidate on Candidate__c (after insert) {
    Map<Id ,Contact> ConListMap = new Map<Id ,Contact>();
    Map<Id ,Account> BroConList = new Map<Id ,Account>();
    Map<Id ,Account> mapBroConList = new Map<Id ,Account>();
    Map<Id ,Task> TaskConList = new Map<Id ,Task>();
    
    List<Account> ManageBroacclist = new List<Account>();
    
    for(Candidate__c con : trigger.New)
    {
        if(con.Brokerage__c!=Null && con.Manage_Brokerage__c!=Null)
        {
            Account Brokerageacc = new  Account();
            Brokerageacc.Name = 'Brokerage Acc';
            if(!BroConList.containsKey(con.Id))
            {
                BroConList.put(con.Id, Brokerageacc);
            }
        }
    }
    if(BroConList.values().size()>0)
    {
        insert BroConList.values();
    }
    for(Candidate__c cont : trigger.New)
    {
        if(cont.Brokerage__c!=Null && cont.Manage_Brokerage__c!=Null)
        {
            Account ManageBrokerageAcc = new Account();
            ManageBrokerageAcc.Name = 'Manage Brokerage Account';
             System.debug('BroconList.get(cont.id).Id---->>>>' + BroconList.get(cont.id).Id);
            if(BroconList.containsKey(cont.id)){
                System.debug('BroconList.get(cont.id).Id---->>>>' + BroconList.get(cont.id).Id);
                ManageBrokerageAcc.ParentId = BroconList.get(cont.id).Id;
            }
            
            if(!mapBroconList.containsKey(cont.id))
            {
                mapBroconList.put(cont.id, ManageBrokerageAcc);
            }
            
            contact contactnew = new contact();
            contactnew.LastName = 'Test cont';
            contactnew.Candidate__c = cont.Id;
            if(!conListMap.containsKey(cont.Id)) 
            {
                conListMap.put(cont.Id, contactnew);  
            }
        }
    }
    if(mapBroConList.values().size()>0)
    {
        insert mapBroConList.values();
    }
    if(ConListMap.values().size()>0)
    {
        insert ConListMap.values();
    }
    
    for(Candidate__c cont3 : trigger.New)
    {
        if(cont3.Brokerage__c!=Null && cont3.Manage_Brokerage__c!=Null)
        {
            Task tt = new Task();
            
            if(conListMap.containsKey(cont3.Id)) 
            {
                tt.WhoId = conListMap.get(cont3.Id).Id;
            }
            
           // tt.WhatId = cont3.Id;
            tt.Subject =  'Portal Contact Setup';
            
            if(!TaskConList.containsKey(cont3.id))
            {
                TaskConList.put(cont3.id , tt);
            }
        }
    }
    if(TaskConList.values().size()>0)
    {
        insert TaskConList.values();
    }
    
}


Thanks 
Akshay
Jean Velonis 21Jean Velonis 21 
I'm trying to limit the user when they use a botton to only be able to have one record if they don't have any other records in the status of "New". 


global with sharing class RetrieveNextUtils {
    webService static Id retrieveNextCase(String userId)
    {
        //Here I'm looking to see if the current user has any leads in Lead Status containing New
        
        
        //Really we're only specifying the user ID for the sake of the test methods
        if (userId=='') {
            //Use the currently running user
            userId = UserInfo.getUserId();
        }
        
        //First find out which queues this user is a member of
        List<Id> listGroupIds = getQueuesForUser(userId);
        
        if(listGroupIds.size()>0) 
        {
            //Find an open case that is assigned to one of those queues
            Case caseObj = [select c.Id,c.OwnerId from Case c where 
                                                        c.IsClosed=false 
                                                        and c.OwnerId in :listGroupIds 
                                                        limit 1 
                                                        for update];
                                                
            if (caseObj!=null) {        
                //If we found one, assign it to the current user
                caseObj.OwnerId = userId;
                update caseObj;
                
                return caseObj.Id;
            }
        }
        
        return null;
    }
    
    webService static Id retrieveNextLead(String userId)
    {
        //Really we're only specifying the user ID for the sake of the test methods
        if (userId=='') {
            //Use the currently running user
            userId = UserInfo.getUserId();
        }
        
        //First find out which queues this user is a member of
        List<Id> listGroupIds = getQueuesForUser(userId);
        
        if(listGroupIds.size()>0) 
        {
        
            
            //Find an open lead that is assigned to one of those queues
            List<Lead> leads = [select l.Id,l.OwnerId from Lead l where 
                                                        l.IsConverted=false 
                                                        and l.OwnerId in :listGroupIds 
                                                        limit 1 
                                                        for update];
                                                
            if (leads.size()>0) {       
                //If we found one, assign it to the current user
                leads[0].OwnerId = userId;
                update leads;
                
                return leads[0].Id;
            }
        }
        
        return null;
    }
    
    //Returns a list of ids of queues that this user is a member of
    public static List<Id> getQueuesForUser(String userId) 
    {
        List<Id> listGroupIds = new List<Id>();
        List<GroupMember> listGroupMembers = [Select g.GroupId From GroupMember g 
                                                where g.Group.Type='Queue'
                                                and g.UserOrGroupId=:userId];
                                                
        if (listGroupMembers!=null && listGroupMembers.size()>0) {      
            for (GroupMember gm:listGroupMembers) {
                listGroupIds.add(gm.GroupId);
            }
        }
        
        return listGroupIds;
    }
    
    
        
   
}
Best Answer chosen by Jean Velonis 21
Daniel BallingerDaniel Ballinger

Try something like the following:

webService static Id retrieveNextLead(String userId) {
    //Really we're only specifying the user ID for the sake of the test methods
    if (userId=='') {
        //Use the currently running user
        userId = UserInfo.getUserId();
    }
        
    List<Lead> existingUserNewLeads = [Select Id, Name, Status, IsConverted 
                                       From Lead 
                                       where 
                                           OwnerID = :userId 
                                           and IsConverted = false 
                                           and Status = 'New'];
    if(!existingUserNewLeads.isEmpty()) {
        // This user already has a Lead with Status New assigned to them
        // Don't let them be greedy and get another lead until they are finished with their current one.
        // No more leads for you!
        return null;
    }

    //First find out which queues this user is a member of
    List<Id> listGroupIds = getQueuesForUser(userId);
    // ... Existing method code
    return null;
}
Nadia GainsbourgNadia Gainsbourg 
Hello! How can I write a trigger to make it so accounts that have specific record types cannot be deleted? 
Thank you! 
Best Answer chosen by Nadia Gainsbourg
Steven NsubugaSteven Nsubuga
You would have to add extra statements to retrieve the additional record types, as well as an or (||) in the if statement.
See example below which checks for 3 record types. 
trigger preventAccountDeletion on Account (before delete) {

	Id recTypeId1 = Schema.SObjectType.Account.getRecordTypeInfosByName().get('RecordTypeNameA').getRecordTypeId();
	Id recTypeId2 = Schema.SObjectType.Account.getRecordTypeInfosByName().get('RecordTypeNameB').getRecordTypeId();
	Id recTypeId3 = Schema.SObjectType.Account.getRecordTypeInfosByName().get('RecordTypeNameC').getRecordTypeId();
	
    for(Account acct : trigger.old){
		if (acct.recordTypeId == recTypeId1 || acct.recordTypeId == recTypeId2 || acct.recordTypeId == recTypeId3){
			acct.addError('This Account Cannot be deleted');
		}
    }
}


 
Srini D 14Srini D 14 
I wanted to pass data from visualforce page to apex class based on user clicks ?
Best Answer chosen by Srini D 14
Lakshmi Deepak InkurthiLakshmi Deepak Inkurthi
Using Apex Cookies you can able to get this done 
reference : https://developer.salesforce.com/forums/ForumsMain?id=9060G0000005f0DQAQ
site : https:lakshmideepak.com
SFDC 18SFDC 18 
Hi, 
I need to update a field called No of Agents with the count of agents in that zone (North, South, East, West). The zone field is on agent object and no of agents is on zone object. I have written the below logic.

I'm stuck with the if clause part. Can anyone help me with this?

Name is a field on zone object with picklist values of zone

On No of Agents field,
public class NoofAgents {
    List<Zone> zonestoupdate = [SELECT Id,Zones__C FROM Agent__C];  
    for(Zone z:zonestoupdate)       
    {       
        Integer NoofAgents = [SELECT count() FROM Agent__C WHERE Zones__C == North];
        if (Name__c == North)
        {
            
        }
    }        
}

it should show the count of agents in that zone

 
Best Answer chosen by SFDC 18
Bala Gangadhar VadlamuriBala Gangadhar Vadlamuri
Sai,
 
public class NoofAgents {
    
    public NoofAgents(){
  		
       
        for(zone__c z : [SELECT Id,Name,NoofAgents__c FROM Zone__C]){
           
            z.NoofAgents__c = [SELECT count() FROM Agent__C WHERE Zone__C =: z.Name];
            upsert z;
        	}
      
            
        }
                         
 
}



This Code will update for all the zones.

Choose this as best answer if you like.

Regards,
Bala
SFDC Coder 8SFDC Coder 8 
Hi All,
I have one custom object. When ever I created a record in this object, I want to send it to a queue for approval.
When it is approved by that queue user, I want to send it to another queue and want to get it approve.

How can I do this?
Please help me

Thanks in Advance.
Best Answer chosen by SFDC Coder 8
{!Piyush_soni__c}{!Piyush_soni__c}
hi SFDC coder
you got your solution by below link
http://www.infallibletechie.com/2013/01/multiple-approvers-for-approval-process.html
let me inform if it helps you
Thanks
 
Shiva RajendranShiva Rajendran 
The salesforce if it involves too much coding ,then i noticed lot of complexities in the code whenever the salesforce updates some of its featues, i would like to know why would someone go for hardcore customization in salesforce instead of choosing  java and heroku? In this case ,their are quite a lot of advantages like
1: no limits as in salesforce
2: licenses are cheap so if the user count is high , it will profitable in the long run
3: No need to have dependency on the existing functionality which may mess with the functionality required.( i have personally been through this, where an existing functionality completely complicated the custom development required)
4: And also need not concern the code breaking because of any standard functionality changes in salesforce ( i have been through this when creating the dynamic thread id in salesforce ,it crashes at some time and no guarante will it work later)

Do share your thoughts to it.

Thanks and Regards,
Shiva RV
Best Answer chosen by Shiva Rajendran
Paul Fayle 9Paul Fayle 9
My thoughts are - different horses for different courses.
  • Force.com using the base level licences (e.g. Employee Apps Starter for internal, and maybe Customer Community for external) is what I call a Platform as a Service + (PaaS+). Note the +. As opposed to Service Cloud (a SaaS). With basic Force.com you get limited use of an object model, and most importantly a whole bunch of declarative frameworks to accelerate an application build (most importantly the whole access control model - a major advanatage of the platform, and very complex if you has to build it yourself). But if you aren't making use of an authenticated paradigm, and you don't need to really leverage the Salesforce data model it makes less sense... if it is mainly a website for the general public - high traffic and low contextual data interaction then maybe not...
  • Heroku is a PaaS - giving you the tools to quickly develop your own applications or sites. Key word "develop". Sure - there are some accelerators here, but not like Force.com - and not declarative in nature. It can work brilliantly for a public/end-consumer overlay to a Force.com framework (internal app and community) - e.g. in a eCommerce paradigm for instance.
  • The assumption that Heroku is a cheaper option than Force.com is not necessarily valid (you need to assess Total Cost of Ownership - and this should take into account development costs, upgrade and maintenance considerations, etc.). It really depends on whether tha value you get from Force.com is enough to offset the cost differential in licences (because arguably the build effort would normally be more in Heroku - depending on what you are delivering).
  • In terms of code breaking - typically if you follow best practices this should never be the case (I have never seen upgrades break build in Force.com except in one instance where there were multiple triggers on a single object and they were processed in a different order post upgrade... you shouldn't have multiple triggers on a single object - so that was the real issue).
iyappan kandasamy 4iyappan kandasamy 4 
Actually this is my apex class for addition of 2 numbers 
public class Addition         //define class
{
  public integer a=5;        //define variables
  public integer b=4;
  public integer c;

  public integer add()               //define function or method
  {
  c=a+b;
  system.debug('the result is '+c);
        return c;
  }
}// end of class


My Test class
----------------
@isTest
public class Additiontest
{
    static testmethod void testadd()
    {
     integer a=5;
     integer b=7;
     integer c=12;
     system.assertEquals(12,12); 
    }  
    
}

and when executing the test class it is showing as pass...

Please need help on this....thanks
Best Answer chosen by iyappan kandasamy 4
SFDC Dev 2269SFDC Dev 2269
Hey @iyappan kandasamy 4,
Test class is used to test your functionality(class you have writter), and in order to test your functionality you need to invoke the Addition class and its methods.
In your test class you have just added the two integers. you need to invoke your class as below in your test class
 
@isTest
public class Additiontest
{
	static testmethod void testadd()
    {
		Addition addObj = new Addition();
		Integer result = addObj.add();
		System.assertEquals(9,result); // As value of a and b in Addition class are 5,4 the expected value is 9
    }  
    
}

Refer: https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
 
VarunCVarunC 

Every time I try to run this query i get only 2 results:

 

Attachments[] records = [Select Name, ParentId, OwnerId, Id, Body, ContentType, Description, IsPrivate From Attachment Where Parent.Type IN ('File__c') AND Owner.IsActive = true];

 

I know including "Body" field will limit number of records returned in Eclipse to only 1, BUT I'm using this query in APEX class and in Debug Log as well but I'm only able to read 2 record everytime, but the total count of Attachment record returned from this query Should be 4152 records which it is not giving.

 

Is it some Bug?

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

You'll need to use the query loop syntax, 

 

for (Attachment [] atts : [select name, body from attachment]) {
// do something with atts
system.debug ( atts.size() );
}

Sandra WicketSandra Wicket 
Hi Guys,

this is my code :
public class CreateMultiExtraBoost {

	public List<cBoost> boostList {get; set;}
    Integer listSize {get;set;}
    public Id opportunityId {get;set;}
    public ID finalBoostId {get; set;}
        
    // Constructor 
    public CreateMultiExtraBoost (){
    	opportunityId =  ApexPages.currentPage().getparameters().get('oppId');
    }

	//Methode
	public List<cBoost> getBoosts() {
		if(boostList == null) {
			boostList = new List<cBoost>();
			for(FinalBoost__c c: [select Id, Name from FinalBoost__c ]) {
				boostList.add(new cBoost(c));
			}
		}
		return boostList;
	}

	public PageReference save() {
 
		List<FinalBoost__c> selectedContacts = new List <FinalBoost__c>();
        List<BoostOpp__c> boostItems = new List <BoostOpp__c>(); 
        pagereference oppPage = new pagereference('/' + opportunityId);

		for(cBoost cCon: getBoosts ()) {
			if(cCon.selected == true ) {
				selectedContacts.add(cCon.con);
			}
		}

		System.debug('These are the selected ...');
		for(FinalBoost__c con: selectedContacts) {
			system.debug(con);
		}
        
        for (FinalBoost__c con: selectedContacts) {
            	boostItems.add(new BoostOpp__c());
            	finalBoostId = con.Id;
            
            		for(BoostOpp__c boostIteminList : boostItems) {
                        boostIteminList.Opportunity__c = opportunityId;
                        boostIteminList.FinalBoost__c = finalBoostId;
       	 }
       }
        insert boostItems;
        return oppPage;
	}
    
   
   // WrapperClass
	public class cBoost {
		public FinalBoost__c con {get; set;}
		public Boolean selected {get; set;}

		// Constructor 
        public cBoost(FinalBoost__c c) {
			con = c;
			selected = false;
		}
	}
}

A visualforcepage shows the table of FinalBoost records. I can select records and use them in the save methode.  The BoostOpp__c object is a junction object. It is related to the opportunity and the FinalBoost Object. 

In my loop, i want to create for each selected record one child record and assign the parent id (FinalBoost) to the masterDetail field. At the moment, it creates for each selection one record but allways with the same finalBoostId.  Is there a simple solution for that ? 


Cheers Sandra
Best Answer chosen by Sandra Wicket
<Saket><Saket>
Hi Sandra,

Please find the solution below.
 
public PageReference save() {

List<FinalBoost__c> selectedContacts = new List <FinalBoost__c>();
List<BoostOpp__c> boostItems = new List <BoostOpp__c>(); 
pagereference oppPage = new pagereference('/' + opportunityId);

for(cBoost cCon: getBoosts ()) {
	if(cCon.selected == true ) {
		selectedContacts.add(cCon.con);
    }
}

for (FinalBoost__c con: selectedContacts) {
	
	BoostOpp__c boost = new BoostOpp__c();
    boost.FinalBoost__c = con.Id;
	boost.Opportunity__c = opportunityId;
	boostItems.add(boost);

	
}
insert boostItems;
return oppPage;
}