• Rishabh Bansal 23
  • NEWBIE
  • 89 Points
  • Member since 2020

  • Chatter
    Feed
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 15
    Replies
I have two custom object Resource__c and Leave__c. Leave__c has lookup with Resource__c.
In Resource there are two custom field Total_Allocated_Paid_Leaves__C and Total_Used_Paid_Leaves__c.
Where Leave__c object has one custom field Leaves__c.
I want trigger on
If i entered +ve value in Leaves__c (Leave__c's field) it will add in Total_Allocated_Paid_Leaves__C (Resouce__c's field)
and if i enterd -ve value in  Leaves__c (Leave__c's field) it will add in otal_Used_Paid_Leaves__c.
I need to accomplish two steps:
1) automatically populate a lookup field on a Lead child record, with its parent record. Once that is done, we have a couple formula fields on the Lead with information from the parent record that we want to display on the Lead.
2) Once that is done and we have populated all the formula fields, we want to automatically delete the parent record. 

The first step is already done, and this trigger works:

trigger LeadLookupParent on Lead (before insert, before update) {
Set<String> setssn = new Set<String>();
Map<String,Id> mapssn = new Map<String,Id>();
    
for(Lead l :trigger.new){
        if(l.UniqueNumber__c !=null && l.UniqueNumber__c != '') {
            setssn.add(l.UniqueNumber__c);
        }
  }  
if(!setssn.isEmpty()){ 
        for(Parentobj__c re : [SELECT id, Uniquenum__c FROM Parentobj__c WHERE (Uniquenum__c =:setssn)]){
                           mapssn.put(re.Uniquenum__c, re.Id); 
     }
  }
if(mapssn.size() > 0){
        for(Lead ld :trigger.new){
            if(ld.UniqueNumber__c !=null && ld.UniqueNumber__c != '')  {
                ld.Parentobj__c = mapssn.get(ld.UniqueNumber__c); 
            }
        }
    }
}

Where I am stuck is on the second step. I tried this trigger on Lead but it is giving me an error that the id does not exist. I am open to any other solutions or fixing this one:

trigger DeleteParentrecord on Lead (after insert, after update) {

Set<String> leadSsn = new Set<String>();
    for (lead ld: trigger.new){
        if (ld.Parent__c !=null){
            leadSsn.add(ld.Parent__c);
        }
        Parent__c par= [select id from parent__c where id = :leadSsn];
        delete par;
    } 
}
I have a custom object-Patient.
the requirement is to - Link 2 or more patients together.

Suppose I have a Patient A, Patient B, Patient C.
There should be a lookup field on Patient 'Linked Patients'.
Now through this linked Patients i need to link Patient B & C to A.

Is this possible?
 
I have two custom object Resource__c and Leave__c. Leave__c has lookup with Resource__c.
In Resource there are two custom field Total_Allocated_Paid_Leaves__C and Total_Used_Paid_Leaves__c.
Where Leave__c object has one custom field Leaves__c.
I want trigger on
If i entered +ve value in Leaves__c (Leave__c's field) it will add in Total_Allocated_Paid_Leaves__C (Resouce__c's field)
and if i enterd -ve value in  Leaves__c (Leave__c's field) it will add in otal_Used_Paid_Leaves__c.
Hi All,
I need you help. I am trying to create a New Button or Link on opportunity ( under Lightning UX).
I would like this button (URL button) to replace the standard "New" Button on opportunity list view and opportunity related list on account.

I would like to create a new opportunity with predefined values for stage and close date fields.
When creating a new opportunity I would like stage = "New" and close date = TODAY()+30.
I read several articles and tried to do it by myself without any success.

Can you please help me ?
Thanks in advance
Best Regards

Sabrina
Hi ,
 I need help in json.
When i try to create record using json i am getting error in $User.Id
[
	{
		"attributes": {
			"type": "Activity_Template__c"
		},
		"Name": "Expense test",
		"Assigned_To__c": $User.Id,
	}
]

I want to dynmically set the Assigned_To__c i.e whoever runs this json Assigned_To__c will contain there user id.

Thanks in advance
I need to accomplish two steps:
1) automatically populate a lookup field on a Lead child record, with its parent record. Once that is done, we have a couple formula fields on the Lead with information from the parent record that we want to display on the Lead.
2) Once that is done and we have populated all the formula fields, we want to automatically delete the parent record. 

The first step is already done, and this trigger works:

trigger LeadLookupParent on Lead (before insert, before update) {
Set<String> setssn = new Set<String>();
Map<String,Id> mapssn = new Map<String,Id>();
    
for(Lead l :trigger.new){
        if(l.UniqueNumber__c !=null && l.UniqueNumber__c != '') {
            setssn.add(l.UniqueNumber__c);
        }
  }  
if(!setssn.isEmpty()){ 
        for(Parentobj__c re : [SELECT id, Uniquenum__c FROM Parentobj__c WHERE (Uniquenum__c =:setssn)]){
                           mapssn.put(re.Uniquenum__c, re.Id); 
     }
  }
if(mapssn.size() > 0){
        for(Lead ld :trigger.new){
            if(ld.UniqueNumber__c !=null && ld.UniqueNumber__c != '')  {
                ld.Parentobj__c = mapssn.get(ld.UniqueNumber__c); 
            }
        }
    }
}

Where I am stuck is on the second step. I tried this trigger on Lead but it is giving me an error that the id does not exist. I am open to any other solutions or fixing this one:

trigger DeleteParentrecord on Lead (after insert, after update) {

Set<String> leadSsn = new Set<String>();
    for (lead ld: trigger.new){
        if (ld.Parent__c !=null){
            leadSsn.add(ld.Parent__c);
        }
        Parent__c par= [select id from parent__c where id = :leadSsn];
        delete par;
    } 
}
When an opportunity is inserted check for it’s a delicacy on the basis of its name and the account to which it is related to i.e. If it has the same name and it’s linked to the same Account then append “Duplicate Opportunity” in the name.
Help please!:  I have successfully created two different combo boxes in a lightning component. The first one displays account records using autocompletion while the second combo box displays user records  using autocompletion. However when I type a user's name in the second combo box I notice that not only do I get a list of user records underneath the second (User) combo box, but I also get that same list of user records listed underneath the first (Account)  combo box. I only want the dynamic list to appear underneath the second (User) combo box when I am searching for a specific group of users when using autocompletion .  Thanks. Let me know if you need additional code. 
 
first class: 
global class FGContactOwnerUpdate1 implements Database.Batchable<sObject> {
List<Contact> Con = new List<Contact>();
List<Contact> ConList = new List<Contact>(); //Contact List to update
 
global FGContactOwnerUpdate1(List<Account> AccList){
        List<id> AccListId = new List<id>();
        for(Account ac: AccList){ 
        AccListId.add(ac.id);
    }
    } 
    
global static Database.QueryLocator start(Database.BatchableContext BC){
 string Con = 'select id, OwnerId, Account.ownerId from Contact where AccountId in :AccListId and Active__c = true';
    return Database.getQueryLocator(Con);
}  
    
   global void execute(Database.BatchableContext BC, List<Contact> conlist){
       for(Contact c: conlist){
    if(c.OwnerId != c.Account.OwnerId){
    c.OwnerId = c.Account.OwnerId;
     ConList.add(c); 
   }

Database.update(ConList);
}
}
    global void finish(Database.BatchableContext BC) {
  }
}

second class :
global class FGContactOwnerUpdate {
    
@InvocableMethod(label='exuete the batch ContactBatch' description='This method will be execute ContactBatch')
global static void executeBatchMethod(List<String> lst) {
    FGContactOwnerUpdate1 c1= new FGContactOwnerUpdate1();
    Database.executeBatch(c1, 50);
  }
    
}

Getting error as : Constructor not defined: [FGContactOwnerUpdate1].<Constructor>().

Its an urgent issue
hi..! 

i have a requirement, when i clicks on the edit button, span tag should have to change to the Input tag.. 
and when click on the Delete button, that particular row from list should have to removed form the list .. 
 
public class testingclass {

public string xmlstring{get;set;}
 public string testingval{get;set;}
 public List<string> lsttestingval{get;set;}

 public testingclass(){
 
  lsttestingval = new list<string>();
  
   lsttestingval.add('Red');
    lsttestingval.add('Blue');
    lsttestingval.add('Yellow');
    
  }
  
}

Visualforce page:
<apex:page controller="testingclass">
<apex:form >

   
    <table style="width:100%">
  <tr>
    <th>name</th>
    <th>Edit</th>
    <th>Delete</th>
    
  </tr>
 
    <apex:repeat var="a" value="{!lsttestingval}"> 
     <tr>
     <td><span>{!a}</span><apex:inputText styleClass="display:none"/></td> <td><apex:commandButton value="Edit"/></td><td><apex:commandButton value="Delete"/></td>
      </tr>
     </apex:repeat>
     
 
 
</table>
   
   </apex:form>
</apex:page>

After, editing, in input, the span value should have the same as the Edited value.. 

Thanks in Advance.
Deepika
Hi 

I have written triggers to sync quotes on opportunity products

Can but in opportunity name feild product name is not getting displayed instead some numbers are getting displyed. According to me it is opportunity id's. Can anyone help me with the code.

Below is the snip for your reference

User-added image


trigger QuoteLineItemTrigger on Quotes__c (after insert, after update)
{
    
    Map<Id,Id> quoteIdToOppId =new Map<Id,Id>();
    Map<Id,List<QuoteLineitem__c>> quoteIdToLineItems = new Map<Id,List<QuoteLineitem__c>>();
    List<OpportunityLineItem__c> oppLineItems = new List<OpportunityLineItem__c>();
    Map<Id,String> oppIdtoName = new Map<Id,String>();
    
    for(Quotes__c q : trigger.new) {
        if(q.IsSyncing__c && q.IsSyncing__c  != Trigger.oldMap.get(q.Id).IsSyncing__c ) 
            quoteIdToOppId.put(q.id, q.OpportunityId__c);
    }
    System.debug('UAC: quoteIdToOppId ' + quoteIdToOppId);
    
    for( QuoteLineitem__c qli :[SELECT Id, Product2Id__c,Product2Id__r.name,Quantity__c,ServiceDate__c, QuotesId__c,ListPrice__c,Line_Item_Description__c,Total_Price__c,Product2Id__r.Product_Code__c,UnitPrice__c  
                                FROM QuoteLineitem__c WHERE QuotesId__c =:quoteIdToOppId.keyset() ])  {
        List<QuoteLineitem__c> tempList = quoteIdToLineItems.get(qli.QuotesId__c) ;
        if(tempList == null)   {            
            templist = new List<QuoteLineitem__c>();
            quoteIdToLineItems.put(qli.QuotesId__c, templist);           
        }
        tempList.add(qli);
    }
    System.debug('UAC: quoteIdToLineItems ' + quoteIdToLineItems);
    
    for(Opportunities__c opp : [SELECT Id , Name  FROM Opportunities__c WHERE ID IN :quoteIdToOppId.values()] )  {
        oppIdtoName.put(opp.id, opp.Name)   ;
    }
    System.debug('UAC: oppIdtoName ' + quoteIdToLineItems);
    
    for(Quotes__c q : Trigger.new)    {
        if(q.IsSyncing__c && quoteIdToLineItems.containsKey(q.Id)) {
            for(QuoteLineitem__c qli : quoteIdToLineItems.get(q.Id))  {
                OpportunityLineItem__c oli = new OpportunityLineItem__c();
                oli.OpportunityId__c = quoteIdToOppId.get(qli.QuotesId__c); 
                System.debug(' qli.Product2Id__r.name ' +  qli.Product2Id__r.name);
                oli.Name = qli.Product2Id__r.name;
                System.debug(' qli.Product2Id__c ' +  qli.Product2Id__c);
                System.debug(' qli.ListPrice__c ' +  qli.ListPrice__c);
                System.debug(' qli.Line_Item_Description__c ' +  qli.Line_Item_Description__c);
                oli.Product2Id__c = qli.Product2Id__c; 
                oli.Quantity__c = qli.Quantity__c; 
                oli.ListPrice__c = integer.valueof(qli.ListPrice__c); 
                oli.Description__c = qli.Line_Item_Description__c;
                oli.ServiceDate__c = qli.ServiceDate__c;
                oli.Total_Price__c = qli.Total_Price__c;
                oli.ProductCode__c = qli.Product2Id__r.Product_Code__c;
                oli.Sales_Price__c =qli.UnitPrice__c;
                oppLineItems.add(oli);
            }
            
        }
        System.debug('UAC: oppLineItems ' + oppLineItems);
        if(oppLineItems.size() > 0) 
            insert oppLineItems ;
        
    }
}



 
Here is the code, running successfully but not copying the products. can someone help on this?

trigger orderproduct on Order__c (before insert,after insert)  {
    Set<Id> opportunityIds = new Set<Id>();
    Set<Id> orderIds = new Set<Id>();
    List<Order__c> orderList = new List<Order__c>();
    for(Order__c o : Trigger.new)
    {
        if(o.Opportunity__c  != NULL)
        {
            opportunityIds.add(o.Opportunity__c );
            orderIds.add(o.Id);
        }
        
    }
    
    if(opportunityIds.size() > 0)
    {
        list<OpportunityLineItem__c> oppprodList = new list<OpportunityLineItem__c>([Select id,name from OpportunityLineItem__c WHERE Id IN :opportunityIds]);
        // Loop through orders
        List<OrderItem__c> orderItemsForInsert = new List<OrderItem__c>();
        for(OpportunityLineItem__c pd : oppprodList)
        {
            OrderItem__c oi = new OrderItem__c();
            oi.OrderId__c = oi.Id;
            oi.Unit_Price__c = 2323;
            oi.Quantity__c = 1;
            orderItemsForInsert.add(oi);
        }
        system.debug('sucess');                              
        if(orderItemsForInsert.size() > 0)
        {
            insert orderItemsForInsert;
        }
        
    }
}
I have a custom object-Patient.
the requirement is to - Link 2 or more patients together.

Suppose I have a Patient A, Patient B, Patient C.
There should be a lookup field on Patient 'Linked Patients'.
Now through this linked Patients i need to link Patient B & C to A.

Is this possible?
 
Hello,

I am using lightning:datatble to display some list i have a requirement to use filters like start date end date and 2 picklist values ,user can choose any combination to update the list can any one suggest better design ?