0

We are checking the couple of conditions based on javascript logic.

  1. Contact email checking: if the contact email is already associated with some other user we needs to be popup message like:

    "User is already exists with the same email".

  2. Partner Licence checking: if there is no licences then we need to popup message like "You have not enough license available,please create support case".

I have tried below Javascript logic, the above points are not working.

Button Logic:

var results = sforce.apex.execute("validatePartnar", "validatePartnerId",{contactId:"{!Contact.Id}"},{contactEmail:"{!Contact.Email}"},{});


Web service class:

lobal class validatePartnar{ webService static string validatePartnerId(String contactId,String contactEmail){ string message =''; List conListForPartnar = [SELECT Id,AccountId,Account.IsPartner,Partner_User__c,Partner_Type__c from Contact where id =: contactId LIMIT 1]; List conListForEmail = [SELECT Id,name, email from user where email =:contactEmail];

    if(conListForEmail.size() > 0){ 
        message = 'User is already exists with the same email'; 
        return message;
    } 

    else{
    return message;
    }
}

}

Thanks

2
  • You need to set the __sfdcSessionId <script type="text/javascript"> var __sfdcSessionId = '{!GETSESSIONID()}'; 2 AJAX Toolkit Developer Guide AJAX Toolkit Support Policy </script> <script src="../../soap/ajax/40.0/connection.js" type="text/javascript"></script> <script type="text/javascript"> see this resources.docs.salesforce.com/sfdc/pdf/apex_ajax.pdf Commented Jun 16, 2017 at 14:21
  • Why did you deface your question and remove the code?
    – Eric
    Commented Jun 19, 2017 at 7:18

1 Answer 1

0

I don't see the declaration of the variable userlicns. There is another way to validate code if you write a web service & consume it from a button

// web service to validate.

global class validatePartnar{
    webService static string validatePartnerId(String contactId,String contactEmail){
        String message ='';
        List<Contact> conListForPartnar = [SELECT Id,AccountId,Account.IsPartner,Partner_User__c,Partner_Type__c from Contact where id =: contactId LIMIT 1];
        List<Contact> conListForEmail = [SELECT Id,name, email from user where email =:contactEmail limit 1];

        if(conListForPartnar <> NULL && conListForPartnar.size() > 0 && conListForPartnar[0].Partner_User__c == 'false'){ 
            message = 'This contact is associated to an account that is not partner enabled. Please mention SFDC Support to open a case.'; 
            return message;
        }
        else{
            System.debug('******** Partner_User__c validation passeed ***********');
        }
        if(conListForEmail <> NULL && conListForEmail.size() > 0){ 
            message = 'User is already exists with the same email'; 
            return message;
        } 
        else{
            System.debug('******** Email validation passeed ***********');
        }
        return message;
    }

}

============== button code =================

{!REQUIRESCRIPT("/soap/ajax/39.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/39.0/apex.js")} 

    var result = sforce.apex.execute("validatePartnar", "validatePartnerId",{contactId:"{!Contact.Id}",contactEmail:"{!Contact.Email}"}); 
    alert(result);

Hope this will resolve the issue as well as check userlicns variable I don't see any issue with this code apart from that variable.Please note salesforce favor to use lightning component instead. See here

10
  • @Avijith, Can you please suggest me if am not wrong where i can use the above _SfdcSessionID.Should i create a new VF page or can i use same lines on my top of the javascript code.Please help us for this. Thanks
    – Ram
    Commented Jun 16, 2017 at 14:28
  • At the top before using sforce commands Commented Jun 18, 2017 at 14:14
  • @Avijith, Don't mind can you please edit my logic with _SfdcSessionID. i have tried not getting proper popup messages.Please help me for this. Thanks
    – Ram
    Commented Jun 19, 2017 at 9:08
  • @Ram Are you trying to do this in classic correct? And your queries returning values? did you tried to put alerts after the statement alert(records ); alert(userrecd); alert(records[0].Partner_User__c); Commented Jun 19, 2017 at 10:43
  • @Avijith,Yes, i have used alerts for userecrd and licences there is no proper outcome which i have expecting.Please help me for this for me it is very high priority.
    – Ram
    Commented Jun 19, 2017 at 11:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .