0

I have the following code on the trigger, but when it runs I get an error message on salesforce page.

(You encountered some errors when trying to save this record There's a problem saving this record. You might not have permission to edit it, or it might have been deleted or archived. Contact your administrator for help.)

trigger OppLeadtoClient on Opportunity (After update) {
    If(trigger.new[0].StageName=='Closed Won'){

Lead ld = [SELECT Id FROM Lead WHERE accountid__c =: trigger.new[0].Accountid ];
       Database.LeadConvert lc = new Database.LeadConvert();
       lc.setLeadId(ld.Id);
            //lc.setDoNotCreateOpportunity(True);
            LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
            lc.setConvertedStatus(convertStatus.MasterLabel);   
            Database.LeadConvertResult lcr = Database.convertLead(lc);
            System.assert(lcr.isSuccess());
            System.debug('converted');

}}
  • 1
    Are you using your administrator user with full permissions? If not, check if your user has the permission to create accounts, contacts and opportunities. – Renato Oliveira Jul 10 '18 at 23:30
  • 1
    When you select the lead in your query based on account id, what is the status of that lead? – Jayant Das Jul 10 '18 at 23:40
  • Im using a Developer Edition, as System Administrator, and the Lead Status is "New". And the trigger also throws the error when i try to register a new Contact from scartch, i mean creating the Contact-> adding the field values -> inserting the Contact. – Eduardo Cordero Jul 11 '18 at 19:19
0

I found the Problem, the Lead was assigned to a queue as owner, and when i tried to edit it from a trigger, it seems not to have the rights even if im doing it from a System Admin Role.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.