• srish
  • NEWBIE
  • 0 Points
  • Member since 2013
  • wipro

  • Chatter
    Feed
  • 0
    Best Answers
  • 4
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
It is a salesforce standard functionality that when two objects are in a Master-detail relatonship with each other then if the Master record is deleted, all the related child records get delted automatically. However, what if we have a vice-versa situation? i.e. when a child record is deleted then the Master record without any child should also get deleted. This can be achieved by a trigger!! :)

Below is the code for the same. (Note: this code does not work for deleting records in bulk. Will be soon posting that as well. Also we need to have a unique key on both the objects)

if(Trigger.isAfter){
            if(Trigger.isDelete){
 
                List<ChildObjName__c> IdSetC = new List<ChildObjName__c>(); 
                List<MasterObjName__c  IdSetM = new List<MasterObjName__c>();
                Set<Id> IdSet = new Set<Id>();
               
                for(ChildObjName__c Cobj : Trigger.Old){
                     IdSet.add(Cobj.RelationshipName__c);
                     }
                List<MasterObjName__c> MobjLst = new List<MasterObjName__c>( [select id from MasterObjName__c where id =:IdSet]);
   
                    IdSetM=[select KeyField__c from MasterObjName__c where id=:IdSet];
                    IdSetC = [select id  from ChildObjName__c where KeyField__c =:IdSetM[0].KeyField__c];
   
                    if (IdSetC.size()==0)
                        {
                            delete MobjLst;
                        }
                    }
                } 

Solution by Abinash Sahoo and Srishti Goyal
  • October 22, 2014
  • Like
  • 1

My objective is to create a custom search page where I can search on the fields input through a multi-select picklist. This picklist consists the list of the fields in which the search is to be done.

 

To acieve the above motive the code provided needs to be modified such that the search is done on the values returned by the method name getSelectedValues(). Also the values assigned to the variable originalvalues should be the required fields(Name, Industry, Rating, Account_Region__c, Account_Priority__c, Account_Summary__c) of the object Account.

 

Please find the code attached and suggest the necessary modifications.

 

//vf code
<apex:page Controller="AccountSearch"> <apex:form > <apex:pageBlock mode="edit" id="block"> <apex:pageBlockSection ></apex:pageBlockSection> &nbsp;&nbsp;&nbsp;<label for="checkbox"> Limit to Account I own: </label> <input id="checkbox" type="checkbox"/> <apex:pageBlockSection > <apex:pageBlockSectionItem > <apex:outputLabel for="searchText">Search Text</apex:outputLabel> <apex:panelGroup > <apex:inputText id="searchText" value="{!searchText}"/> </apex:panelGroup> </apex:pageBlockSectionItem> </apex:pageBlockSection> <apex:actionStatus id="status" startText="requesting..."/> <apex:pageBlockSection > <apex:panelGroup > <apex:panelGrid columns="3" id="abcd"> <apex:selectList id="sel1" value="{!leftselected}" multiselect="true" style="width:150px" size="7"> <apex:selectOptions value="{!unselectedvalues}" /> </apex:selectList> <apex:panelGroup > <br/> <apex:CommandButton value=" > " action="{!selectclick}"/> <br/> <apex:CommandButton value=" < " action="{!unselectclick}"/> </apex:panelGroup> <apex:selectList id="sel2" value="{!rightselected}" multiselect="true" style="width:150px" size="7"> <apex:selectOptions value="{!SelectedValues}" /> </apex:selectList> </apex:panelGrid> </apex:panelGroup> </apex:pageBlockSection> <apex:pageBlockSection > <apex:commandButton value="Submit" action="{!search}" rerender="block"/> </apex:pageBlockSection> <apex:pageBlockSection title="Results" id="results" columns="1"> <apex:pageBlockTable value="{!results}" var="a"> <apex:column value="{!a.Name}"/> <apex:column value="{!a.Industry}"/> <apex:column value="{!a.Rating}"/> <apex:column value="{!a.Account_Region__c}"/> <apex:column value="{!a.Account_Priority__c}"/> <apex:column value="{!a.Account_Summary__c}"/> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page> ---------------------------------------------------------------- //controller class
public class AccountSearch { String searchText; List<Account> results; //assign the values i.e. fields to originalvalues Set<String> originalvalues = new Set<String> {'Name', 'Industry', 'Rating', 'Account Region', 'Account Priority', 'Account Summary'}; Public List<string> leftselected{get;set;} Public List<string> rightselected{get;set;} Set<string> leftvalues = new Set<string>(); Set<string> rightvalues = new Set<string>(); public String getSearchText() { return searchText; } public void setSearchText(String s) { searchText = s; } public List<Account> getResults() { return results; } public PageReference search() { results = (List<Account>)[FIND :searchText RETURNING Account(Name, Industry, Rating, Account_Region__c, Account_Priority__c, Account_Summary__c)][0]; return null; } public AccountSearch() { leftselected = new List<String>(); rightselected = new List<String>(); leftvalues.addAll(originalValues); } public PageReference selectclick() { rightselected.clear(); for(String s : leftselected) { leftvalues.remove(s); rightvalues.add(s); } return null; } public PageReference unselectclick() { leftselected.clear(); for(String s : rightselected) { rightvalues.remove(s); leftvalues.add(s); } return null; } //unselected values remain in the left box public List<SelectOption> getunSelectedValues() { List<SelectOption> options = new List<SelectOption>(); List<string> tempList = new List<String>(); tempList.addAll(leftvalues); tempList.sort(); for(string s : tempList) options.add(new SelectOption(s,s)); return options; } //selected values that get displayed in the right box are returned public List<SelectOption> getSelectedValues() { List<SelectOption> options1 = new List<SelectOption>(); List<string> tempList = new List<String>(); tempList.addAll(rightvalues); tempList.sort(); for(String s : tempList) options1.add(new SelectOption(s,s)); return options1; } }
  • May 28, 2013
  • Like
  • 0

Kindly provide a solution to the following : 

 

Details

I as a product manager require a custom search page for my salesforce CRM account. I don’t want to use the standard search functionality for this. Here is what I want to be done:

 

