• Ankur Srivastava
  • NEWBIE
  • 75 Points
  • Member since 2014
  • Technical Lead
  • PricewaterhouseCoopers


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 15
    Questions
  • 10
    Replies
There is a duplicate rule on Account object enabled in my org. I have a customize lead convert classic page, in which if I select Create New account option then on click of convert button, it should display the error message of the duplicate rule. I added the below code to be displayed in error messge.
Database.LeadConvertResult leadConvertResult = Database.convertLead(leadConvert);
        
        // if the lead converting was a success then create a task
        if (!leadConvertResult.success)
        {
           PrintErrors(leadConvertResult.errors);
            
            return null;
         }

    //this method will take database errors and print them to teh PageMessages 
    public void PrintErrors(Database.Error[] errors)
    {
        for(Database.Error error : errors)
        {
            if(error instanceof Database.DuplicateError)
            {
               Database.DuplicateError duplicateError = (Database.DuplicateError)error;
               Datacloud.DuplicateResult duplicateResult = duplicateError.getDuplicateResult();
			// Display duplicate error message as defined in the duplicate rule
               ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.Severity.ERROR, 'You are creating a duplicate record. We recommend you use an existing record instead.');
               System.debug('The error message'+errorMessage);
                ApexPages.addMessage(errorMessage); 
            }
        }
    }
The above code doesn't provide the simple error message as mentioned in the code. However I recieve a the below error. What is it that I am doing wrong here ?
OR(AND( 
Owner:User.ProfileId <> "00e16000001054Q",
Owner:User.ProfileId <> "00e16000001Givi", 
Owner:User.ProfileId <> "00e16000001054R", 
Owner:User.ProfileId <> "00e16000001054S",
BEGINS( OwnerId , '00G')

This WF rule works when a Lead owner is changed from Queue to User Or User to Queue, but it doesn't work when I change owner from Q to Q.  I tried ISCHanged(OwnerId) to check if the owner has changed and if it belongs to '00G' . but ISCHANGED can't be used in such a formula. any way to do it ?
I have the following method returning a changed owner id when a person selects a new value from lightning component. I want to use this ownerId in a method of some other class. The value of the ownerId is available in this method. I am unable to use this return ownerId in a different class. It looks trivial but I don't know how to do it.
    @AuraEnabled
    public static Id getNewRecordOwner(Id ownerId) 
    { 
        System.debug('The value of Owner ID'+ownerId);
        
        leadConvertController lctr = new leadConvertController(ownerId);
        lctr.ownerIdChanged=ownerId;

        return ownerId; 
    }
How can I conditionally render a lightning component/app in my VF page based on a button click ? I have a lightning lookup component which I want to render when I click a search button on my VF page.
I have to insert the value of Name field present in OpportunityLineItem record in another holder object. I am using doing this by an after insert trigger on OpportunityLineItem object. All the other fields are getting inserted on the trigger execution. But the Name field is populating as null in the Holder object.

Sample code: (just for ref.)

List <B> b = new List<B>();

for(OpportunityLineItem opli : Trigger.New )
{
  B bi = new B();

 bi.Product_Name__c = opli.Name;
b.add(bi);
}
insert b;

I have skipped the other fields in the snippet..

Please let me know how to resolve this.
Hi,
I am inserting a record in another object B, once an insert trigger is executed in my source object A.
however i want to display error message /notify if any of the fields of object B failed to get populated with values from object A.
The user should be notified that the insertion in object B failed ,because a field X couldn't be populated due to some reason.