• Salesforce seekar
  • NEWBIE
  • 95 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 7
    Likes Given
  • 15
    Questions
  • 26
    Replies
Hello Folks ,
My scenario: under account say  i have 4 opportunities each having Opportunity.Amount__c field , i want to show show the Max value of Amount out of 4 opportunities under that account  on Account.Amount__c field.

 I  want it only using maps ,
no nested for loops please like below.

list < Account > AccList = new list < Account > ([Select id, Name, (Select id, Amount from opportunities) from Account ]);
Map<Accid,Opportunity> Opptoupdate = new Map<Accid,Opportunity>();

for( Account account : AccList) {
    for(Opportunity opportunity : account.opportunities) {
        if(opportunity.Amount == null || Opptoupdate.get(opportunity.AccountId).Amount > opportunity.Amount) {
            Opptoupdate.put(opportunity.AccountId, opportunity);
        }

    }
The below  licenses are of manages packages assigned to a active user , On user creation page . when once user is made inactive , I want to de-activate all the manage packages  using trigger . can you please tell me how to write trigger .



trigger to remove managed package licenses when user becomes inactive
we have a custom  checkbox on contact  is_primary__c , if we enter a number in field "  phone " on contact , corresponding Account should also have the same number populated on account . 



solution :

//Phone number from primary Contact (if Is_Primary__c checkbox is true )  will get updated to parent Account
//verified and working fine
trigger IsprimaryCOntact on Contact (after insert , after update ) 
{
  // contacts will be having id,accountid , so adding to their respective id 
Set<Id> accountIdSet= new Set<Id>();
Set<Id> contactIdSet=new Set<Id>();
List<Account> updateAccList=new List<Account>();
        
            for(Contact contact:Trigger.new)
            {
                accountIdSet.add(contact.accountId);
                contactIdSet.add(contact.Id);
            }
            // Get accounts with their contacts.
 Map<Id,Account> accountMap=new Map<Id,Account>([select id, Phone,(select id, Name from Contacts where Is_Primary__c=true and 
                                                               id not in :contactIdSet) from Account where Id in: accountIdSet]); 
 
 
                                                                          
   
   // checking the data     
           
            for(Contact contact:Trigger.new)
            {
            
                if(contact.Is_Primary__c && accountMap.containsKey(contact.accountId))
                {
                    //This will identify if account already has primary contact set
                    Account updAccount = accountMap.get(contact.accountId);
                    system.debug('--updAccount--'+updAccount);
                    updAccount.Phone=contact.Phone;
                    
                        if(updAccount.Contacts!= null && updAccount.Contacts.size() >0)
                        {
                            contact.addError('Error in saving data!!! Account already has primary contact');                                                
                        }
                    updateAccList.add(updAccount);
                }
            }
            
        update updateAccList;
}  
 
hi All , 

I have a custom object called subscription ( sub__c )  . owd for sub__c is public read/write for internal users (salesforce license) and private for external users (portal users ----> if we create a contact under account and click on button manage external user  , who are normally called partner users   ). partner users login via partner portal . 

Issue : in my account a1 ,  if i have contacts c1 and c2 now and they are converted as partner users . if i made a opportunity under account a1 to closed won i will get a subscription s1  created  under related list of  a1 ,  as c1 and c2 are created before subscription is created they are able to see the subscription under the related list . 

if a new contact c3 is created  , and now it is made  as portal user under the same account a1 , he is unable to see the subscription record . sharing of the s1 record is not happening  for new created contacts . so i wrote a below trigger on contact , please guide me is this approach correct . 

trigger : 

trigger ContactShare on contact (after update,after insert)
 {
if(trigger.isAfter && trigger.isInsert){
   List<Subscription__Share> shares = new List<Subscription__Share>();
   for(Contact c : trigger.new){
     for(Sub__c sb: [select id from Sub__c where AccountOwnerId__c = :c.accountid]){
       System.debug('sb Details*****'+c);
       Subscription__Share sr = new Subscription__Share();
       sr.UserOrGroupId =  c.id;
       sr.parentId = sb.id;
       sr.AccessLevel = 'Read';
       shares.add(sr);
       System.debug('shares Details*****'+shares);
     }
   }
   if(shares.size() >0) insert shares;
 }
 
}

To acheive : I want to acheive that  everytime if a new contact is created ,  subscription s1 which is present below a1 need to be visible below the related list for that contact , if the partner users login via partner portal .   
hi Team , 

i have a profile  named  " Knl_Profile  "  whih has 50 user , and that profile is added Delegated Group ie "Delegated_Knl_profile "  .  (5 / 50 )users are added to delegated system admin .  i need to write a vaildation rule in such a  way that , user detail can be edited by only delegated system admin of profile "Delegated_Knl_profile " or system admin profile . can you please help me here . getting no idea 
hi Team , 

can any one suggest me good blogs or  links to learn integration ,  which will be helpful for me . 

Thanks in Adv 
hi all , 

can you please tell me how to extract loginIP adress for a puticular profile containing 100 + users   , can we do a report  . or how can we do it 
Requirement on trigger -- my requirement is if we change the opportunity stage  to "CLosed won" , 
 based on email address present in  Contact role in  opportunity line item  we need to send an automatic reply email to that email address  .
 can any one share sample code or give us idea how to write this trigger.
how to create a report / anyother way for how many users are logging with purticular profile(say system administrator ) in a peroid of month /3 months. i want have data like (for example  #logins/day with  purticular profile in my org).
hi All , 
howw to create a report on the opportunity object  , where i need a report that tells me the amount of  opportunitys in each  stages in production  org. 

 
I would need the follow columns :

•    Opportunity Stage
•    Amount of records for this Opportunity stage.
In our organization the user management in SalesForce will be conducted by another department. 
They will only be responsible for the user management.  

  we already have a role called -->‘delegated system admin’ role.
-This gives a lot of rights which won’t be necessary to perform user management

 so how to Create a new Role for this requirement or how to proceed with this Requirement???

Their actions with user of new Role  should do the following 
          Creating user accounts
         Deactivate/re-activate user accounts
          Modifying user accounts (settings, add/remove permission sets, add/remove managed packages)x`x
          Creating contact, and converting them into managed user accounts (these are the sales rep accounts.

can you please help me here how to do this requirement .
here uid__c is a custom field which is a unique identty number like adhar card , now my requirement is only the users with this profile  can edit this uid__c

can you correct my validation rule . thing i sthat with one profile i am able to change the uid__c , with other profile it is throwing error . 

ans:  
AND( 
$Profile.Name <> 'Partner Manager', 
$Profile.Name <>'Sales Management User', 
$Profile.Name <>'Telephone Ibsales User', 
$Profile.Name <>'ddash Sales User', 
OR ( 
AND ( ISBLANK( uid__c ) = FALSE, 
PRIORVALUE( uid__c ) <> '', 
ISCHANGED( uid__c ) = TRUE), 
AND ( ISBLANK( uid__c ) = TRUE, 
PRIORVALUE( uid__c ) <> '', 
ISCHANGED( uid__c ) = TRUE) 

)
Hi ALL , i have a user who is unable to see the product baskets and a button on opporunity in his prod environmnet .... in test environmnet he is able to see . i checked all the  profiles both were same in test and prod ... i checked the page layout as well in prod , both are having the related list as prod basket and button ' send quote for Approval '

 







User-added image
If i create a List view in desktop version with admin profile , i want to see the list view in my Ipad in salesforce1 version where i am using portal licenses .... can you please help here
Hi ALL , 
 If a user logging with salerep profile , in Opportunity , stage picklist he should be unable to select a value called Needs Analysis.

please correct my rule :
AND 
( $Profile.Name = "Sales Profile" && 

Not( 
ISPICKVAL(StageName, "Needs Analysis") 

)
 
Hi guys help me out with some concept,
I learnt Set, Map and all their releted methods.
but while writing triggers I cannot decide when to use Map and Set,
please tell me how to decide, while writing, now their is need of Map.
Hello Folks ,
My scenario: under account say  i have 4 opportunities each having Opportunity.Amount__c field , i want to show show the Max value of Amount out of 4 opportunities under that account  on Account.Amount__c field.

 I  want it only using maps ,
no nested for loops please like below.

list < Account > AccList = new list < Account > ([Select id, Name, (Select id, Amount from opportunities) from Account ]);
Map<Accid,Opportunity> Opptoupdate = new Map<Accid,Opportunity>();

for( Account account : AccList) {
    for(Opportunity opportunity : account.opportunities) {
        if(opportunity.Amount == null || Opptoupdate.get(opportunity.AccountId).Amount > opportunity.Amount) {
            Opptoupdate.put(opportunity.AccountId, opportunity);
        }

    }
Hi All
How can i sum the last record value with new one.For example i have created a record with field value 400.again i  create another record with filed value 500 ,then how i will add this field value like 400+500=900 in second record  and so on..
We have a Subscribe button that will take you to a different webiste when you click on it. In Lightning, when you click on the button, the Navigate to this page message will pop-up. 

Button: Subscribe 
Display Type: Detail Page Button
Behavior: Execute JavaScript
Content Source: OnClick JavaScript 

Code: 

window.open('/apex/ConnectSignup?FirstName={!URLENCODE(Contact.FirstName)}&lastname={!URLENCODE(Contact.LastName) }&CompanyName={!URLENCODE(Contact.Company__c)}&email={!URLENCODE(Contact.Email)}&ContactId={!URLENCODE(Contact.CDSContact_ID__c)}');

Is it possible to add another line to prevent the pop-up from opening and take our user directly to the website?
what we need to fetch all records present in paymentlineitems from payment,using parent to child nested relation ship query.
how to write this query?
can any one help me
please check below User-added image
We are looking for a part-time offshore developer to create 15-20 new Visual Force pages for a startup company.
Details will be provided later.  You must have 2-3 years of hands-on programming experience in Apex, VFP, Java Script, SOQL, etc.  Must sign an NDA (non-disclosure agreement).  Please contact us with your hourly rate and email address.
Job Description:
We are currently searching for a Salesforce Developer to help us keep our salesforce database synced with our box office vendor, Brown Paper Tickets, in order to automatically transfer ticket sales from our box office to our database.   We currently have integration through Salesforce with Brown Paper Tickets already set up. However, we do need that integration to be updated and modified so that it can work as it is supposed to, as it once did.
 
Compensation:
$150 flat rate.
 
About the Company:
The African-American Shakespeare Company is a local non-profit theatre company in San Francisco, California. On top of providing classical theatre at an affordable price, we also work with local public schools, particularly from underrepresented communities, theatre workshops.
Job Description:
We are currently searching for a Salesforce Developer to help us keep our salesforce database synced with our box office vendor, Brown Paper Tickets, in order to automatically transfer ticket sales from our box office to our database.   We currently have integration through Salesforce with Brown Paper Tickets already set up. However, we do need that integration to be updated and modified so that it can work as it is supposed to, as it once did.
 
Compensation:
$150 flat rate.
 
About the Company:
The African-American Shakespeare Company is a local non-profit theatre company in San Francisco, California. On top of providing classical theatre at an affordable price, we also work with local public schools, particularly from underrepresented communities, theatre workshops.
 
we have a custom  checkbox on contact  is_primary__c , if we enter a number in field "  phone " on contact , corresponding Account should also have the same number populated on account . 



solution :

//Phone number from primary Contact (if Is_Primary__c checkbox is true )  will get updated to parent Account
//verified and working fine
trigger IsprimaryCOntact on Contact (after insert , after update ) 
{
  // contacts will be having id,accountid , so adding to their respective id 
Set<Id> accountIdSet= new Set<Id>();
Set<Id> contactIdSet=new Set<Id>();
List<Account> updateAccList=new List<Account>();
        
            for(Contact contact:Trigger.new)
            {
                accountIdSet.add(contact.accountId);
                contactIdSet.add(contact.Id);
            }
            // Get accounts with their contacts.
 Map<Id,Account> accountMap=new Map<Id,Account>([select id, Phone,(select id, Name from Contacts where Is_Primary__c=true and 
                                                               id not in :contactIdSet) from Account where Id in: accountIdSet]); 
 
 
                                                                          
   
   // checking the data     
           
            for(Contact contact:Trigger.new)
            {
            
                if(contact.Is_Primary__c && accountMap.containsKey(contact.accountId))
                {
                    //This will identify if account already has primary contact set
                    Account updAccount = accountMap.get(contact.accountId);
                    system.debug('--updAccount--'+updAccount);
                    updAccount.Phone=contact.Phone;
                    
                        if(updAccount.Contacts!= null && updAccount.Contacts.size() >0)
                        {
                            contact.addError('Error in saving data!!! Account already has primary contact');                                                
                        }
                    updateAccList.add(updAccount);
                }
            }
            
        update updateAccList;
}  
 
Hi Experts,
 
Please help me test class for below trigger.

​ 
Trigger AccountandContactUpdateTrigger on Case(before insert, before update){
 
    List<String> AccNoSet = new List<String>();
    for(Case c: trigger.new){
     AccNoSet.add(c.Account_Number__c);
    }
 
    Map<String, Account> AccMap  = new Map<String, Account>();
    for(Account acc : [SELECT Id, Parent_VRP_Number__c, VRP_Account_Number__c from Account where VRP_Account_Number__c IN :AccNoSet]){
     AccMap.put(acc.Parent_VRP_Number__c , acc);
    }
 
    for(Case c:trigger.new){
         c.Accountid = AccMap.get(c.Account_Number__c).id;
         if(c.accountid!=null){
         List<Contact> ConList = [select id, name from Contact where accountid =:c.accountid];
         if(!ConList.isempty()){
         c.Contactid = ConList[0].id;
         }
         }
    }
}
 
Regards,
Sai
Hi Experts,

I'm new to salesforce coding. I need a trigger for updating case fields based on account number.
For more information please find below image.

User-added image

Regards,
Manu
hi All , 

I have a custom object called subscription ( sub__c )  . owd for sub__c is public read/write for internal users (salesforce license) and private for external users (portal users ----> if we create a contact under account and click on button manage external user  , who are normally called partner users   ). partner users login via partner portal . 

Issue : in my account a1 ,  if i have contacts c1 and c2 now and they are converted as partner users . if i made a opportunity under account a1 to closed won i will get a subscription s1  created  under related list of  a1 ,  as c1 and c2 are created before subscription is created they are able to see the subscription under the related list . 

if a new contact c3 is created  , and now it is made  as portal user under the same account a1 , he is unable to see the subscription record . sharing of the s1 record is not happening  for new created contacts . so i wrote a below trigger on contact , please guide me is this approach correct . 

trigger : 

trigger ContactShare on contact (after update,after insert)
 {
if(trigger.isAfter && trigger.isInsert){
   List<Subscription__Share> shares = new List<Subscription__Share>();
   for(Contact c : trigger.new){
     for(Sub__c sb: [select id from Sub__c where AccountOwnerId__c = :c.accountid]){
       System.debug('sb Details*****'+c);
       Subscription__Share sr = new Subscription__Share();
       sr.UserOrGroupId =  c.id;
       sr.parentId = sb.id;
       sr.AccessLevel = 'Read';
       shares.add(sr);
       System.debug('shares Details*****'+shares);
     }
   }
   if(shares.size() >0) insert shares;
 }
 
}

To acheive : I want to acheive that  everytime if a new contact is created ,  subscription s1 which is present below a1 need to be visible below the related list for that contact , if the partner users login via partner portal .   
Hi,
I am new to SFDC development.

Can anyone explain to me how to write a trigger, if we inserting data in one object and should get updated in another object.
Hello, Anybody tried two way authentication. I am trying it's failing again and again. 
hi Team , 

i have a profile  named  " Knl_Profile  "  whih has 50 user , and that profile is added Delegated Group ie "Delegated_Knl_profile "  .  (5 / 50 )users are added to delegated system admin .  i need to write a vaildation rule in such a  way that , user detail can be edited by only delegated system admin of profile "Delegated_Knl_profile " or system admin profile . can you please help me here . getting no idea 
hi Team , 

can any one suggest me good blogs or  links to learn integration ,  which will be helpful for me . 

Thanks in Adv 
Hi,
I have a the requirement: I need to create a Custom Object with a relationship to Contact. I need to create 5 checkbox in Contacts and same in custom object. Now when I enter the values in the checkboxes in contact I need to insert a new record in custom object with the checkbox values. After inserting the record in cusgom object I need to make the contact checkbox to unselsect if 2 checkbox is selected. How can I do this. I am done with insert and update trigger. Below is my Trigger for reference. Please give me your suggestions.

trigger projInsert on Contact (after insert, after update) {
    System.debug('---- Inside Contact :----');
    
    if(trigger.isInsert) {
        List<Project__c> projList = new List<Project__c>();
        for(Contact con : Trigger.new) {
            System.debug('---- Inside For Loop : ----');    
            if (con.LastName != '' && con.LastName != null) {
                System.debug('---- Inside IF Loop : ----');    
                Project__c proj = new Project__c();
                proj.Contact__c = con.id;
                proj.Feature_1__c = con.Feature_1__c;
                proj.Feature_2__c = con.Feature_2__c;
                if(con.Product_A__c == true) {
                    proj.Products__c = 'Product A';
                }
                else if (con.Product_B__c == true) {
                    proj.Products__c = 'Product B';
                }
                else {
                    proj.Products__c = '';
                }
                projList.add(proj);
            }
            System.debug('---- Proj List ----');
            System.debug('---- Proj List After If : ----'+projList);   
        }
        
        if(projList.size() > 0) {
            insert projList;
        }
        System.debug('---- Proj List : ----');
        System.debug('---- Proj List Size : ----' +projList.size());
    }
       
    if(trigger.isUpdate) {
        Map <Id, Contact> mapContact = new Map <Id, Contact>();
        List<Project__c> listProject = new List<Project__c>();
        
        for(Contact cont : trigger.new)
            mapContact.put(cont.Id, cont);
        
        listProject = [SELECT id, Contact__c, Feature_1__c, Feature_2__c, Products__c
                         FROM Project__c 
                         WHERE Contact__c IN : mapContact.keySet()];
        
        if (listProject.size() > 0) {
            for (Project__c pro : listProject) {
                pro.Feature_1__c = mapContact.get(pro.Contact__c).Feature_1__c;
                pro.Feature_2__c = mapContact.get(pro.Contact__c).Feature_2__c;
            }
            update listProject;
        }
    }        
}

Thanks
I have a Map defined as follows
Map<ID,List<Opportunity>> accMap = new Map<ID,List>Opportunity>>();

My requirement is I need to fill the List<Oppotunity> defined inside the map with data from the Opportunity object and accountIDs for the Map.

like select [ID,Name,Amount from opportunity to be filled inside the list and from opportunity we get the accountID and this will be in Map like
accMap.put(o.accountID) some thing like this.

I hope I am clear.

please let me code if possible how to achieve this scenario.

thanks
shweta


 
Hello, total coding noob and trying to simply copy an Opportunity picklist value to a lookup field that is on the same Opportunity; the lookup is to a custom object called Warehouse__c.  I've scoured the forums for coding examples and thought I found what I needed but I am getting an error message in the Apex Trigger editor.

Source field is Opportunity.FMAV_Selling_Office__c (picklist)
Destination field is Opportunity.Selling_Office__c which is a lookup to a custom object Warehouse__c
Picklist values exactly match record names on Warehouse object.

Here is what I have so far?
Trigger GrabReference on Opportunity (before insert, before update)  
{    for (Opportunity dp: trigger.new) {
       if(Opportunity.FMAV_Selling_Office__c != null) {  
        //queries for 1 record's ID, being the record ID where the dpas.Name field is the same as the dp.picklist field that fired the trigger
           List<Warehouse__c> dpas = new List<Warehouse__c>(); 
           dpas = [Select Id from Warehouse__c WHERE Warehouse__c.Name = :Opportunity.FMAV_Selling_Office__c ORDER BY Id LIMIT 1];
           // and if we got back anything...
              if (dpas.size() > 0){
            //set your dp.reference field equal to the returned record's ID
                 Opportunity.Selling_Office__c = dpas[0].Id;
              }        
       }
    }
    }

Help?
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';
 
  • July 19, 2018
  • Like
  • 1
Hi All,
I want to generate records from one object into another object. I have written a trigger for this and working fine.
I want this output in batch apex form
What ever I get the records in object1 today, I want a schedule batch apex that all records should get create in object2 at Midnight only.
How can I do this?
Please provide me syntax

Thanks in Advance

Regards,
Hari
Hi All,

Q). What is a future method ? When we are going to use Future methods? Example program for Future method and Schedulable class for Future method?

Give me reply anyone.....
HI All,

Q). What is a Batch Apex,Queueable Apex and @Future methods?, What are the differences between them and when we are going to use these classes?
Can anyone explain these classes.......