    1. On the VF page, create accustom “search” button and a checkbox with the name “limit to accounts I own”
    2. I should be able to enter and search on the following fields (these are the search criteria fields):
      1. Account name(standard field)
      2. Industry (standard field)
      3. Rating(standard field)
      4. Account  region(custom field)
      5. Account priority(custom filed)
      6. Account summary(text)
    3. The search functionality should be a logical OR of all the above combinations.
    4. The correct search results should be displayed ON THE SAME PAGE only after clicking the “submit” button.Display columns should have these fields: account name, industry, rating, account priority.
    5. If the checkbox “limit to accounts I Own” is checked before clicking on search the display only those accounts where the owner=current logged in user. 

I have developed the following code:

 

<apex:page Controller="AccountSearch">
<apex:form >
 
<apex:outputPanel layout="block">
<label for="checkbox"> Limit to Account I own: </label>
<input id="checkbox" type="checkbox"/>
</apex:outputPanel>
<apex:commandButton action="{!search}" value="Search"/>
 
<apex:pageBlock mode="edit" id="block">
         <apex:pageBlockSection >
            <apex:pageBlockSectionItem >
               <apex:outputLabel for="searchText">Search Text</apex:outputLabel>
               <apex:panelGroup >
                  <apex:inputText id="searchText" value="{!searchText}"/>
                  <apex:commandButton value="Submit" action="{!search}" 
                                      rerender="block"/>
               </apex:panelGroup>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
 <apex:actionStatus id="status" startText="requesting..."/>
<apex:pageBlockSection title="Results" id="results" columns="1">
           <apex:pageBlockTable value="{!results}" var="a"
                               rendered="{!NOT(ISNULL(results))}">
                               
              <apex:column value="{!a.Name}"/>
              <apex:column value="{!a.Industry}"/>
              <apex:column value="{!a.Rating}"/>
              <apex:column value="{!a.Account_Region__c}"/>
              <apex:column value="{!a.Account_Priority__c}"/>
              <apex:column value="{!a.Account_Summary__c}"/>
   </apex:pageBlockTable>
   </apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
__________________________________________________________________________________________
 
public class AccountSearch {
 
  String searchText;
   List<Account> results;
 
public String getSearchText() {
      return searchText;
   }
 
   public void setSearchText(String s) {
      searchText = s;
   }
 
   public List<Account> getResults() {
      return results;
   }
    public PageReference search() {
    results = (List<Account>)[FIND :searchText RETURNING Account(Name, Industry, Rating, Account_Region__c, Account_Priority__c, Account_Summary__c)][0];  
        return null;
    }
 
}
Please provide the necessary modifications
  • May 27, 2013
  • Like
  • 3
It is a salesforce standard functionality that when two objects are in a Master-detail relatonship with each other then if the Master record is deleted, all the related child records get delted automatically. However, what if we have a vice-versa situation? i.e. when a child record is deleted then the Master record without any child should also get deleted. This can be achieved by a trigger!! :)

Below is the code for the same. (Note: this code does not work for deleting records in bulk. Will be soon posting that as well. Also we need to have a unique key on both the objects)

if(Trigger.isAfter){
            if(Trigger.isDelete){
 
                List<ChildObjName__c> IdSetC = new List<ChildObjName__c>(); 
                List<MasterObjName__c  IdSetM = new List<MasterObjName__c>();
                Set<Id> IdSet = new Set<Id>();
               
                for(ChildObjName__c Cobj : Trigger.Old){
                     IdSet.add(Cobj.RelationshipName__c);
                     }
                List<MasterObjName__c> MobjLst = new List<MasterObjName__c>( [select id from MasterObjName__c where id =:IdSet]);
   
                    IdSetM=[select KeyField__c from MasterObjName__c where id=:IdSet];
                    IdSetC = [select id  from ChildObjName__c where KeyField__c =:IdSetM[0].KeyField__c];
   
                    if (IdSetC.size()==0)
                        {
                            delete MobjLst;
                        }
                    }
                } 

Solution by Abinash Sahoo and Srishti Goyal
  • October 22, 2014
  • Like
  • 1

Kindly provide a solution to the following : 

 

Details

I as a product manager require a custom search page for my salesforce CRM account. I don’t want to use the standard search functionality for this. Here is what I want to be done:

 

    1. On the VF page, create accustom “search” button and a checkbox with the name “limit to accounts I own”
    2. I should be able to enter and search on the following fields (these are the search criteria fields):
      1. Account name(standard field)
      2. Industry (standard field)
      3. Rating(standard field)
      4. Account  region(custom field)
      5. Account priority(custom filed)
      6. Account summary(text)
    3. The search functionality should be a logical OR of all the above combinations.
    4. The correct search results should be displayed ON THE SAME PAGE only after clicking the “submit” button.Display columns should have these fields: account name, industry, rating, account priority.
    5. If the checkbox “limit to accounts I Own” is checked before clicking on search the display only those accounts where the owner=current logged in user. 

I have developed the following code:

 

<apex:page Controller="AccountSearch">
<apex:form >
 
<apex:outputPanel layout="block">
<label for="checkbox"> Limit to Account I own: </label>
<input id="checkbox" type="checkbox"/>
</apex:outputPanel>
<apex:commandButton action="{!search}" value="Search"/>
 
<apex:pageBlock mode="edit" id="block">
         <apex:pageBlockSection >
            <apex:pageBlockSectionItem >
               <apex:outputLabel for="searchText">Search Text</apex:outputLabel>
               <apex:panelGroup >
                  <apex:inputText id="searchText" value="{!searchText}"/>
                  <apex:commandButton value="Submit" action="{!search}" 
                                      rerender="block"/>
               </apex:panelGroup>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
 <apex:actionStatus id="status" startText="requesting..."/>
<apex:pageBlockSection title="Results" id="results" columns="1">
           <apex:pageBlockTable value="{!results}" var="a"
                               rendered="{!NOT(ISNULL(results))}">
                               
              <apex:column value="{!a.Name}"/>
              <apex:column value="{!a.Industry}"/>
              <apex:column value="{!a.Rating}"/>
              <apex:column value="{!a.Account_Region__c}"/>
              <apex:column value="{!a.Account_Priority__c}"/>
              <apex:column value="{!a.Account_Summary__c}"/>
   </apex:pageBlockTable>
   </apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
__________________________________________________________________________________________
 
public class AccountSearch {
 
  String searchText;
   List<Account> results;
 
public String getSearchText() {
      return searchText;
   }
 
   public void setSearchText(String s) {
      searchText = s;
   }
 
   public List<Account> getResults() {
      return results;
   }
    public PageReference search() {
    results = (List<Account>)[FIND :searchText RETURNING Account(Name, Industry, Rating, Account_Region__c, Account_Priority__c, Account_Summary__c)][0];  
        return null;
    }
 
}
Please provide the necessary modifications
  • May 27, 2013
  • Like
  • 3
It is a salesforce standard functionality that when two objects are in a Master-detail relatonship with each other then if the Master record is deleted, all the related child records get delted automatically. However, what if we have a vice-versa situation? i.e. when a child record is deleted then the Master record without any child should also get deleted. This can be achieved by a trigger!! :)

Below is the code for the same. (Note: this code does not work for deleting records in bulk. Will be soon posting that as well. Also we need to have a unique key on both the objects)

if(Trigger.isAfter){
            if(Trigger.isDelete){
 
                List<ChildObjName__c> IdSetC = new List<ChildObjName__c>(); 
                List<MasterObjName__c  IdSetM = new List<MasterObjName__c>();
                Set<Id> IdSet = new Set<Id>();
               
                for(ChildObjName__c Cobj : Trigger.Old){
                     IdSet.add(Cobj.RelationshipName__c);
                     }
                List<MasterObjName__c> MobjLst = new List<MasterObjName__c>( [select id from MasterObjName__c where id =:IdSet]);
   
                    IdSetM=[select KeyField__c from MasterObjName__c where id=:IdSet];
                    IdSetC = [select id  from ChildObjName__c where KeyField__c =:IdSetM[0].KeyField__c];
   
                    if (IdSetC.size()==0)
                        {
                            delete MobjLst;
                        }
                    }
                } 

Solution by Abinash Sahoo and Srishti Goyal
  • October 22, 2014
  • Like
  • 1

VF

<apex:page controller="search_global">

<apex:form >

<apex:pageBlock title="Custom Search" mode="edit" id="block" >

<apex:pageBlockSection >

<apex:inputCheckbox label="Limit to accounts I own" />

<apex:pageBlockSectionItem >

<apex:outputLabel for="SearchText">Enter The Records Of Accounts

</apex:outputLabel>

<apex:panelGroup >

<apex:inputText id="searchText" value="{!searchText}"/>

<apex:commandButton value="Submit!" action="{!dosearch}" rerender="block" status="status"/>

</apex:panelGroup>

</apex:pageBlockSectionItem>

</apex:pageBlockSection>

<apex:actionStatus id="status" startText="requesting..."/>

<apex:pageBlockSection title="Results" id="results" columns="1">

<apex:pageBlockTable value="{!results}" var="l" rendered="{!NOT(ISNULL(results))}">

<apex:column value="{!l.name}"/>

<apex:column value="{!l.industry}"/>

<apex:column value="{!l.rating}"/>

<apex:column value="{!l.AccountPriority__c}"/>

</apex:pageBlockTable>

</apex:pageBlockSection>

</apex:pageBlock>

</apex:form>

</apex:page>

 

CONTROLLER

 

public class search_global {

 

String searchtext;

String newsearchtext=searchtext+'%';

 

List<account> Results;

public String getsearchtext(){

return searchtext;

}

public Boolean check{

get{

if(check== null){

check = false;

}

return check;

}

set;

}

 

public void setsearchtext(String s)

{

searchtext=s;

}

public list<account> getResults()

{

return Results;

}

public pagereference dosearch()

{

if(check==false)

{

results=[select name,Industry,Rating,AccountPriority__C from account where account.name like :searchtext+'%' or industry=:searchtext or rating=:searchtext or AccountRegion__c=:searchtext or AccountPriority__c=:searchtext or AccountSummary__c like :searchtext+'%'];

}

else

{

results=[select name,Industry,Rating,AccountPriority__C from account where (account.name like :searchtext+'%' or industry=:searchtext or rating=:searchtext or AccountRegion__c=:searchtext or AccountPriority__c=:searchtext or AccountSummary__c like :searchtext+'%')and (ownerid=:UserInfo.getUserId())];

}

return null;

}

 

}

//Upto this i got the entire fields of the record types.But my requirment is to give all those field of account record should be in a picklist.

Hello

 

I am using a csv file to do an insert/update operation into the salesfroce using the Apex Data loader from command line.

I inserted a record with three columns (one being ID , mapped to the Salesforce ID). 

When i perform an update operation, its throwing out the error saying that ,"Id not specified in an update call"

 

Did any of you face this issue? I fos could you let me know how to resolve this

 

thanks

pradeep

  • November 15, 2011
  • Like
  • 0